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

Jaxrs defined extension mappings interfere with swagger.json #1169

Closed
sg-ad opened this issue Jun 15, 2015 · 9 comments
Closed

Jaxrs defined extension mappings interfere with swagger.json #1169

sg-ad opened this issue Jun 15, 2015 · 9 comments
Labels
Milestone

Comments

@sg-ad
Copy link

sg-ad commented Jun 15, 2015

Hi,

I'm not sure if this is something that should be fixed or simply documented. I've found that if Jaxrs has been configured with explicit extension mappings (ex: for JSON), it makes it impossible to access the new Swagger resource swagger.json. It's because the /swagger.json will get rewritten to /swagger by Jaxrs, which will no longer resolve to the API listing resource. The same happens if you have a yaml extension mapping defined.

One workaround is to extend the ApiListingResource, map /swagger and internally call either getListingJson(...) or getListingYaml(...).

Cheers,
Sebastien

@webron
Copy link
Contributor

webron commented Jun 15, 2015

Could be the hour for me, but I don't follow you.

@sg-ad
Copy link
Author

sg-ad commented Jun 15, 2015

Sorry I wasn't clear. The JAXRSServerFactoryBean allows you to specify some extension mappings where you map an extension to a content-type. So you can say that all paths ending with .json extension are mapped to application/json content-type. These mappings are used by a Jaxrs request pre-processor that will update the Accept header to include application/json as an accepted content-type if the request path ends with that extension.

Jaxrs will follow this update with a removal of the .json extension from the path. So at the exit of the pre-processor, the request path is now .../swagger instead of .../swagger.json, so it no longer resolves to the resources exposed by ApiListingResource since they explicitly check for the extension.

So I wonder whether this would make a candidate for configuration or simply a case of documentation.

Caveat: judging from the few hits I get when searching, I don't think that configuring extension mappings in Jaxrs is a very widely used feature.

@webron
Copy link
Contributor

webron commented Jun 15, 2015

Whether it is or isn't, it may still be worth investigating. Just keep in mind that the usage of swagger.json and swagger.yaml is based on the standard recommendation specified in the Swagger specification to end up with a common name for the documentation (similarly to the /api-docs in previous versions).

@sg-ad
Copy link
Author

sg-ad commented Jun 15, 2015

Good point. I guess if one wants their API to be discoverable by Swagger-knowledgeable tools, changing the usage won't be a very good workaround. Another (somewhat rudimentary) possibility would be for one to expose the Swagger definitions with a different endpoint on a different root than the rest of the API /spec/swagger.json while the API itself exists under /api/. This assumes that there are no extension mappings configured on /spec/ endpoint. Besides being counterintuitive, would this violate any explicit or implicit convention?

@webron
Copy link
Contributor

webron commented Jun 16, 2015

Funny you should mention it. The specification does not mention where it should be hosted, and then came this - OAI/OpenAPI-Specification#393. It doesn't affect this version, but may affect future ones.

@sg-ad
Copy link
Author

sg-ad commented Jun 16, 2015

Thanks for pointing that out. I'll be curious to see how it develops.

I see you also referenced to #1145 - that basically brings in the workaround that I have now into the fold of Swagger directly. That fix will solve my issue quite nicely. I'm not very clear on the release process, so any idea when it might make it into a release? In the meantime I can continue using my workaround, so there's no particular rush for me.

Thanks for the help, and thanks for such a great tool!

@webron webron added the Feature label Jul 13, 2015
@webron webron added this to the v1.5.1 milestone Jul 13, 2015
@webron
Copy link
Contributor

webron commented Jul 13, 2015

For easier reference, this should now be resolved by #1172.

@webron
Copy link
Contributor

webron commented Jul 13, 2015

Well, not now, but will be resolved with it is merged.

@webron webron modified the milestones: v1.5.1, v1.5.3 Aug 6, 2015
@webron webron modified the milestones: v1.5.3, v1.5.4 Aug 18, 2015
@webron
Copy link
Contributor

webron commented Oct 19, 2015

This is resolved as the PR is merged.

@webron webron closed this as completed Oct 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants