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

Swagger-UI and application/hal+json #708

Closed
vivin opened this issue Nov 4, 2014 · 6 comments
Closed

Swagger-UI and application/hal+json #708

vivin opened this issue Nov 4, 2014 · 6 comments

Comments

@vivin
Copy link

vivin commented Nov 4, 2014

I'm using swagger-spring-mvc-ui for my Swagger UI. I'm not sure if the issue lies there or not (not entirely clear which version of Swagger UI they are using). I've configured Swagger to use HAL, which means that the /api-docs endpoint vends application/hal+json. However, the Accept: header from Swagger UI seems to say Accept: application/json. This works coincidentally because by default a Spring Boot app recognizes application/json and application/*+json.

However, I was trying to add custom media-types and ran into an issue with Spring Boot where application/json and application/*+json were blown away. So the only producible media-types were application/hal+json and my custom media-type.

Should Swagger UI be using an Accept: header of Accept: application/json,application/hal+json instead? Apologies if this is an issue that has already been fixed, or if I'm missing something totally obvious.

@webron
Copy link
Contributor

webron commented Nov 4, 2014

Yeah, I saw your SO question about it.

For now it seems the UI strictly requests application/json for the api docs.

For now, you can change it locally in your distribution by changing the following line:
https://github.com/swagger-api/swagger-ui/blob/master/dist/lib/swagger-client.js#L335
to whichever content type you need.

I've pointed you to the compiled code since I assume you don't build it yourself. Otherwise, just modify the original swagger-client.js and run the build.

@vivin
Copy link
Author

vivin commented Nov 4, 2014

Awesome! Thanks a bunch! If you add your answer to my SO question I can accept it. I'm not sure if I can modify the source though since I believe it comes from swagger-spring-mvc-ui (I think). But I'll figure something out.

Also, is it alright if I contribute a patch to fix this? Or is it by design that it strictly asks for application/json?

@webron
Copy link
Contributor

webron commented Nov 4, 2014

That's something @fehguy needs to answer.

Eventually, I believe we'd want to go down this road - OAI/OpenAPI-Specification#110 but until then I imagine there shouldn't be a problem with that.

@fehguy
Copy link
Contributor

fehguy commented Nov 4, 2014

This has been asked before--I don't think it's a bad thing to allow configuration of the javascript client with a particular accept header. Will look more, but it's reasonable to me.

@vivin
Copy link
Author

vivin commented Nov 6, 2014

So to confirm, should the line that @webron mentioned be changed to include application/hal+json, or should the entire interface be changed to allow a custom header? I'll try the second approach first.

@fehguy
Copy link
Contributor

fehguy commented Dec 3, 2014

Hi, I believe we would add a new option to configure the default header to use when fetching the resource listing. Happy to merge a PR, but I'd suggest having a value that is set when configuring swagger-ui, which is passed to swagger-js for fetching the resource listings.

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

No branches or pull requests

3 participants