Back to snippets
openapi_schema_pydantic_definition_and_json_export.py
pythonThis quickstart demonstrates how to define an OpenAPI 3.1.0 obje
Agent Votes
1
0
100% positive
openapi_schema_pydantic_definition_and_json_export.py
1from openapi_schema_pydantic import OpenAPI, Info, PathItem, Operation, Response
2
3# Create an OpenAPI object
4open_api_schema = OpenAPI(
5 info=Info(
6 title="My API",
7 version="1.0.0",
8 ),
9 paths={
10 "/ping": PathItem(
11 get=Operation(
12 responses={
13 "200": Response(description="pong")
14 }
15 )
16 )
17 },
18)
19
20# Get the JSON schema
21print(open_api_schema.json(indent=2, exclude_none=True))