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 to jsonschema #1

Closed
jayvdb opened this issue Jul 10, 2020 · 3 comments · Fixed by #3
Closed

openapi to jsonschema #1

jayvdb opened this issue Jul 10, 2020 · 3 comments · Fixed by #3

Comments

@jayvdb
Copy link
Contributor

jayvdb commented Jul 10, 2020

The logic in strict_schema doesnt descend into the components (i.e. referenced by $ref) and recurse as necessary to do a complete conversion of openapi to jsonschema.

As a result I am seeing

mismatch None is not of type 'string'

Failed validating 'type' in schema['items']['properties']['headerImage']:
    {'format': 'uri', 'nullable': True, 'type': 'string'}

On instance[0]['headerImage']:
    None

I tried to quickly hack a fix using https://github.com/pglass/py-openapi-schema-to-json-schema , but it also doesnt handle complex openapi schema.
Mine is generated by https://github.com/tfranzel/drf-spectacular

instrumenta/openapi2jsonschema#24 says that tool doesnt do it either, but a comment there says that https://github.com/p1c2u/openapi-core works correctly.

It also has some Django helpers https://github.com/p1c2u/openapi-core/blob/master/README.rst#django

@jayvdb
Copy link
Contributor Author

jayvdb commented Jul 11, 2020

pglass/py-openapi-schema-to-json-schema#9 shows that library does work, and could be used to do the conversion to jsonschema if you wanted to keep going down that path. Without my PR, it can still be used if this middleware gave it all of the schema objects within the openapi spec. Unfortunately there a lots of places that schema exist, so I think it makes more sense to convert the entire document once.

@zlqm
Copy link
Owner

zlqm commented Jul 19, 2020

The logic in strict_schema doesnt descend into the components (i.e. referenced by $ref) and recurse as necessary to do a complete conversion of openapi to jsonschema.

i have submit a commit, hope this commit can solved the problem. :)

@jayvdb
Copy link
Contributor Author

jayvdb commented Jul 20, 2020

It sort of did solve the problem, however many logic exceptions occur in the openapi -> jsonschema , when the openapi doesnt contain what the logic expects. Irrespective of whether the openapi spec is properly formed, Django middleware should not create new exceptions unless explicitly requested by the implementor.

#3 tidies that up, and after that it is able to the endpoints in my schema which I have tested so far.

@zlqm zlqm closed this as completed in #3 Jul 20, 2020
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

Successfully merging a pull request may close this issue.

2 participants