sanic-org / sanic-openapi

Easily document your Sanic API with a UI
https://sanic-openapi.readthedocs.io/
MIT License
505 stars 107 forks source link

Multiple fixes and improvements #244

Closed ahopkins closed 3 years ago

ahopkins commented 3 years ago
  1. Fixes #240
  2. Fixes #239
  3. Adds exclude to OAS3
  4. Adds openapi.definition decorator to OAS3
  5. Adds support for reading from annotated class models
  6. Adds specification.raw() method to OAS3 for adding specs directly

Here is an example of how the definition decorator could be used:

class Name:
    first_name: str
    last_name: str

class User:
    name: Name

@app.post("/path")
@openapi.definition(
    operation="opeID",
    summary="This is a summary",
    description="This is a description",
    tag=["one", "two"],
    document="http://127.0.0.1:9999/doc",
    # body=RequestBody(content=User),
    body=RequestBody(User, True, "Hello"),
    # body=RequestBody({"application/json": {"name": str}}),
    # body={"*/*": User},
    parameter=Parameter("foo", int),
    # parameter={"required": True, "name": "something"},
    response=[
        Response(User, status=201),
        Response(Name, status=400),
    ],
    # response={"application/json": User
)
async def post_test(request):
    return json({"hello": "world"})
artcg commented 3 years ago

👍 nice thanks for that, looks like some good changes, nice to see some more robust tests as well