Last active
January 9, 2025 08:12
-
-
Save goodki-d/fa4d1f7ad14303fa83faf7c1e6eaf77f to your computer and use it in GitHub Desktop.
Build OpenAPI spec for a sanic app without starting the server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from sanic import Sanic | |
from sanic_ext.extensions.openapi.builders import SpecificationBuilder | |
app = Sanic(__name__) | |
def get_spec(a: Sanic): | |
return SpecificationBuilder().build(a).serialize() | |
@app.command | |
def openapi(): | |
with open("./openapi.json", "w") as f: | |
f.write(json.dumps(get_spec(app))) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment