Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed May 1, 2024
1 parent 295a221 commit 10a1976
Showing 1 changed file with 55 additions and 80 deletions.
135 changes: 55 additions & 80 deletions src/ring/openapi/openapi3_schema.clj
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
(ns ring.openapi.openapi3-schema
(:require [schema.core :as s]
[ring.swagger.swagger2-full-schema :refer [X- length-greater matches opt Contact Info]]))
[ring.swagger.swagger2-full-schema :refer [opt Info]]))

(s/defschema Server-Variable
{
(opt :enum) [s/Str]
:default s/Str
(opt :description) s/Str
})
{(opt :enum) [s/Str]
:default s/Str
(opt :description) s/Str})

(s/defschema Server
{
:url s/Str
{:url s/Str
(opt :description) s/Str
(opt :variables) {s/Str Server-Variable}
})
(opt :variables) {s/Str Server-Variable}})

(s/defschema ExternalDocumentation
{
(opt :description) s/Str
:url s/Str
})
{(opt :description) s/Str
:url s/Str})

(s/defschema OpenApiSchemaPart
{s/Keyword s/Any})

(s/defschema Example
{
(opt :summary) s/Str
{(opt :summary) s/Str
(opt :description) s/Str
(opt :value) s/Any
(opt :externalValue) s/Str})

(s/defschema Header
{
(opt :description) s/Str
{(opt :description) s/Str
:required s/Bool
(opt :deprecated) s/Bool
(opt :allowEmptyValue) s/Bool
Expand All @@ -45,24 +37,20 @@
(opt :examples) {s/Str Example}})

(s/defschema Encoding
{
(opt :contentType) s/Str
{(opt :contentType) s/Str
(opt :headers) {s/Str Header}
(opt :style) s/Any
(opt :explode) s/Bool
(opt :allowReserved) s/Bool})

(s/defschema MediaObject
{
(opt :schema) OpenApiSchemaPart
{(opt :schema) OpenApiSchemaPart
(opt :example) Example
(opt :examples) {s/Str Example}
(opt :encoding) {s/Str Encoding}
})
(opt :encoding) {s/Str Encoding}})

(s/defschema Parameter
{
:name s/Str
{:name s/Str
(opt :in) s/Any
(opt :description) s/Str
:required s/Bool
Expand All @@ -77,35 +65,33 @@
(opt :content) {s/Str MediaObject}})

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

(s/defschema Link
{
(opt :operationRef) s/Str
{(opt :operationRef) s/Str
(opt :operationId) s/Str
(opt :parameters) {s/Str s/Any}
(opt :requestBody) s/Any
(opt :description) s/Str
(opt :server) Server
})
(opt :server) Server})

(s/defschema ResponseCode (s/enum "100" "101" "102" "103" "200" "201" "202" "203" "204" "205" "206" "207" "208" "226" "300" "301" "302" "303" "304" "305" "306" "307" "308" "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" "500" "510" "502" "503" "504" "505" "506" "507" "508" "510" "511"))
(s/defschema ResponseCode
(s/enum "100" "101" "102" "103" "200" "201" "202" "203" "204" "205" "206" "207" "208" "226"
"300" "301" "302" "303" "304" "305" "306" "307" "308"
"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"
"500" "510" "502" "503" "504" "505" "506" "507" "508" "510" "511"))

(s/defschema Response
{
:description s/Str
{:description s/Str
(opt :headers) {s/Str Header}
(opt :content) {s/Str MediaObject}
(opt :links) {s/Str Link}
})
(opt :links) {s/Str Link}})

(s/defschema Operation
{
(opt :tags) [s/Str]
{(opt :tags) [s/Str]
(opt :summary) s/Str
(opt :description) s/Str
(opt :externalDocs) ExternalDocumentation
Expand All @@ -115,73 +101,62 @@
(opt :responses) {ResponseCode Response}
(opt :deprecated) s/Bool
(opt :security) {s/Str [s/Str]}
(opt :servers) [Server]
})
(opt :servers) [Server]})

(s/defschema Path
{
(opt :summary) s/Str
{(opt :summary) s/Str
(opt :description) s/Str
(opt :get) Operation
(opt :put) Operation
(opt :post) Operation
(opt :delete) Operation
(opt :head) Operation
(opt :patch) Operation
(opt :get) Operation
(opt :put) Operation
(opt :post) Operation
(opt :delete) Operation
(opt :head) Operation
(opt :patch) Operation
(opt :servers) [Server]
(opt :parameters) s/Any
})
(opt :parameters) s/Any})

(s/defschema Callback
{s/Str Path})

(s/defschema Tag
{
:name s/Str
{:name s/Str
(opt :description) s/Str
(opt :externalDocs) ExternalDocumentation
})
(opt :externalDocs) ExternalDocumentation})

(s/defschema SecuritySchemeApiKey
{
:type s/Any
{:type s/Any
(opt :description) s/Str
:name s/Str
:in s/Any
})
:in s/Any})

(s/defschema SecuritySchemeHttp
{
:type s/Any
{:type s/Any
(opt :description) s/Str
:scheme s/Str
:bearerFormat s/Str
})
:bearerFormat s/Str})

(s/defschema SecurityScheme
(s/conditional (every-pred map? #(= (:type %) "apiKey")) SecuritySchemeApiKey :else SecuritySchemeHttp))
(s/conditional
#(and (map? %) (= "apiKey" (:type %))) SecuritySchemeApiKey
:else SecuritySchemeHttp))

(s/defschema Components
{
(opt :schemas) {s/Str OpenApiSchemaPart}
{(opt :schemas) {s/Str OpenApiSchemaPart}
(opt :responses) {s/Str Response}
(opt :parameters) {s/Str Parameter}
(opt :examples) {s/Str Example}
(opt :requestBodies) {s/Keyword RequestBody}
(opt :headers) {s/Str Header}
(opt :securitySchemes) {s/Str SecurityScheme}
(opt :links) {s/Str Link}
(opt :callbacks) {s/Str Callback}
})
(opt :callbacks) {s/Str Callback}})

(s/defschema OpenApi
{
(opt :openapi) (s/conditional string? (s/pred #(re-matches #"^3\.\d\.\d$" %)))
(opt :info) Info
(opt :servers) [Server]
(opt :paths) {s/Str Path}
(opt :components) Components
(opt :security) {s/Str [s/Str]}
(opt :tags) [Tag]
(opt :externalDocs) ExternalDocumentation
})
{(opt :openapi) (s/conditional string? (s/pred #(re-matches #"^3\.\d\.\d$" %)))
(opt :info) Info
(opt :servers) [Server]
(opt :paths) {s/Str Path}
(opt :components) Components
(opt :security) {s/Str [s/Str]}
(opt :tags) [Tag]
(opt :externalDocs) ExternalDocumentation})

0 comments on commit 10a1976

Please sign in to comment.