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

DM-37525: Add openapi generator extension #159

Merged
merged 9 commits into from
Jun 7, 2023
Merged

Conversation

jonathansick
Copy link
Member

@jonathansick jonathansick commented Jun 5, 2023

This PR provides support for embedding a Redoc site for FastAPI apps and other projects that have OpenAPI specifications.

  • The documenteer.ext.openapi Sphinx extension can generate the OpenAPI specification during the Sphinx build by running a user-specified function. See the docs at https://documenteer.lsst.io/v/DM-37525/sphinx-extensions/openapi.html
  • The documenteer.ext.openapi and sphinxcontrib.redoc extensions are included by default with the Documenteer user guide configuration (documenteer[guide])
  • Users can configure both the openapi generator and redoc extensions by setting a [project.openapi] table in the documenteer.toml configuration file. See the docs at https://documenteer.lsst.io/v/DM-37525/guides/openapi.html
  • The docs advocate setting up a stub page to add the redoc HTML page to the Sphinx toctree; this stub gets overwritten by the sphinxcontrib.redoc extension. This solution removes the need to an API landing page.

For a working demo see lsst-sqre/squarebot#18 and https://squarebot.lsst.io/v/DM-37525/index.html

This Sphinx extension can run a user-provided function to generate the
OpenAPI specification for, e.g., a FastAPI project.
- Include sphinxcontrib-redoc to the [guide] extras
- In the default configuration for guides, include sphinxcontrib-redoc
and documenteer.ext.openapi.
The new [project.openapi] section lets docs writers configure both
documenteer.ext.openapi and sphinxcontrib-redoc to generate and include
redoc docs in their site.
Add both the TOML reference for [project.openapi] and a guide for
setting up the Redoc/OpenAPI site embed.
Setting the default to None makes the documenteer.toml use case easier
so that the value can be set to None if the [project.openapi] table
isn't set. Otherwise Sphinx raises a value that None is being set on a
string-defaulted configuration.
@jonathansick jonathansick marked this pull request as ready for review June 6, 2023 20:13
@jonathansick jonathansick requested a review from rra June 6, 2023 20:14
Copy link
Member

@rra rra left a comment

Choose a reason for hiding this comment

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

This looks great! Really happy with how easy this is to plug in to packages.

The demo with squarebot for some reason didn't work for me. I just see the stub page when I go to https://squarebot.lsst.io/v/DM-37525/api.html, I just see the stub page.

@jonathansick
Copy link
Member Author

Whoops, looks like I broke it. I'll check this.

@jonathansick
Copy link
Member Author

https://squarebot.lsst.io/v/DM-37525/api.html is working again. I'm still not sure why the stub didn't get replaced; I haven't been able to replicate it.

@jonathansick jonathansick merged commit 62de299 into main Jun 7, 2023
@jonathansick jonathansick deleted the tickets/DM-37525 branch June 7, 2023 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants