This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-18
Channels
- # aws-lambda (3)
- # beginners (57)
- # boot (3)
- # bristol-clojurians (1)
- # cider (38)
- # cljs-dev (23)
- # clojure (35)
- # clojure-italy (32)
- # clojure-nl (6)
- # clojure-spec (35)
- # clojure-uk (132)
- # clojurescript (34)
- # cursive (22)
- # data-science (1)
- # datomic (54)
- # devcards (1)
- # duct (5)
- # editors (7)
- # euroclojure (4)
- # fulcro (40)
- # graphql (1)
- # hoplon (6)
- # immutant (5)
- # jobs (1)
- # off-topic (22)
- # om (1)
- # planck (17)
- # portkey (1)
- # protorepl (12)
- # re-frame (97)
- # reagent (67)
- # reitit (16)
- # ring-swagger (1)
- # shadow-cljs (98)
- # spacemacs (8)
- # sql (20)
- # tools-deps (60)
@seantempesta did you set the :securityDefinitions
?
Yeah, I tried that. Here’s the full definition I’m using (borrowed from https://github.com/metosin/reitit/tree/master/examples/ring-swagger):
(swagger-ui/create-swagger-ui-handler
{:path "/"
:url "/api/swagger.json"
:config {:securityDefinitions
{:api_key
{:type "apiKey"
:name "x-apikey"
:in "header"}}}})
and it’s still not showing up. Does anyone have an example that’s working?Yep, that did it. I feel stupid now. Thanks! @ikitommi For anyone else who is curious, this is the diff from the example:
diff --git a/examples/ring-swagger/src/example/server.clj b/examples/ring-swagger/src/example/server.clj
index 341342b..32d87d8 100644
--- a/examples/ring-swagger/src/example/server.clj
+++ b/examples/ring-swagger/src/example/server.clj
@@ -18,60 +18,65 @@
{:swagger {:id ::math}}
["/swagger.json"
- {:get {:no-doc true
- :swagger {:info {:title "my-api"}}
+ {:get {:no-doc true
+ :swagger {:info {:title "my-api"}
+ :securityDefinitions
+ {:api_key
+ {:type "apiKey"
+ :name "x-apikey"
+ :in "header"}}}
:handler (swagger/create-swagger-handler)}}]
e.f. set swagger-data:
{:securityDefinitions
{:api_key
{:type "apiKey"
:name "x-apikey"
:in "header"}}}
speccing xml sounds like lots of typing -- the problem then will be that clojure's representation of xml (and my specs for it) will have to be converted to swagger's expected format as described at https://github.com/OAI/OpenAPI-Specification/blob/master/fixtures/v2.0/json/models/modelWithXmlAttributes.json
@vale the reitit + spec + XML. If you have a XML body parsing middleware mounted, you need to describe the Swagger XML stuff manually for specs. Haven’t heard that there is a automatic converter for spec -> SwaggerXML (or XML Schema). Something like:
(require '[clojure.spec.alpha :as s])
(require '[spec-tools.core :as st])
(s/def ::id
(st/spec
{:spec int?
:json-schema/xml {:attribute true
:namespac "ns1"
:prefix "urn1"}}))
(s/def ::items
(st/spec
{:spec (s/coll-of string?)
:json-schema/xml {:wrapped true}}))
(s/def ::model
(st/spec
{:spec (s/keys :opt-un [::id ::items])
:json-schema/xml {:name "XMLModel"}}))
(require '[spec-tools.swagger.core :as swagger])
(swagger/transform ::model)
;{:type "object"
; :xml {:name "XMLModel"}
; :properties {"id" {:type "integer"
; :format "int64"
; :xml {:attribute true
; :namespac "ns1"
; :prefix "urn1"}}
; "items" {:type "array"
; :items {:type "string"}
; :xml {:wrapped true}}}}
not sure it’s worth the trouble defining all the fields like that, you can always write the swagger spec by hand. Just paste anything valid under :swagger
and it should work.
… but the integration here is that any keys for Spec
data that starts with json-schema
is merged on top of the normal spec->swagger/json-schema conversion.
this is great reference, thanks! i'll be sure to get back to you once i got it to work (hopefully tomorrow)
Yeah, I tried that. Here’s the full definition I’m using (borrowed from https://github.com/metosin/reitit/tree/master/examples/ring-swagger):
(swagger-ui/create-swagger-ui-handler
{:path "/"
:url "/api/swagger.json"
:config {:securityDefinitions
{:api_key
{:type "apiKey"
:name "x-apikey"
:in "header"}}}})
and it’s still not showing up. Does anyone have an example that’s working?@seantempesta you need to put it route data under :swagger
, to any place that is in the path to the endpoint serving swagger spec. E.g. here: https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj#L22
the :config
in the swagger-ui-handler is for swagger-ui configuration, described here: https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
Yep, that did it. I feel stupid now. Thanks! @ikitommi For anyone else who is curious, this is the diff from the example:
diff --git a/examples/ring-swagger/src/example/server.clj b/examples/ring-swagger/src/example/server.clj
index 341342b..32d87d8 100644
--- a/examples/ring-swagger/src/example/server.clj
+++ b/examples/ring-swagger/src/example/server.clj
@@ -18,60 +18,65 @@
{:swagger {:id ::math}}
["/swagger.json"
- {:get {:no-doc true
- :swagger {:info {:title "my-api"}}
+ {:get {:no-doc true
+ :swagger {:info {:title "my-api"}
+ :securityDefinitions
+ {:api_key
+ {:type "apiKey"
+ :name "x-apikey"
+ :in "header"}}}
:handler (swagger/create-swagger-handler)}}]