Fork me on GitHub
#ring-swagger
<
2016-05-18
>
trieloff17:05:25

Hi, is there a way to add a entries to the responses map in the generated swagger.json?

trieloff17:05:35

AWS API Gateway wants explicit definitions of status code 200 (and probably 302 as well) and the auto-generation creates only default, which AWS ignores.

trieloff17:05:04

I tried adding it to the :swagger key in my routes, but this fails

trieloff17:05:28

So for now, I’m post-processing the generated JSON, but I can hardly imagine an uglier way to do this.

juhoteperi17:05:10

Also, :return should set :responses 200

trieloff17:05:41

Thanks @juhoteperi – I will try this.

trieloff18:05:46

Does this only work when you enforce a schema?

juhoteperi18:05:24

You could use s/Any if you don't want or can't specify Schema

trieloff18:05:30

I’ve added

:responses { 200 {:schema s/Any}
                              302 {:schema s/Any}}
and I’m still getting the same result.

trieloff18:05:43

"responses": {
          "default": {
            "description": ""
          }
        }

juhoteperi18:05:09

Hmm, are you using latest Compojure-api?

trieloff18:05:14

In fact not even the description does get picked up:

trieloff18:05:17

:responses { 200 {:schema s/Any :description "Default response"}
                            302 {:schema s/Any :description "Redirect to `continue` location”}}

trieloff18:05:19

[metosin/compojure-api "1.1.0”]

juhoteperi18:05:08

Now that I'm looking at the test, I'm not sure if it correctly checks the generated swagger docs

ikitommi18:05:48

(GET "/plus" []
  :responses {200 {:schema {:result s/Int} :description "Default response"}
              302 {:schema s/Any :description "Redirect to `continue` location"}}
  :query-params [x :- Long, y :- Long]
  :summary "adds two numbers together"
  (ok {:result (+ x y)}))

trieloff18:05:40

Works fine when I copy it into my code as is.

ikitommi18:05:41

so, it works ok now?

trieloff18:05:30

It works fine for plus – It does not work for my own routes.

ikitommi18:05:20

hmm.. I can’t make the :swagger work with a value, get a compiler exception.

ikitommi18:05:12

@darean the :swagger value is evaluated at compile-time, could be promoted to run-time, what do you think?

ikitommi19:05:38

I think the resource would work nicely in here. It doesn’t support the same destructuring as normal routes, but it’s fully data driven.

ikitommi19:05:52

something like:

ikitommi19:05:04

(context "/:sheet/:cell" []
  (resource
    {:get {:responses {200 {:schema s/Any :description "Default response"}
                       302 {:schema s/Any :description "Redirect to `continue` location"}
                       500 {:schema {:code String} :description "Horror"}}
           :parameters {:query-params {:speadsheet String
                                      :continue String}
                       :path-params {:sheet Long
                                     :cell String}}
           :summary "Calculate response value from Redirect"
           :swagger aws-gateway-options
           :handler (fn [request]
                      ...)}}))

ikitommi19:05:41

hope this helps

trieloff19:05:34

Thanks, I will have a look.

ikitommi20:05:21

@trieloff: actually, I fixed the :swagger runtime-bindings, so you could try first the [metosin/compojure.api “1.1.1”]