Skip to content

Instantly share code, notes, and snippets.

@chunleng
Last active August 9, 2021 14:55
Show Gist options
  • Save chunleng/a75f7774319bd0f18a293e8dd32807b7 to your computer and use it in GitHub Desktop.
Save chunleng/a75f7774319bd0f18a293e8dd32807b7 to your computer and use it in GitHub Desktop.
Medium: OpenAPI and CodeGen - FastAPI
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from pydantic import BaseModel
app = FastAPI()
app.add_middleware(CORSMiddleware, allow_origins=['*'])
class Bar(BaseModel):
items: list[str] = []
@app.get('/GetFoo', operation_id='GetFoo',
response_class=JSONResponse, response_model=Bar, tags=['First'])
async def get_foo():
return Bar(items=[1,2,3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment