sinatra-swagger-exposer icon indicating copy to clipboard operation
sinatra-swagger-exposer copied to clipboard

Getting "Undeclared content type [], if no declaration for the endpoint you should only return json" on every endpoint

Open astrieanna opened this issue 9 years ago • 3 comments

I'm trying to setup Swagger docs for an existing, poorly documented, sinatra server. I'm starting out by just adding documentation to a couple of methods, to expand from there later on.

I added the following decoration to one of the endpoints:

      endpoint_description 'HTML homepage'
      endpoint_produces 'text/html'
      endpoint_response 200, 'file', 'Standard response'
      endpoint_tags 'webface'
      get '/' do
        erb :index
      end

But when the tests hit that endpoint, they get:

@body=["{\"code\":400,\"message\":\"Undeclared content type [], if no declaration for the endpoint you should only return json\"}"]>

I got the same thing with or without the endpoint_produces line. I also get this response on an endpoint that I haven't added any decoration to yet.

Is this a bug or am I doing something wrong?

astrieanna avatar Jul 09 '16 06:07 astrieanna

Sinatra is adding a default html content-type when no content-type is specified, can you try with the 84114c04d55fd5203e181a3770ac0937b4edd7db commit ?

archiloque avatar Jul 13 '16 17:07 archiloque

Thanks! That fixes my problem.

I do still have another error, that seems to be coming from this gem. One of the other endpoints, that I haven't added annotations to yet, returns a response with this body: "{\"error\":\"Not Found. Unknown service: parsed_body\"}". The phrase parsed_body doesn't appear in my code base, so I'm assuming this is happening some where in the gem?

astrieanna avatar Jul 13 '16 18:07 astrieanna

parsed_body parameter should contain the parsed JSON body of the request, since we need to parse it for the validation it's available to the application to avoid another parsing. Do you have a stacktrace of the error ?

archiloque avatar Sep 06 '16 10:09 archiloque