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

OpenAPI schema generator is not production ready #7205

Closed
Behoston opened this issue Feb 28, 2020 · 7 comments
Closed

OpenAPI schema generator is not production ready #7205

Behoston opened this issue Feb 28, 2020 · 7 comments

Comments

@Behoston
Copy link
Contributor

Behoston commented Feb 28, 2020

I have general issue with Open API schema generator, it looks like someone wants too hard to deliver this. I decided to create one issue for all problems and not use template - sorry.

  • Previously created issue: Error mapping Python regex to OpenAPI. #7204 - URL regexp is invalid for swagger editor (works with Swagger UI, but many other tools just fails, UI can work even if schema is very bad, so please do not use it as reference).
  • Create status code are 200, should be 201
  • Required fields in response is empty list if no fields required but should be absent. required: []
  • Security schemes is not supported at all, but swagger can differ depends on user is logged whether or not (already implemented, so it's inconsistent).

In most cases, schema is invalid or not representing actual API. I think, you should revert this feature, fix all issues, add some tests then release it again. Other source code in DRF is top quality, but this part looks/works bad :/

@Behoston
Copy link
Contributor Author

Behoston commented Feb 28, 2020

I searched deeper and I foud that empty list in required should works
swagger-api/swagger-editor#2113

edit:
It will be allowed in OAS3.1 but in OAS3.0 is not allowed.

@Behoston
Copy link
Contributor Author

Behoston commented Mar 1, 2020

  • ListSerializer does not work with child
    serializer:
class CitiesSerializer(serializers.ListSerializer):
   child = serializers.CharField(read_only=True, allow_null=False)

schema.json:

    "/api/core/cities/": {
      "get": {
        "operationId": "listCities",
        "description": "",
        "parameters": [],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {}
                }
              }
            },
            "description": ""
          }
        }
      }
    },

@carltongibson
Copy link
Collaborator

carltongibson commented Mar 1, 2020

Hi @Behoston. Sorry it’s not up to your standards. It is open source, and built with volunteer effort, so there’s a easy way to improve it.

The schema generation is very young in contrast to the rest of the code. It’s coming on nicely, with some fixes, tags, components,... targeted for the next release. You say not production ready. I say maturing nicely. 🤷‍♂️

I don’t think, even with **’s replacing expletives, that the tone of your comment is appropriate, so I would ask you to moderate that. Thanks. 👍

Very happy to see issue reports. That’s the best way to fill in the gaps.

@carltongibson
Copy link
Collaborator

Looking at the individual issues, except Security schemes — which is a bigger change, but for now you can subclass SchemaGenerator to add — they all should be addressable. PRs very welcome!

Create status code are 200, should be 201

Yes. Ideally we'd map the response code from the mixins (and viewset actions) That would be a nice addition.

Individual tickets would be better — not least because people see them and can take them on. I'll leave this open as it is so we don't loose track but, if you have time to create the separate tickets that would be good.

@Behoston
Copy link
Contributor Author

Behoston commented Mar 1, 2020

Ok, I'll try.
Locally I have much more hax in subclass :P

@carltongibson
Copy link
Collaborator

Super. Happy to comment on PRs if you want input and open them early.

@Olokor
Copy link

Olokor commented Jan 12, 2023

i'm new to django, i tried running this command: python manage.py generateschema > openapi-schema.yml
and i got some error i can't quite fix

raise TypeError(

TypeError: Post() got unexpected keyword arguments: 'context'

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

No branches or pull requests

3 participants