Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scalar integration (additional alternative to Swagger UI/Redoc) #10674

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

marclave
Copy link

👋 hey FastAPI, long time fan of everyone's work here and have been eagerly wanting to integrate Scalar's open-source & MIT licensed OpenAPI/Swagger documentation tool to FastAPI.

image
preview of Scalar integrated with a custom FastAPI theme (not sure on where the best place to add a bit of css is for a custom theme ✨ )

You can play around with what Scalar is like here based on the PetStore https://fastapi.apidocumentation.com

This is also my first time contribution to FastAPI so I am excited for feedback and ready for any requested changes!

@tiangolo
Copy link
Owner

📝 Docs preview for commit fe9d070 at: https://3908a882.fastapitiangolo.pages.dev

@tiangolo
Copy link
Owner

📝 Docs preview for commit 3a31862 at: https://e2b8a06b.fastapitiangolo.pages.dev

@tiangolo
Copy link
Owner

📝 Docs preview for commit 95803ef at: https://52620119.fastapitiangolo.pages.dev

README.md Outdated Show resolved Hide resolved
docs/en/docs/features.md Outdated Show resolved Hide resolved
@tiangolo
Copy link
Owner

📝 Docs preview for commit 36fc23f at: https://db2a9cdc.fastapitiangolo.pages.dev

@marclave marclave changed the title feat: add scalar integration feat: add scalar integration (additional alternative to Swagger UI/Redoc) Nov 20, 2023
Copy link

@nkamali nkamali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@nkamali nkamali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marclave
Copy link
Author

@marclave Do you not need a conditional block similar to this one that exists for redoc, for scalar?

https://github.com/tiangolo/fastapi/pull/10674/files#diff-2acad16c8816cd891697cf09bc6158a64aeab4091ad4cb7a3e5cce88bb9a1a78R1118-R1127

we do have one right below where you referenced :)

https://github.com/tiangolo/fastapi/pull/10674/files#diff-2acad16c8816cd891697cf09bc6158a64aeab4091ad4cb7a3e5cce88bb9a1a78R1129

@marclave
Copy link
Author

@marclave Need scalar_url=None here as well, probably? https://github.com/tiangolo/fastapi/pull/10674/files#diff-2acad16c8816cd891697cf09bc6158a64aeab4091ad4cb7a3e5cce88bb9a1a78R422

ah good catch! I wrote the tests for it but didnt update the docs there.

Just pushed up a commit to fix this :)

@tiangolo
Copy link
Owner

📝 Docs preview for commit 8a79d14 at: https://8318b0bb.fastapitiangolo.pages.dev

@tiangolo
Copy link
Owner

📝 Docs preview for commit 08f43fd at: https://49a76bae.fastapitiangolo.pages.dev

@tiangolo
Copy link
Owner

tiangolo commented Dec 2, 2023

📝 Docs preview for commit 743a4c5 at: https://2f17ff93.fastapitiangolo.pages.dev

fastapi/applications.py Outdated Show resolved Hide resolved
Copy link
Contributor

@hasansezertasan hasansezertasan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great job.

@marclave marclave force-pushed the marc/add-scalar-integration branch 2 times, most recently from dfb30f8 to e131330 Compare December 11, 2023 14:42
@hasansezertasan
Copy link
Contributor

@marclave I'm quite excited about this. Hope you'll soon fix failed checks.

@marclave
Copy link
Author

@marclave I'm quite excited about this. Hope you'll soon fix failed checks.

@hasansezertasan im glad you're excited! We are too ✨

I'll fix up these build issues this weekend :)

@marclave
Copy link
Author

marclave commented Jan 6, 2024

@tiangolo did something change with building of the docs? I might need to make a fresh PR but im not sure what's happening based on the logs. any guidance would be great ✨

@tiangolo tiangolo added investigate p4 feature New feature or request and removed investigate labels Jan 13, 2024
@hasansezertasan
Copy link
Contributor

Hello @marclave, is there any update on this?

@marclave
Copy link
Author

Hello @marclave, is there any update on this?

waiting on a review from @tiangolo :) also im not sure why build docs is failing tho, any insights there would be great ✨ I could do a fresh rebase and maybe that will fix it

@hasansezertasan
Copy link
Contributor

waiting on a review from @tiangolo :) also im not sure why build docs is failing tho

I'm not sure either. 😕

About the review, I recommend you to read this #10437 (comment) from the author, especially this sentence: "I'm also considering trimming a bit these things and simplify the way that automatic OpenAPI UIs are provided, probably removing the default ReDoc and making it opt-in. But that will come later." 😞

I interpreted that sentence as "No more alternative automatic OpenAPI UI's will be included.". What do you think about it @marclave?

I also created a package called openapipages and included Scalar to it (based on this PR 🙏). I would not say no to a 🌟. Let me know what you think about it 🤓

@marclave
Copy link
Author

waiting on a review from @tiangolo :) also im not sure why build docs is failing tho

I'm not sure either. 😕

About the review, I recommend you to read this #10437 (comment) from the author, especially this sentence: "I'm also considering trimming a bit these things and simplify the way that automatic OpenAPI UIs are provided, probably removing the default ReDoc and making it opt-in. But that will come later." 😞

I interpreted that sentence as "No more alternative automatic OpenAPI UI's will be included.". What do you think about it @marclave?

I also created a package called openapipages and included Scalar to it (based on this PR 🙏). I would not say no to a 🌟. Let me know what you think about it 🤓

Wow thanks for adding scalar @hasansezertasan ! I gave it a star 💫

Would be cool to add your package to the documentation of FastAPI then ✨

@hasansezertasan
Copy link
Contributor

Wow thanks for adding scalar @hasansezertasan ! I gave it a star 💫

Thank you, I'm grateful 🙏. Of course, I'm gonna add Scalar API, it's a great tool (it's my fav so far)!

Would be cool to add your package to the documentation of FastAPI then ✨

Well, where (which page) do you recommend adding it to? As far as I remember, FastAPI documentation doesn't have a page for third-party-extensions like Starlette (Third Party Packages - Starlette)

@marclave
Copy link
Author

Wow thanks for adding scalar @hasansezertasan ! I gave it a star 💫

Thank you, I'm grateful 🙏. Of course, I'm gonna add Scalar API, it's a great tool (it's my fav so far)!

Would be cool to add your package to the documentation of FastAPI then ✨

Well, where (which page) do you recommend adding it to? As far as I remember, FastAPI documentation doesn't have a page for third-party-extensions like Starlette (Third Party Packages - Starlette)

I'm not entirely sure where it should go to be honest. But maybe in the root README? Or maybe we should have a page for third party extensions ✨

@hasansezertasan
Copy link
Contributor

hasansezertasan commented Feb 17, 2024

I'm not entirely sure where it should go to be honest. But maybe in the root README? Or maybe we should have a page for third party extensions ✨

I'm not sure if the author would promote openapipages in the README but I believe there can be a page called "More Alternative Interfaces" next to "Configure Swagger UI" page that demonstrates Scalar integration using openapipages package.

I also been longing for a third-party-extensions page.

WDYT about it @tiangolo? I can work on "More Alternative Interfaces" page if you like the idea.

Edit: I started a discussion at #11158, check it out 🥇.

@marclave marclave force-pushed the marc/add-scalar-integration branch from adb7fd5 to a7f5717 Compare March 31, 2024 20:55
@marclave
Copy link
Author

we got an official integration! scalar/scalar#1534

pip install scalar-fastapi
from fastapi import FastAPI
from scalar_fastapi import get_scalar_api_reference

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/scalar", include_in_schema=False)
async def scalar_html():
    return get_scalar_api_reference(
        openapi_url=app.openapi_url,
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request p4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants