core-api / python-openapi-codec

An OpenAPI codec for Core API.
Other
33 stars 35 forks source link

OpenAPI codec does not support definitions for nested objects #37

Open xxmatyuk opened 7 years ago

xxmatyuk commented 7 years ago

According to official spec, there's definitions objects.

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#definitionsObject

As a result of absence of definitions it's not possible to use references in generated schema.

xxmatyuk commented 7 years ago

I fixed that for my local branch, now a bit messy, when I'm done with clean-up and all the corner cases, I'll come up with the PR.

tovmeod commented 7 years ago

If I understand correctly encode.py should be able to receive a coreschema.schemas.Schema object and return a dictionary as defined in the link above.

I wrote a function that does that to add the objects definitions in swagger, it is not complete but it meet my needs for now, it may be used as an initial commit to start supporting this, if you think this may be accepted into the project I can prepare a PR

xxmatyuk commented 7 years ago

@tovmeod I've already made a PR, check it out. I'm waiting it to be merged. Btw, really need this one in my project.

xxmatyuk commented 7 years ago

@tomchristie, I'm really sorry for being kinda annoying, but would you mind to take a look at the PR.

tovmeod commented 7 years ago

@xxmatyuk you may check what I wrote here: https://github.com/tovmeod/drf-swagger-missing specifically related to encode https://github.com/tovmeod/drf-swagger-missing/blob/master/drf_swagger_missing/openapi_codec_encode.py

I didn't prepare a PR, but we can compare notes.

If I understood correctly you are trying to autogenerate the definitions inside the encoder, my approach was that the document should already have a list of definitions, which in my case it was the user which defined manually, but they could as well be automatic, or a combination

I'm using the definitions for reference in the responses, so for now I am writing them manually and passing them to the Document object, the document object shouldn't care how the definitions list was created, much less the encoder.

Can you explain the logic of what you wrote? how are the definitions generated? what about field descriptions?

xxmatyuk commented 7 years ago

@tovmeod sorry for such a long delay answering to you. I'll clarify each step, but so far, you should not perform any manual steps creating definitions, but I'll be clear on that later on.

tovmeod commented 7 years ago

I made a function that create definitions using the serializer from each view, each serializer have two definitions, read and write, since there are read_only fields and also write_only fields

https://github.com/tovmeod/drf-swagger-missing/blob/master/drf_swagger_missing/rest_framework_schemas.py#L117

richard-reece commented 6 years ago

Came here to post this bug. Will look at the PR next week to see if it solves our use-case.

xxmatyuk commented 6 years ago

@richard-reece I still want to make it, since I came up with the PR, so please wait a bit. Will finish this weekend.