Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

OpenAPI codec does not support definitions for nested objects #37

Open
xxmatyuk opened this issue Jun 9, 2017 · 9 comments
Open

OpenAPI codec does not support definitions for nested objects #37

xxmatyuk opened this issue Jun 9, 2017 · 9 comments

Comments

@xxmatyuk
Copy link

xxmatyuk commented Jun 9, 2017

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
Copy link
Author

xxmatyuk commented Jun 9, 2017

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.

@xxmatyuk xxmatyuk changed the title OpenAPI codec does not support definitions for nested object OpenAPI codec does not support definitions for nested objects Jun 10, 2017
xxmatyuk pushed a commit to xxmatyuk/python-openapi-codec that referenced this issue Jun 11, 2017
@tovmeod
Copy link

tovmeod commented Jun 20, 2017

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
Copy link
Author

xxmatyuk commented Jun 24, 2017

@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
Copy link
Author

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

@tovmeod
Copy link

tovmeod commented Jun 25, 2017

@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
Copy link
Author

xxmatyuk commented Jul 3, 2017

@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
Copy link

tovmeod commented Jul 4, 2017

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
Copy link

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

@xxmatyuk
Copy link
Author

xxmatyuk commented Jan 5, 2018

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

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

No branches or pull requests

3 participants