java - Swagger-UI doesn't recognize application/hal+json -



java - Swagger-UI doesn't recognize application/hal+json -

i have restful api spring boot application. ran when trying figure out separate issue involved trying add together custom media-types.

after trying got httpmediatypenotacceptable exception when seek view api documentation. exception visible in logs (if turn level debug). on browser see 406 undefined. here's screenshot:

the exception spring boot's logs this:

2014-11-04 10:08:26.189 debug 5496 --- [nio-8080-exec-9] .w.s.m.s.defaulthandlerexceptionresolver : resolving exception handler [public org.springframework.http.responseentity<com.wordnik.swagger.model.resourcelisting> com.mangofactory.swagger.controllers.defaultswaggercontroller.getresourcelisting(java.lang.string)]: org.springframework.web.httpmediatypenotacceptableexception: not find acceptable representation

the root of problem existing, producible-media-types overwritten.

without code above, list contains:

application/hal+json application/json;charset=utf-8 application/*+json;charset=utf-8.

with changes, list contains application/hal+json , custom media-type. happens spring cannot find compatible media-type @ because swagger ui has application/json in accept: header whereas http://localhost:8080/api-docs vends application/hal+json (i verified using curl):

http/1.1 200 ok server: apache-coyote/1.1 x-content-type-options: nosniff x-xss-protection: 1; mode=block cache-control: no-cache, no-store, max-age=0, must-revalidate pragma: no-cache expires: 0 x-frame-options: deny x-application-context: application content-type: application/hal+json transfer-encoding: chunked date: tue, 04 nov 2014 16:56:57 gmt

i'm guessing swagger ui should set take header application/json,application/hal+json or perhaps utilize wildcard application/*+json.

the current solution update swagger-client.js - part swaggerclient built, hard coded application/json mime type.

the current line of code https://github.com/swagger-api/swagger-ui/blob/master/dist/lib/swagger-client.js#l335 though may alter in different versions (so may not relevant in future when reading answer).

the swagger-client.js exists in 2 places - /dist/lib dir pre-built application or straight under /lib dir build process. should alter value depending on you're using.

java spring rest swagger swagger-ui

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -