Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRFOpenAPISchema and DRFOpenAPIInfo are missing attributes from the openapi specs #42

Open
dolfandringa opened this issue Jul 26, 2023 · 1 comment

Comments

@dolfandringa
Copy link

dolfandringa commented Jul 26, 2023

The openapi specs have more information then the TypedDict's in schemas.openapi allow. This results in type errors if we override some of the fields as described in the docs

For instance this code:

import typing
from rest_framework.request import Request
from rest_framework.schemas.openapi import SchemaGenerator

DRFOpenAPISchema = dict[str, typing.Any]
if typing.TYPE_CHECKING:
    from rest_framework.schemas.openapi import DRFOpenAPISchema


class DataSchemaGenerator(SchemaGenerator):
    def get_info(self):
        info = super().get_info()
        info["termsOfService"] = "https://example.com/tos.html"  
        return info

    def get_schema(
        self, request: Request | None = None, public: bool = False
    ) -> DRFOpenAPISchema:
        schema = super().get_schema(request, public)
        return schema

Results in this error:

Could not assign item in TypedDict  "termsOfService" is not a defined key in "DRFOpenAPIInfo" 
@dolfandringa
Copy link
Author

I saw the comment:
Unfortunately https://github.com/meeshkan/openapi-typed is archived so I don't think it should be used.
https://github.com/openapi-generators/openapi-python-client has a complete pydantic schema which is great, but isn't just a types package. It contains much more and it also depends on python>=3.8 while we depend on python>=3.7 so we can't depend on it. We could just slowly add type information to our own types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant