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

[WIP] Use Cornice Swagger to generate the OpenAPI specification #1033

Closed
wants to merge 17 commits into from

Conversation

gabisurita
Copy link
Member

@gabisurita gabisurita commented Jan 25, 2017

Fixes #1006

This is still early WIP but I need some feedback on the architecture. If you think the changes are "too breaking" we can rollback ASAP and find another approach. The more controversial change IMO is to move parts of the schema from resource to a separate module. I've did this to allow imports from other parts of the code that are imported before Service is defined (like errors), and most of the schemas there are not exclusive to resources. Opinions?

Todos:

  • Release cornice_swagger 0.4
  • Add basicauth security.
  • Add missing Tags , operation ids and responses
  • Investigate security extensions. (Documenting security properties? Cornices/cornice.ext.swagger#34)
  • Fix broken tests.
  • Add/Modify schema tests.
  • Add/Modify swagger tests.
  • Sort operations properly.
  • Add documentation.
  • Add a changelog entry.
  • Cleanup .yaml files

Extras (can be finished at other PRs):

r? @glasserc

@glasserc
Copy link
Contributor

I didn't have time to do a thorough review, but from what I see, this looks OK to me. I don't have a problem with concentrating fundamental or common schemas in a schemas module. (In Haskell, sometimes projects will have a Types.hs module where all the models are defined but most of the operations they support omitted. This seems like that to me.) On the other hand, I like better how you put e.g. VersionResponseSchema in the same module as the view that serves versions -- it's closer, so it seems to me like it will be more likely to be modified at the same time. So I would say that we should try to do that as much as we can, and fall back to putting things in schemas if we have to. At first I thought you put things in schemas to re-use them, but I see that e.g. CollectionRequestSchema is only used once?

The ResourceResponses thing seems a little complicated.. I guess this is to simplify shared error responses? It feels like it's tied too tightly to the different views we support.

@glasserc
Copy link
Contributor

I'd love to hear @leplatrem 's thoughts on this!

@@ -113,7 +113,7 @@ def test_validate_headers(self):
for head in headers:
self.request.headers = head
self.assertRaises(ValidationError, unmarshal_request,
self.request, self.resources['Buckets'].get_buckets)
self.request, self.resources['Bucket'].get_buckets)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch.. too bad we have to make dozens of changes like this. Maybe we should try to find a few minutes in a subsequent PR to extract this expression as an attribute on the test case, something like self.swagger_resource?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be good. I mean, now we are generating it automatically I don't think we should test it this way. We can probably think of something better.

@gabisurita
Copy link
Member Author

The ResourceResponses thing seems a little complicated.. I guess this is to simplify shared error responses? It feels like it's tied too tightly to the different views we support.

Hmm, these are actually all the responses for the Resource class, and we are actually changing the record schemas (e.g allowed permissions) for each view during initialization here.

Changing the error responses is not something we would probably do in the server repository, because all storage views have the exactly same error messages. We did the same with the handwritten spec. But there may be some extensions that would like to change it. I just realized we can make responses a Resource attribute rather than a ViewSet attribute, than we could just change the responses messages by setting response_schemas on each Resource derived class.

@gabisurita
Copy link
Member Author

gabisurita commented Jan 27, 2017

So I would say that we should try to do that as much as we can, and fall back to putting things in schemas if we have to. At first I thought you put things in schemas to re-use them, but I see that e.g. CollectionRequestSchema is only used once?

CollectionRequestSchema is used only on resources, and that's why it's on kinto.core.resource.schema. Any and QueryField are reused, and that's why they are on kinto.core.schema. What I did was to move some non resource specific schemas from kinto.core.resource.schema to kinto.core.schema. IMO CollectionRequestSchema should remain in kinto.core.resource.schema.

gabisurita added a commit to gabisurita/kinto that referenced this pull request Feb 1, 2017
This is needed to allow importing generic schemas on other parts
of kinto core without breaking the import order.

Related to Kinto#1033
@gabisurita
Copy link
Member Author

Closed in favor of #1078

@gabisurita gabisurita closed this Feb 14, 2017
@gabisurita gabisurita deleted the cornice-swagger branch February 23, 2017 00:04
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 this pull request may close these issues.

2 participants