Skip to content

Commit 0f2bbd7

Browse files
author
Rajkumar Natarajan
committed
fix response header schema
1 parent 3860059 commit 0f2bbd7

File tree

3 files changed

+27
-65
lines changed

3 files changed

+27
-65
lines changed

src/ring/swagger/openapi3.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
(cond-> headers (update-in [:headers] (fn [headers]
8181
(if headers
8282
(->> (for [[k v] headers]
83-
[k (rsjs/->swagger v (into options openapi-opts))])
83+
[k {:schema (rsjs/->swagger v (into options openapi-opts))}])
8484
(into {}))))))
8585
(update-in [:description] #(or %
8686
(:description (rsjs/json-schema-meta v))

src/ring/swagger/openapi3_schema.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@
7373
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 428 429 431 451
7474
500 501 502 503 504 505 506 507 508 510 511])
7575

76-
#_(assert (apply distinct? codes))
77-
#_(assert (apply < codes))
76+
(assert (apply distinct? codes))
77+
(assert (apply < codes))
7878

7979
(s/defschema ResponseCode
80-
(apply s/enum (map str codes)))
80+
(apply s/enum :default "default" (concat (map str codes) (map keyword codes))))
8181

8282
(s/defschema Response
8383
{(opt :description) s/Str

test/ring/swagger/openapi3_test.clj

Lines changed: 23 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
(:require [clojure.test :refer :all]
33
[ring.swagger.openapi3 :refer :all]
44
[schema.core :as s]
5-
[ring.swagger.extension :as extension]
65
[ring.swagger.openapi3-validator :as validator]
76
[midje.sweet :refer :all])
8-
(:import (java.time Instant)
7+
(:import
98
[java.util Date UUID]
109
[java.util.regex Pattern]
1110
[org.joda.time DateTime LocalDate LocalTime]))
@@ -40,39 +39,6 @@
4039
(if-let [output-errors (validate-swagger-json swagger options)]
4140
{:output-errors output-errors}))))
4241

43-
(def a-complete-swagger
44-
{:info {:version "version"
45-
:title "title"
46-
:description "description"
47-
:termsOfService "jeah"
48-
:contact {:name "name"
49-
:url "http://someurl.com"
50-
51-
:license {:name "name"
52-
:url "http://someurl.com"}}
53-
:servers [{:url "somehost:8080"}]
54-
:externalDocs {:url "http://someurl.com"
55-
:description "more info"}
56-
:tags [{:name "pet",
57-
:description "Everything about your Pets",
58-
:externalDocs {:description "Find out more", :url "http://swagger.io"}}
59-
{:name "store",
60-
:description "Access to Petstore orders"}
61-
{:name "user",
62-
:description "Operations about user",
63-
:externalDocs {:description "Find out more about our store", :url "http://swagger.io"}}]
64-
:paths {"/api/:id" {:get {:tags ["pet"]
65-
:summary "summary"
66-
:description "description"
67-
:operationId "operationId"
68-
:parameters {:query (merge Anything {:x Long :y Long})
69-
:path {:id String}
70-
:header Anything}
71-
:responses {"200" {:description "ok"
72-
:content {"application/json" {:schema Parrot}}}
73-
"400" {:description "not found"
74-
:content {"application/json" {:schema nil}}}}}}}})
75-
7642
(def a-complete-swagger-2
7743
{:info {:version "version"
7844
:title "title"
@@ -103,12 +69,12 @@
10369
:parameters {:query (merge Anything {:x Long :y Long})
10470
:path {:id String}
10571
:header Anything}
106-
:responses {"200" {:description "ok"
107-
:content {"application/json" {:schema nil}}}
108-
"400" {:description "not found"
109-
:content {"application/json" {:schema NotFound}}}}
110-
#_"default" #_{:description "error"
111-
:content {"application/json" {:schema {:code Long}}}}}}
72+
:responses {"200" {:description "ok"
73+
:content {"application/json" {:schema nil}}}
74+
"400" {:description "not found"
75+
:content {"application/json" {:schema NotFound}}}
76+
"default" {:description "error"
77+
:content {"application/json" {:schema {:code Long}}}}}}}
11278
"/api/parrots" {:get {:responses {"200" {:description "ok"
11379
:content {"application/json" {:schema Parrot}}}}}}
11480
"/api/all-types" {:get {:requestBody {:content {"application/json" {:a Boolean
@@ -130,36 +96,32 @@
13096
:w #"a[6-9]"}}}}
13197
:responses {"200" {:description "file"
13298
:content {"application/json" {:schema Parrot}}}}}}
133-
"/api/pets" {:get {:parameters {:query (merge Anything {:x Long :y Long})
134-
:path Nothing
135-
:header Anything}
99+
"/api/pets" {:get {:parameters {:query (merge Anything {:x Long :y Long})}
136100
:requestBody {:content {"application/json" Pet}}
137-
:responses {"200" {:description "ok"
138-
:content {"application/json" {:schema {:sum Long}}}}
139-
#_:default #_{:description "error"
140-
:content {"application/json" {:schema Parrot}}}}}
101+
:responses {"200" {:description "ok"
102+
:content {"application/json" {:schema {:sum Long}}}}
103+
"default" {:description "error"
104+
:content {"application/json" {:schema Parrot}}}}}
141105
:post {:parameters {:query (merge Anything {:x Long :y Long})}
142106
:requestBody {:content {"application/json" [Pet]}}
143-
:responses {"200" {:content {"application/xml" {:schema {:sum Long}}}}
144-
#_:default #_{:content {"application/json" {:schema {:code Long}}}
145-
:headers {:location String}}}}
107+
:responses {"200" {:content {"application/xml" {:schema {:sum Long}}}}
108+
"default" {:content {"application/json" {:schema {:code Long}}}
109+
:headers {:location String}}}}
146110
:put {:parameters {:query {:x (s/maybe String)}}
147111
:requestBody {:content {"application/json" [(s/maybe Pet)]}}
148112
:responses {"200" {:description "ok"
149113
:content {"application/json" {:schema {:sum (s/maybe Long)}}}}}}}
150-
"/api/turtle" {:get {:parameters {:query (merge Anything {:x Long :y Long})
151-
:path Nothing
152-
:header Anything}
114+
"/api/turtle" {:get {:parameters {:query (merge Anything {:x Long :y Long})}
153115
:requestBody {:content {"application/json" Turtle}}
154-
:responses {"200" {:description "ok"
155-
:content {"application/json" {:schema {:sum Long}}}}
156-
#_:default #_{:description "error"
157-
:content {"application/json" {:schema {:code Long}}}}}}
116+
:responses {"200" {:description "ok"
117+
:content {"application/json" {:schema {:sum Long}}}}
118+
"default" {:description "error"
119+
:content {"application/json" {:schema {:code Long}}}}}}
158120
:post {:parameters {:query (merge Anything {:x Long :y Long})}
159121
:requestBody {:content {"application/json" [Turtle]}}
160-
:responses {"200" {:content {"application/json" {:schema {:sum Long}}}}
161-
#_:default #_{:content {"application/json" {:schema {:code Long}}}
162-
:headers {:location String}}}}
122+
:responses {"200" {:content {"application/json" {:schema {:sum Long}}}}
123+
"default" {:content {"application/json" {:schema {:code Long}}}
124+
:headers (merge Anything {:location String})}}}
163125
:put {:parameters {:query {:x (s/maybe String)}}
164126
:requestBody {:content {"application/json" [(s/maybe Turtle)]}}
165127
:responses {"200" {:description "ok"

0 commit comments

Comments
 (0)