Skip to content

Commit

Permalink
fix the parameter schema
Browse files Browse the repository at this point in the history
  • Loading branch information
rajcspsg committed May 24, 2024
1 parent f8b8e59 commit 0001b2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 12 additions & 4 deletions src/ring/swagger/json_schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@

schema.core.Maybe
(convert [e {:keys [in] :as options}]
(let [schema (->swagger (:schema e) options)]
(let [schema (->swagger (:schema e) options)
schema-type (opts->schema-type options)
nullable-key (if (= schema-type :openapi) :nullable :x-nullable)]
(condp contains? in
#{:query :formData} (assoc schema :allowEmptyValue true)
#{nil :body} (assoc schema :x-nullable true)
#{nil :body} (assoc schema nullable-key true)
schema)))

schema.core.Both
Expand Down Expand Up @@ -226,11 +228,17 @@

schema.core.ConditionalSchema
(convert [e options]
{:x-oneOf (vec (keep #(->swagger (second %) options) (:preds-and-schemas e)))})
(let [schema-type (opts->schema-type options)
schema (vec (keep #(->swagger (second %) options) (:preds-and-schemas e)))
schema-key (if (= schema-type :openapi) :oneOf :x-oneOf)]
{schema-key schema}))

schema.core.CondPre
(convert [e options]
{:x-oneOf (mapv #(->swagger % options) (:schemas e))})
(let [schema-type (opts->schema-type options)
schema (mapv #(->swagger % options) (:schemas e))
schema-key (if (= schema-type :openapi) :oneOf :x-oneOf)]
{schema-key schema}))

schema.core.Constrained
(convert [e options]
Expand Down
10 changes: 5 additions & 5 deletions src/ring/swagger/openapi3_schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
(opt :encoding) {s/Str Encoding}})

(s/defschema Parameter
{(opt :query) s/Any
(opt :path) s/Any
(opt :header) s/Any})
{(opt :query) {s/Any s/Any}
(opt :path) {s/Any s/Any}
(opt :header) {s/Any s/Any}})

(s/defschema RequestBody
{(opt :description) s/Str
:content {s/Str MediaObject}
:content {s/Str MediaObject}
(opt :required) s/Bool})

(s/defschema Link
Expand Down Expand Up @@ -91,7 +91,7 @@
(opt :description) s/Str
(opt :externalDocs) ExternalDocumentation
(opt :operationId) s/Str
(opt :parameters) [Parameter]
(opt :parameters) Parameter
(opt :requestBody) RequestBody
(opt :responses) {ResponseCode Response}
(opt :deprecated) s/Bool
Expand Down

0 comments on commit 0001b2d

Please sign in to comment.