Neoteroi / BlackSheep

Fast ASGI web framework for Python
https://www.neoteroi.dev/blacksheep/
MIT License
1.8k stars 75 forks source link

Add support for Union types in OpenAPI Doc generation #389

Open RobertoPrevato opened 1 year ago

RobertoPrevato commented 1 year ago

🚀 Feature Request

Add support for the following scenarios:

@dataclass
class A:
    a_prop: int

@dataclass
class B:
    b_prop: str

@dataclass
class C:
    c_prop: str

@dataclass
class AnyOfTestClass:
    sub_prop: Union[A, B, C]

@pytest.mark.asyncio
async def test_any_of_dataclasses(docs: OpenAPIHandler, serializer: Serializer):
    app = get_app()
    docs.bind_app(app)

    @app.route("/one")
    def one(data: AnyOfTestClass):
        ...

    await app.start()

    yaml = serializer.to_yaml(docs.generate_documentation(app))
RobertoPrevato commented 1 year ago