Fork me on GitHub
#reitit
<
2018-12-17
>
ro616:12:51

I'm using Spec to generate Swagger docs, following this example (https://github.com/metosin/reitit/blob/master/examples/ring-spec-swagger/src/example/server.clj). The Swagger UI "Example Value" for one of my responses isn't being generated the way I would expect. Here's the spec definiton:

(ns http.fail
  (:require [clojure.spec.alpha :as s]
            [http.fail.message :as message]))

(s/def ::message (s/keys :req-un [::message/short]
                         :opt-un [::message/full]))

(s/def ::type keyword?)
(s/def ::context map?)

(s/def ::response-body (s/keys :req-un [::message ::type]
                                          :opt-un [::context]))
And the :responses in the route definition:
{200 {:body {:url {:provided    string?
                              :resolved-to string?}}}
 409 {:body ::http.fail/response-body}}
But the Swagger UI only shows
{} 
for the example.

ro617:12:40

So strange, I changed the definition to something else, then back, and now it looks correct:

{
  "message": {
    "short": "string",
    "full": "string"
  },
  "type": "string",
  "context": {}
}
Is it possible there's a caching error in the Swagger UI generation logic?

ro617:12:06

Also, I guess it doesn't do anything special with optional keys at this level?

ikitommi17:12:59

@robert.mather.rmm the ui doesn't show the optional keys, but if you look at the generated swagger JSON file, they are defined there (the list of mandatory keys).

👍 4
ikitommi17:12:31

not sure about the caching at the UI.

ikitommi17:12:03

I think the model tab shows the optional keys?

ikitommi17:12:48

also, I think the form editor shows 'em (there is an ui option to generate html forms out of bodies)