git.iko.soy/typeable/openapi3
on master help sign in
change SwaggerType to OpenApiType
1d2e9d2Paweł Nosal
examples/hackage.hs+1−1
@@ -27,7 +27,7 @@ instance ToSchema UserSummary where
27 usernameSchema <- declareSchemaRef (Proxy :: Proxy Username)
27 usernameSchema <- declareSchemaRef (Proxy :: Proxy Username)
28 useridSchema <- declareSchemaRef (Proxy :: Proxy Int)
28 useridSchema <- declareSchemaRef (Proxy :: Proxy Int)
29 return $ NamedSchema (Just "UserSummary") $ mempty
29 return $ NamedSchema (Just "UserSummary") $ mempty
30− & type_ ?~ SwaggerObject
30+ & type_ ?~ OpenApiObject
31 & properties .~
31 & properties .~
32 [ ("summaryUsername", usernameSchema )
32 [ ("summaryUsername", usernameSchema )
33 , ("summaryUserid" , useridSchema )
33 , ("summaryUserid" , useridSchema )
src/Data/OpenApi.hs+4−4
@@ -56,7 +56,7 @@ module Data.OpenApi (
56 TagName,
56 TagName,
57
57
58 -- ** Types and formats
58 -- ** Types and formats
59− SwaggerType(..),
59+ OpenApiType(..),
60 Format,
60 Format,
61 Definitions,
61 Definitions,
62 Style(..),
62 Style(..),
@@ -194,7 +194,7 @@ import Data.OpenApi.Internal
194--
194--
195-- >>> :{
195-- >>> :{
196-- BSL.putStrLn $ encode $ (mempty :: OpenApi)
196-- BSL.putStrLn $ encode $ (mempty :: OpenApi)
197−-- & components . schemas .~ [ ("User", mempty & type_ ?~ SwaggerString) ]
197+-- & components . schemas .~ [ ("User", mempty & type_ ?~ OpenApiString) ]
198-- & paths .~
198-- & paths .~
199-- [ ("/user", mempty & get ?~ (mempty
199-- [ ("/user", mempty & get ?~ (mempty
200-- & at 200 ?~ ("OK" & _Inline.content.at "application/json" ?~ (mempty & schema ?~ Ref (Reference "User")))
200-- & at 200 ?~ ("OK" & _Inline.content.at "application/json" ?~ (mempty & schema ?~ Ref (Reference "User")))
@@ -216,7 +216,7 @@ import Data.OpenApi.Internal
216-- {"description":"No content"}
216-- {"description":"No content"}
217-- >>> :{
217-- >>> :{
218-- BSL.putStrLn $ encode $ (mempty :: Schema)
218-- BSL.putStrLn $ encode $ (mempty :: Schema)
219−-- & type_ ?~ SwaggerBoolean
219+-- & type_ ?~ OpenApiBoolean
220-- & description ?~ "To be or not to be"
220-- & description ?~ "To be or not to be"
221-- :}
221-- :}
222-- {"type":"boolean","description":"To be or not to be"}
222-- {"type":"boolean","description":"To be or not to be"}
@@ -244,7 +244,7 @@ import Data.OpenApi.Internal
244-- @'ParamSchema'@ and @'Schema'@ are the two core types for data model specification.
244-- @'ParamSchema'@ and @'Schema'@ are the two core types for data model specification.
245--
245--
246-- @'ParamSchema' t@ specifies all the common properties, available for every data schema.
246-- @'ParamSchema' t@ specifies all the common properties, available for every data schema.
247−-- The @t@ parameter imposes some restrictions on @type@ and @items@ properties (see @'SwaggerType'@ and @'SwaggerItems'@).
247+-- The @t@ parameter imposes some restrictions on @type@ and @items@ properties (see @'OpenApiType'@ and @'SwaggerItems'@).
248--
248--
249-- @'Schema'@ is used for request and response bodies and allows specifying objects
249-- @'Schema'@ is used for request and response bodies and allows specifying objects
250-- with properties in addition to what @'ParamSchema'@ provides.
250-- with properties in addition to what @'ParamSchema'@ provides.
src/Data/OpenApi/Internal.hs+15−15
@@ -571,7 +571,7 @@ data Link = Link
571 , _linkServer :: Maybe Server
571 , _linkServer :: Maybe Server
572 } deriving (Eq, Show, Generic, Typeable, Data)
572 } deriving (Eq, Show, Generic, Typeable, Data)
573
573
574−-- | Items for @'SwaggerArray'@ schemas.
574+-- | Items for @'OpenApiArray'@ schemas.
575--
575--
576-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
576-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
577-- it will incorporate Json Schema mostly verbatim.
577-- it will incorporate Json Schema mostly verbatim.
@@ -584,14 +584,14 @@ data SwaggerItems where
584 SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems
584 SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems
585 deriving (Eq, Show, Typeable, Data)
585 deriving (Eq, Show, Typeable, Data)
586
586
587−data SwaggerType where
587+data OpenApiType where
588− SwaggerString :: SwaggerType
588+ OpenApiString :: OpenApiType
589− SwaggerNumber :: SwaggerType
589+ OpenApiNumber :: OpenApiType
590− SwaggerInteger :: SwaggerType
590+ OpenApiInteger :: OpenApiType
591− SwaggerBoolean :: SwaggerType
591+ OpenApiBoolean :: OpenApiType
592− SwaggerArray :: SwaggerType
592+ OpenApiArray :: OpenApiType
593− SwaggerNull :: SwaggerType
593+ OpenApiNull :: OpenApiType
594− SwaggerObject :: SwaggerType
594+ OpenApiObject :: OpenApiType
595 deriving (Eq, Show, Typeable, Generic, Data)
595 deriving (Eq, Show, Typeable, Generic, Data)
596
596
597data ParamLocation
597data ParamLocation
@@ -643,7 +643,7 @@ data Schema = Schema
643 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
643 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
644 _schemaDefault :: Maybe Value
644 _schemaDefault :: Maybe Value
645
645
646− , _schemaType :: Maybe SwaggerType
646+ , _schemaType :: Maybe OpenApiType
647 , _schemaFormat :: Maybe Format
647 , _schemaFormat :: Maybe Format
648 , _schemaItems :: Maybe SwaggerItems
648 , _schemaItems :: Maybe SwaggerItems
649 , _schemaMaximum :: Maybe Scientific
649 , _schemaMaximum :: Maybe Scientific
@@ -1085,8 +1085,8 @@ instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
1085instance SwaggerMonoid MimeList
1085instance SwaggerMonoid MimeList
1086deriving instance SwaggerMonoid URL
1086deriving instance SwaggerMonoid URL
1087
1087
1088−instance SwaggerMonoid SwaggerType where
1088+instance SwaggerMonoid OpenApiType where
1089− swaggerMempty = SwaggerString
1089+ swaggerMempty = OpenApiString
1090 swaggerMappend _ y = y
1090 swaggerMappend _ y = y
1091
1091
1092instance SwaggerMonoid ParamLocation where
1092instance SwaggerMonoid ParamLocation where
@@ -1109,7 +1109,7 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
1109instance ToJSON Style where
1109instance ToJSON Style where
1110 toJSON = genericToJSON (jsonPrefix "Style")
1110 toJSON = genericToJSON (jsonPrefix "Style")
1111
1111
1112−instance ToJSON SwaggerType where
1112+instance ToJSON OpenApiType where
1113 toJSON = genericToJSON (jsonPrefix "Swagger")
1113 toJSON = genericToJSON (jsonPrefix "Swagger")
1114
1114
1115instance ToJSON ParamLocation where
1115instance ToJSON ParamLocation where
@@ -1164,7 +1164,7 @@ instance ToJSON OAuth2AuthorizationCodeFlow where
1164instance FromJSON Style where
1164instance FromJSON Style where
1165 parseJSON = genericParseJSON (jsonPrefix "Style")
1165 parseJSON = genericParseJSON (jsonPrefix "Style")
1166
1166
1167−instance FromJSON SwaggerType where
1167+instance FromJSON OpenApiType where
1168 parseJSON = genericParseJSON (jsonPrefix "Swagger")
1168 parseJSON = genericParseJSON (jsonPrefix "Swagger")
1169
1169
1170instance FromJSON ParamLocation where
1170instance FromJSON ParamLocation where
@@ -1545,7 +1545,7 @@ instance AesonDefaultValue OAuth2AuthorizationCodeFlow
1545instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
1545instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
1546instance AesonDefaultValue Responses
1546instance AesonDefaultValue Responses
1547instance AesonDefaultValue SecuritySchemeType
1547instance AesonDefaultValue SecuritySchemeType
1548−instance AesonDefaultValue SwaggerType
1548+instance AesonDefaultValue OpenApiType
1549instance AesonDefaultValue MimeList where defaultValue = Just mempty
1549instance AesonDefaultValue MimeList where defaultValue = Just mempty
1550instance AesonDefaultValue Info
1550instance AesonDefaultValue Info
1551instance AesonDefaultValue ParamLocation
1551instance AesonDefaultValue ParamLocation
src/Data/OpenApi/Internal/ParamSchema.hs+21−21
@@ -52,20 +52,20 @@ import GHC.TypeLits (TypeError, ErrorMessage(..))
52-- | Default schema for binary data (any sequence of octets).
52-- | Default schema for binary data (any sequence of octets).
53binarySchema :: Schema
53binarySchema :: Schema
54binarySchema = mempty
54binarySchema = mempty
55− & type_ ?~ SwaggerString
55+ & type_ ?~ OpenApiString
56 & format ?~ "binary"
56 & format ?~ "binary"
57
57
58-- | Default schema for binary data (base64 encoded).
58-- | Default schema for binary data (base64 encoded).
59byteSchema :: Schema
59byteSchema :: Schema
60byteSchema = mempty
60byteSchema = mempty
61− & type_ ?~ SwaggerString
61+ & type_ ?~ OpenApiString
62 & format ?~ "byte"
62 & format ?~ "byte"
63
63
64-- | Default schema for password string.
64-- | Default schema for password string.
65-- @"password"@ format is used to hint UIs the input needs to be obscured.
65-- @"password"@ format is used to hint UIs the input needs to be obscured.
66passwordSchema :: Schema
66passwordSchema :: Schema
67passwordSchema = mempty
67passwordSchema = mempty
68− & type_ ?~ SwaggerString
68+ & type_ ?~ OpenApiString
69 & format ?~ "password"
69 & format ?~ "password"
70
70
71-- | Convert a type into a plain @'Schema'@.
71-- | Convert a type into a plain @'Schema'@.
@@ -87,7 +87,7 @@ passwordSchema = mempty
87--
87--
88-- instance ToParamSchema Direction where
88-- instance ToParamSchema Direction where
89-- toParamSchema _ = mempty
89-- toParamSchema _ = mempty
90−-- & type_ ?~ SwaggerString
90+-- & type_ ?~ OpenApiString
91-- & enum_ ?~ [ \"Up\", \"Down\" ]
91-- & enum_ ?~ [ \"Up\", \"Down\" ]
92-- @
92-- @
93--
93--
@@ -119,17 +119,17 @@ class ToParamSchema a where
119 toParamSchema = genericToParamSchema defaultSchemaOptions
119 toParamSchema = genericToParamSchema defaultSchemaOptions
120
120
121instance {-# OVERLAPPING #-} ToParamSchema String where
121instance {-# OVERLAPPING #-} ToParamSchema String where
122− toParamSchema _ = mempty & type_ ?~ SwaggerString
122+ toParamSchema _ = mempty & type_ ?~ OpenApiString
123
123
124instance ToParamSchema Bool where
124instance ToParamSchema Bool where
125− toParamSchema _ = mempty & type_ ?~ SwaggerBoolean
125+ toParamSchema _ = mempty & type_ ?~ OpenApiBoolean
126
126
127instance ToParamSchema Integer where
127instance ToParamSchema Integer where
128− toParamSchema _ = mempty & type_ ?~ SwaggerInteger
128+ toParamSchema _ = mempty & type_ ?~ OpenApiInteger
129
129
130instance ToParamSchema Natural where
130instance ToParamSchema Natural where
131 toParamSchema _ = mempty
131 toParamSchema _ = mempty
132− & type_ ?~ SwaggerInteger
132+ & type_ ?~ OpenApiInteger
133 & minimum_ ?~ 0
133 & minimum_ ?~ 0
134 & exclusiveMinimum ?~ False
134 & exclusiveMinimum ?~ False
135
135
@@ -159,37 +159,37 @@ instance ToParamSchema Word64 where
159-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
159-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
160toParamSchemaBoundedIntegral :: forall a t. (Bounded a, Integral a) => Proxy a -> Schema
160toParamSchemaBoundedIntegral :: forall a t. (Bounded a, Integral a) => Proxy a -> Schema
161toParamSchemaBoundedIntegral _ = mempty
161toParamSchemaBoundedIntegral _ = mempty
162− & type_ ?~ SwaggerInteger
162+ & type_ ?~ OpenApiInteger
163 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
163 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
164 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
164 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
165
165
166instance ToParamSchema Char where
166instance ToParamSchema Char where
167 toParamSchema _ = mempty
167 toParamSchema _ = mempty
168− & type_ ?~ SwaggerString
168+ & type_ ?~ OpenApiString
169 & maxLength ?~ 1
169 & maxLength ?~ 1
170 & minLength ?~ 1
170 & minLength ?~ 1
171
171
172instance ToParamSchema Scientific where
172instance ToParamSchema Scientific where
173− toParamSchema _ = mempty & type_ ?~ SwaggerNumber
173+ toParamSchema _ = mempty & type_ ?~ OpenApiNumber
174
174
175instance HasResolution a => ToParamSchema (Fixed a) where
175instance HasResolution a => ToParamSchema (Fixed a) where
176 toParamSchema _ = mempty
176 toParamSchema _ = mempty
177− & type_ ?~ SwaggerNumber
177+ & type_ ?~ OpenApiNumber
178 & multipleOf ?~ (recip . fromInteger $ resolution (Proxy :: Proxy a))
178 & multipleOf ?~ (recip . fromInteger $ resolution (Proxy :: Proxy a))
179
179
180instance ToParamSchema Double where
180instance ToParamSchema Double where
181 toParamSchema _ = mempty
181 toParamSchema _ = mempty
182− & type_ ?~ SwaggerNumber
182+ & type_ ?~ OpenApiNumber
183 & format ?~ "double"
183 & format ?~ "double"
184
184
185instance ToParamSchema Float where
185instance ToParamSchema Float where
186 toParamSchema _ = mempty
186 toParamSchema _ = mempty
187− & type_ ?~ SwaggerNumber
187+ & type_ ?~ OpenApiNumber
188 & format ?~ "float"
188 & format ?~ "float"
189
189
190timeParamSchema :: String -> Schema
190timeParamSchema :: String -> Schema
191timeParamSchema fmt = mempty
191timeParamSchema fmt = mempty
192− & type_ ?~ SwaggerString
192+ & type_ ?~ OpenApiString
193 & format ?~ T.pack fmt
193 & format ?~ T.pack fmt
194
194
195-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
195-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -231,12 +231,12 @@ instance ToParamSchema TL.Text where
231
231
232instance ToParamSchema Version where
232instance ToParamSchema Version where
233 toParamSchema _ = mempty
233 toParamSchema _ = mempty
234− & type_ ?~ SwaggerString
234+ & type_ ?~ OpenApiString
235 & pattern ?~ "^\\d+(\\.\\d+)*$"
235 & pattern ?~ "^\\d+(\\.\\d+)*$"
236
236
237instance ToParamSchema SetCookie where
237instance ToParamSchema SetCookie where
238 toParamSchema _ = mempty
238 toParamSchema _ = mempty
239− & type_ ?~ SwaggerString
239+ & type_ ?~ OpenApiString
240
240
241type family ToParamSchemaByteStringError bs where
241type family ToParamSchemaByteStringError bs where
242 ToParamSchemaByteStringError bs = TypeError
242 ToParamSchemaByteStringError bs = TypeError
@@ -259,7 +259,7 @@ instance ToParamSchema a => ToParamSchema (Identity a) where toParamSchema _ = t
259
259
260instance ToParamSchema a => ToParamSchema [a] where
260instance ToParamSchema a => ToParamSchema [a] where
261 toParamSchema _ = mempty
261 toParamSchema _ = mempty
262− & type_ ?~ SwaggerArray
262+ & type_ ?~ OpenApiArray
263 & items ?~ SwaggerItemsObject (Inline $ toParamSchema (Proxy :: Proxy a))
263 & items ?~ SwaggerItemsObject (Inline $ toParamSchema (Proxy :: Proxy a))
264
264
265instance ToParamSchema a => ToParamSchema (V.Vector a) where toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
265instance ToParamSchema a => ToParamSchema (V.Vector a) where toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
@@ -279,12 +279,12 @@ instance ToParamSchema a => ToParamSchema (HashSet a) where
279-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
279-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
280instance ToParamSchema () where
280instance ToParamSchema () where
281 toParamSchema _ = mempty
281 toParamSchema _ = mempty
282− & type_ ?~ SwaggerString
282+ & type_ ?~ OpenApiString
283 & enum_ ?~ ["_"]
283 & enum_ ?~ ["_"]
284
284
285instance ToParamSchema UUID where
285instance ToParamSchema UUID where
286 toParamSchema _ = mempty
286 toParamSchema _ = mempty
287− & type_ ?~ SwaggerString
287+ & type_ ?~ OpenApiString
288 & format ?~ "uuid"
288 & format ?~ "uuid"
289
289
290-- | A configurable generic @'Schema'@ creator.
290-- | A configurable generic @'Schema'@ creator.
@@ -322,7 +322,7 @@ instance (GEnumParamSchema f, GEnumParamSchema g) => GEnumParamSchema (f :+: g)
322
322
323instance Constructor c => GEnumParamSchema (C1 c U1) where
323instance Constructor c => GEnumParamSchema (C1 c U1) where
324 genumParamSchema opts _ s = s
324 genumParamSchema opts _ s = s
325− & type_ ?~ SwaggerString
325+ & type_ ?~ OpenApiString
326 & enum_ %~ addEnumValue tag
326 & enum_ %~ addEnumValue tag
327 where
327 where
328 tag = toJSON (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
328 tag = toJSON (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
src/Data/OpenApi/Internal/Schema.hs+34−34
@@ -105,7 +105,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
105-- declareNamedSchema _ = do
105-- declareNamedSchema _ = do
106-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
106-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
107-- return $ NamedSchema (Just \"Coord\") $ mempty
107-- return $ NamedSchema (Just \"Coord\") $ mempty
108−-- & type_ ?~ SwaggerObject
108+-- & type_ ?~ OpenApiObject
109-- & properties .~
109-- & properties .~
110-- [ (\"x\", doubleSchema)
110-- [ (\"x\", doubleSchema)
111-- , (\"y\", doubleSchema)
111-- , (\"y\", doubleSchema)
@@ -312,12 +312,12 @@ sketchSchema = sketch . toJSON
312 sketch js@(Bool _) = go js
312 sketch js@(Bool _) = go js
313 sketch js = go js & example ?~ js
313 sketch js = go js & example ?~ js
314
314
315− go Null = mempty & type_ ?~ SwaggerNull
315+ go Null = mempty & type_ ?~ OpenApiNull
316− go (Bool _) = mempty & type_ ?~ SwaggerBoolean
316+ go (Bool _) = mempty & type_ ?~ OpenApiBoolean
317− go (String _) = mempty & type_ ?~ SwaggerString
317+ go (String _) = mempty & type_ ?~ OpenApiString
318− go (Number _) = mempty & type_ ?~ SwaggerNumber
318+ go (Number _) = mempty & type_ ?~ OpenApiNumber
319 go (Array xs) = mempty
319 go (Array xs) = mempty
320− & type_ ?~ SwaggerArray
320+ & type_ ?~ OpenApiArray
321 & items ?~ case ischema of
321 & items ?~ case ischema of
322 Just s -> SwaggerItemsObject (Inline s)
322 Just s -> SwaggerItemsObject (Inline s)
323 _ -> SwaggerItemsArray (map Inline ys)
323 _ -> SwaggerItemsArray (map Inline ys)
@@ -329,7 +329,7 @@ sketchSchema = sketch . toJSON
329 (z:_) | allSame -> Just z
329 (z:_) | allSame -> Just z
330 _ -> Nothing
330 _ -> Nothing
331 go (Object o) = mempty
331 go (Object o) = mempty
332− & type_ ?~ SwaggerObject
332+ & type_ ?~ OpenApiObject
333 & required .~ HashMap.keys o
333 & required .~ HashMap.keys o
334 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
334 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
335
335
@@ -352,24 +352,24 @@ sketchSchema = sketch . toJSON
352sketchStrictSchema :: ToJSON a => a -> Schema
352sketchStrictSchema :: ToJSON a => a -> Schema
353sketchStrictSchema = go . toJSON
353sketchStrictSchema = go . toJSON
354 where
354 where
355− go Null = mempty & type_ ?~ SwaggerNull
355+ go Null = mempty & type_ ?~ OpenApiNull
356 go js@(Bool _) = mempty
356 go js@(Bool _) = mempty
357− & type_ ?~ SwaggerBoolean
357+ & type_ ?~ OpenApiBoolean
358 & enum_ ?~ [js]
358 & enum_ ?~ [js]
359 go js@(String s) = mempty
359 go js@(String s) = mempty
360− & type_ ?~ SwaggerString
360+ & type_ ?~ OpenApiString
361 & maxLength ?~ fromIntegral (T.length s)
361 & maxLength ?~ fromIntegral (T.length s)
362 & minLength ?~ fromIntegral (T.length s)
362 & minLength ?~ fromIntegral (T.length s)
363 & pattern ?~ s
363 & pattern ?~ s
364 & enum_ ?~ [js]
364 & enum_ ?~ [js]
365 go js@(Number n) = mempty
365 go js@(Number n) = mempty
366− & type_ ?~ SwaggerNumber
366+ & type_ ?~ OpenApiNumber
367 & maximum_ ?~ n
367 & maximum_ ?~ n
368 & minimum_ ?~ n
368 & minimum_ ?~ n
369 & multipleOf ?~ n
369 & multipleOf ?~ n
370 & enum_ ?~ [js]
370 & enum_ ?~ [js]
371 go js@(Array xs) = mempty
371 go js@(Array xs) = mempty
372− & type_ ?~ SwaggerArray
372+ & type_ ?~ OpenApiArray
373 & maxItems ?~ fromIntegral sz
373 & maxItems ?~ fromIntegral sz
374 & minItems ?~ fromIntegral sz
374 & minItems ?~ fromIntegral sz
375 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
375 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
@@ -379,7 +379,7 @@ sketchStrictSchema = go . toJSON
379 sz = length xs
379 sz = length xs
380 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
380 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
381 go js@(Object o) = mempty
381 go js@(Object o) = mempty
382− & type_ ?~ SwaggerObject
382+ & type_ ?~ OpenApiObject
383 & required .~ names
383 & required .~ names
384 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
384 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
385 & maxProperties ?~ fromIntegral (length names)
385 & maxProperties ?~ fromIntegral (length names)
@@ -395,7 +395,7 @@ instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
395 declareNamedSchema _ = do
395 declareNamedSchema _ = do
396 ref <- declareSchemaRef (Proxy :: Proxy a)
396 ref <- declareSchemaRef (Proxy :: Proxy a)
397 return $ unnamed $ mempty
397 return $ unnamed $ mempty
398− & type_ ?~ SwaggerArray
398+ & type_ ?~ OpenApiArray
399 & items ?~ SwaggerItemsObject ref
399 & items ?~ SwaggerItemsObject ref
400
400
401instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
401instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
@@ -447,7 +447,7 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f
447
447
448timeSchema :: T.Text -> Schema
448timeSchema :: T.Text -> Schema
449timeSchema fmt = mempty
449timeSchema fmt = mempty
450− & type_ ?~ SwaggerString
450+ & type_ ?~ OpenApiString
451 & format ?~ fmt
451 & format ?~ fmt
452
452
453-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
453-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -505,7 +505,7 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
505 declareObjectMapSchema = do
505 declareObjectMapSchema = do
506 schema <- declareSchemaRef (Proxy :: Proxy v)
506 schema <- declareSchemaRef (Proxy :: Proxy v)
507 return $ unnamed $ mempty
507 return $ unnamed $ mempty
508− & type_ ?~ SwaggerObject
508+ & type_ ?~ OpenApiObject
509 & additionalProperties ?~ AdditionalPropertiesSchema schema
509 & additionalProperties ?~ AdditionalPropertiesSchema schema
510
510
511instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
511instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
@@ -513,7 +513,7 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
513
513
514instance {-# OVERLAPPING #-} ToSchema Object where
514instance {-# OVERLAPPING #-} ToSchema Object where
515 declareNamedSchema _ = pure $ NamedSchema (Just "Object") $ mempty
515 declareNamedSchema _ = pure $ NamedSchema (Just "Object") $ mempty
516− & type_ ?~ SwaggerObject
516+ & type_ ?~ OpenApiObject
517 & description ?~ "Arbitrary JSON object."
517 & description ?~ "Arbitrary JSON object."
518 & additionalProperties ?~ AdditionalPropertiesAllowed True
518 & additionalProperties ?~ AdditionalPropertiesAllowed True
519
519
@@ -554,7 +554,7 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
554-- {"maximum":32767,"minimum":-32768,"type":"integer"}
554-- {"maximum":32767,"minimum":-32768,"type":"integer"}
555toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
555toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
556toSchemaBoundedIntegral _ = mempty
556toSchemaBoundedIntegral _ = mempty
557− & type_ ?~ SwaggerInteger
557+ & type_ ?~ OpenApiInteger
558 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
558 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
559 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
559 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
560
560
@@ -600,7 +600,7 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
600 let allKeys = [minBound..maxBound :: key]
600 let allKeys = [minBound..maxBound :: key]
601 mkPair k = (keyToText k, valueRef)
601 mkPair k = (keyToText k, valueRef)
602 return $ mempty
602 return $ mempty
603− & type_ ?~ SwaggerObject
603+ & type_ ?~ OpenApiObject
604 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
604 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
605
605
606-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
606-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
@@ -659,7 +659,7 @@ paramSchemaToSchema = toParamSchema
659
659
660nullarySchema :: Schema
660nullarySchema :: Schema
661nullarySchema = mempty
661nullarySchema = mempty
662− & type_ ?~ SwaggerArray
662+ & type_ ?~ OpenApiArray
663 & items ?~ SwaggerItemsArray []
663 & items ?~ SwaggerItemsArray []
664
664
665gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
665gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
@@ -730,12 +730,12 @@ withFieldSchema opts _ isRequiredField schema = do
730 return $
730 return $
731 if T.null fname
731 if T.null fname
732 then schema
732 then schema
733− & type_ ?~ SwaggerArray
733+ & type_ ?~ OpenApiArray
734 & items %~ appendItem ref
734 & items %~ appendItem ref
735 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
735 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
736 & minItems %~ Just . maybe 1 (+1) -- increment minItems
736 & minItems %~ Just . maybe 1 (+1) -- increment minItems
737 else schema
737 else schema
738− & type_ ?~ SwaggerObject
738+ & type_ ?~ OpenApiObject
739 & properties . at fname ?~ ref
739 & properties . at fname ?~ ref
740 & if isRequiredField
740 & if isRequiredField
741 then required %~ (++ [fname])
741 then required %~ (++ [fname])
@@ -770,14 +770,14 @@ gdeclareNamedSumSchema opts proxy _
770 | otherwise = do
770 | otherwise = do
771 (schemas, _) <- runWriterT declareSumSchema
771 (schemas, _) <- runWriterT declareSumSchema
772 return $ unnamed $ mempty
772 return $ unnamed $ mempty
773− & type_ ?~ SwaggerObject
773+ & type_ ?~ OpenApiObject
774 & oneOf ?~ (snd <$> schemas)
774 & oneOf ?~ (snd <$> schemas)
775 where
775 where
776 declareSumSchema = gsumToSchema opts proxy
776 declareSumSchema = gsumToSchema opts proxy
777 (sumSchemas, All allNullary) = undeclare (runWriterT declareSumSchema)
777 (sumSchemas, All allNullary) = undeclare (runWriterT declareSumSchema)
778
778
779 toStringTag schemas = mempty
779 toStringTag schemas = mempty
780− & type_ ?~ SwaggerString
780+ & type_ ?~ OpenApiString
781 & enum_ ?~ map (String . fst) sumSchemas
781 & enum_ ?~ map (String . fst) sumSchemas
782
782
783type AllNullary = All
783type AllNullary = All
@@ -799,15 +799,15 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
799 case ref of
799 case ref of
800 -- If subschema is an object and constructor is a record, we add tag directly
800 -- If subschema is an object and constructor is a record, we add tag directly
801 -- to the record, as Aeson does it.
801 -- to the record, as Aeson does it.
802− Just (Inline sub) | sub ^. type_ == Just SwaggerObject && isRecord -> Inline $ sub
802+ Just (Inline sub) | sub ^. type_ == Just OpenApiObject && isRecord -> Inline $ sub
803 & required <>~ [T.pack tagField]
803 & required <>~ [T.pack tagField]
804− & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ SwaggerString & enum_ ?~ [String tag])
804+ & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ OpenApiString & enum_ ?~ [String tag])
805
805
806 -- If it is not a record, we need to put subschema into "contents" field.
806 -- If it is not a record, we need to put subschema into "contents" field.
807 _ | not isRecord -> Inline $ mempty
807 _ | not isRecord -> Inline $ mempty
808− & type_ ?~ SwaggerObject
808+ & type_ ?~ OpenApiObject
809 & required .~ [T.pack tagField]
809 & required .~ [T.pack tagField]
810− & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ SwaggerString & enum_ ?~ [String tag])
810+ & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ OpenApiString & enum_ ?~ [String tag])
811 -- If constructor is nullary, there is no content.
811 -- If constructor is nullary, there is no content.
812 & case ref of
812 & case ref of
813 Just r -> (properties . at (T.pack contentsField) ?~ r) . (required <>~ [T.pack contentsField])
813 Just r -> (properties . at (T.pack contentsField) ?~ r) . (required <>~ [T.pack contentsField])
@@ -815,17 +815,17 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
815
815
816 -- In the remaining cases we combine "tag" object and "contents" object using allOf.
816 -- In the remaining cases we combine "tag" object and "contents" object using allOf.
817 _ -> Inline $ mempty
817 _ -> Inline $ mempty
818− & type_ ?~ SwaggerObject
818+ & type_ ?~ OpenApiObject
819 & allOf ?~ [Inline $ mempty
819 & allOf ?~ [Inline $ mempty
820− & type_ ?~ SwaggerObject
820+ & type_ ?~ OpenApiObject
821 & required .~ (T.pack tagField : if isRecord then [] else [T.pack contentsField])
821 & required .~ (T.pack tagField : if isRecord then [] else [T.pack contentsField])
822− & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ SwaggerString & enum_ ?~ [String tag])]
822+ & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ OpenApiString & enum_ ?~ [String tag])]
823 & if isRecord
823 & if isRecord
824 then allOf . _Just <>~ [refOrNullary]
824 then allOf . _Just <>~ [refOrNullary]
825− else allOf . _Just <>~ [Inline $ mempty & type_ ?~ SwaggerObject & properties . at (T.pack contentsField) ?~ refOrNullary]
825+ else allOf . _Just <>~ [Inline $ mempty & type_ ?~ OpenApiObject & properties . at (T.pack contentsField) ?~ refOrNullary]
826 UntaggedValue -> refOrEnum -- Aeson encodes nullary constructors as strings in this case.
826 UntaggedValue -> refOrEnum -- Aeson encodes nullary constructors as strings in this case.
827 ObjectWithSingleField -> Inline $ mempty
827 ObjectWithSingleField -> Inline $ mempty
828− & type_ ?~ SwaggerObject
828+ & type_ ?~ OpenApiObject
829 & required .~ [tag]
829 & required .~ [tag]
830 & properties . at tag ?~ refOrNullary
830 & properties . at tag ?~ refOrNullary
831 TwoElemArray -> error "unrepresentable in OpenAPI 3"
831 TwoElemArray -> error "unrepresentable in OpenAPI 3"
@@ -833,7 +833,7 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
833 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
833 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
834 isRecord = conIsRecord (Proxy3 :: Proxy3 c f p)
834 isRecord = conIsRecord (Proxy3 :: Proxy3 c f p)
835 refOrNullary = fromMaybe (Inline nullarySchema) ref
835 refOrNullary = fromMaybe (Inline nullarySchema) ref
836− refOrEnum = fromMaybe (Inline $ mempty & type_ ?~ SwaggerString & enum_ ?~ [String tag]) ref
836+ refOrEnum = fromMaybe (Inline $ mempty & type_ ?~ OpenApiString & enum_ ?~ [String tag]) ref
837
837
838gsumConToSchema :: (GToSchema (C1 c f), Constructor c) =>
838gsumConToSchema :: (GToSchema (C1 c f), Constructor c) =>
839 SchemaOptions -> Proxy (C1 c f) -> Declare (Definitions Schema) [(T.Text, Referenced Schema)]
839 SchemaOptions -> Proxy (C1 c f) -> Declare (Definitions Schema) [(T.Text, Referenced Schema)]
src/Data/OpenApi/Internal/Schema/Validation.hs+31−31
@@ -423,10 +423,10 @@ validateEnum val = do
423-- This is like 'inferParamSchemaTypes', but also works for objects:
423-- This is like 'inferParamSchemaTypes', but also works for objects:
424--
424--
425-- >>> inferSchemaTypes <$> decode "{\"minProperties\": 1}"
425-- >>> inferSchemaTypes <$> decode "{\"minProperties\": 1}"
426−-- Just [SwaggerObject]
426+-- Just [OpenApiObject]
427−inferSchemaTypes :: Schema -> [SwaggerType]
427+inferSchemaTypes :: Schema -> [OpenApiType]
428inferSchemaTypes sch = inferParamSchemaTypes sch ++
428inferSchemaTypes sch = inferParamSchemaTypes sch ++
429− [ SwaggerObject | any ($ sch)
429+ [ OpenApiObject | any ($ sch)
430 [ has (additionalProperties._Just)
430 [ has (additionalProperties._Just)
431 , has (maxProperties._Just)
431 , has (maxProperties._Just)
432 , has (minProperties._Just)
432 , has (minProperties._Just)
@@ -436,30 +436,30 @@ inferSchemaTypes sch = inferParamSchemaTypes sch ++
436-- | Infer schema type based on used properties.
436-- | Infer schema type based on used properties.
437--
437--
438-- >>> inferSchemaTypes <$> decode "{\"minLength\": 2}"
438-- >>> inferSchemaTypes <$> decode "{\"minLength\": 2}"
439−-- Just [SwaggerString]
439+-- Just [OpenApiString]
440--
440--
441-- >>> inferSchemaTypes <$> decode "{\"maxItems\": 0}"
441-- >>> inferSchemaTypes <$> decode "{\"maxItems\": 0}"
442−-- Just [SwaggerArray]
442+-- Just [OpenApiArray]
443--
443--
444−-- From numeric properties 'SwaggerInteger' type is inferred.
444+-- From numeric properties 'OpenApiInteger' type is inferred.
445−-- If you want 'SwaggerNumber' instead, you must specify it explicitly.
445+-- If you want 'OpenApiNumber' instead, you must specify it explicitly.
446--
446--
447-- >>> inferSchemaTypes <$> decode "{\"minimum\": 1}"
447-- >>> inferSchemaTypes <$> decode "{\"minimum\": 1}"
448−-- Just [SwaggerInteger]
448+-- Just [OpenApiInteger]
449−inferParamSchemaTypes :: Schema -> [SwaggerType]
449+inferParamSchemaTypes :: Schema -> [OpenApiType]
450inferParamSchemaTypes sch = concat
450inferParamSchemaTypes sch = concat
451− [ [ SwaggerArray | any ($ sch)
451+ [ [ OpenApiArray | any ($ sch)
452 [ has (items._Just)
452 [ has (items._Just)
453 , has (maxItems._Just)
453 , has (maxItems._Just)
454 , has (minItems._Just)
454 , has (minItems._Just)
455 , has (uniqueItems._Just) ] ]
455 , has (uniqueItems._Just) ] ]
456− , [ SwaggerInteger | any ($ sch)
456+ , [ OpenApiInteger | any ($ sch)
457 [ has (exclusiveMaximum._Just)
457 [ has (exclusiveMaximum._Just)
458 , has (exclusiveMinimum._Just)
458 , has (exclusiveMinimum._Just)
459 , has (maximum_._Just)
459 , has (maximum_._Just)
460 , has (minimum_._Just)
460 , has (minimum_._Just)
461 , has (multipleOf._Just) ] ]
461 , has (multipleOf._Just) ] ]
462− , [ SwaggerString | any ($ sch)
462+ , [ OpenApiString | any ($ sch)
463 [ has (maxLength._Just)
463 [ has (maxLength._Just)
464 , has (minLength._Just)
464 , has (minLength._Just)
465 , has (pattern._Just) ] ]
465 , has (pattern._Just) ] ]
@@ -483,13 +483,13 @@ validateSchemaType val = withSchema $ \sch ->
483
483
484 _ ->
484 _ ->
485 case (sch ^. type_, val) of
485 case (sch ^. type_, val) of
486− (Just SwaggerNull, Null) -> valid
486+ (Just OpenApiNull, Null) -> valid
487− (Just SwaggerBoolean, Bool _) -> valid
487+ (Just OpenApiBoolean, Bool _) -> valid
488− (Just SwaggerInteger, Number n) -> validateInteger n
488+ (Just OpenApiInteger, Number n) -> validateInteger n
489− (Just SwaggerNumber, Number n) -> validateNumber n
489+ (Just OpenApiNumber, Number n) -> validateNumber n
490− (Just SwaggerString, String s) -> validateString s
490+ (Just OpenApiString, String s) -> validateString s
491− (Just SwaggerArray, Array xs) -> validateArray xs
491+ (Just OpenApiArray, Array xs) -> validateArray xs
492− (Just SwaggerObject, Object o) -> validateObject o
492+ (Just OpenApiObject, Object o) -> validateObject o
493 (Nothing, Null) -> valid
493 (Nothing, Null) -> valid
494 (Nothing, Bool _) -> valid
494 (Nothing, Bool _) -> valid
495 -- Number by default
495 -- Number by default
@@ -502,11 +502,11 @@ validateSchemaType val = withSchema $ \sch ->
502validateParamSchemaType :: Value -> Validation Schema ()
502validateParamSchemaType :: Value -> Validation Schema ()
503validateParamSchemaType val = withSchema $ \sch ->
503validateParamSchemaType val = withSchema $ \sch ->
504 case (sch ^. type_, val) of
504 case (sch ^. type_, val) of
505− (Just SwaggerBoolean, Bool _) -> valid
505+ (Just OpenApiBoolean, Bool _) -> valid
506− (Just SwaggerInteger, Number n) -> validateInteger n
506+ (Just OpenApiInteger, Number n) -> validateInteger n
507− (Just SwaggerNumber, Number n) -> validateNumber n
507+ (Just OpenApiNumber, Number n) -> validateNumber n
508− (Just SwaggerString, String s) -> validateString s
508+ (Just OpenApiString, String s) -> validateString s
509− (Just SwaggerArray, Array xs) -> validateArray xs
509+ (Just OpenApiArray, Array xs) -> validateArray xs
510 (Nothing, Bool _) -> valid
510 (Nothing, Bool _) -> valid
511 -- Number by default
511 -- Number by default
512 (Nothing, Number n) -> validateNumber n
512 (Nothing, Number n) -> validateNumber n
@@ -514,11 +514,11 @@ validateParamSchemaType val = withSchema $ \sch ->
514 (Nothing, Array xs) -> validateArray xs
514 (Nothing, Array xs) -> validateArray xs
515 bad -> invalid $ "expected JSON value of type " ++ showType bad
515 bad -> invalid $ "expected JSON value of type " ++ showType bad
516
516
517−showType :: (Maybe SwaggerType, Value) -> String
517+showType :: (Maybe OpenApiType, Value) -> String
518showType (Just ty, _) = show ty
518showType (Just ty, _) = show ty
519−showType (Nothing, Null) = "SwaggerNull"
519+showType (Nothing, Null) = "OpenApiNull"
520−showType (Nothing, Bool _) = "SwaggerBoolean"
520+showType (Nothing, Bool _) = "OpenApiBoolean"
521−showType (Nothing, Number _) = "SwaggerNumber"
521+showType (Nothing, Number _) = "OpenApiNumber"
522−showType (Nothing, String _) = "SwaggerString"
522+showType (Nothing, String _) = "OpenApiString"
523−showType (Nothing, Array _) = "SwaggerArray"
523+showType (Nothing, Array _) = "OpenApiArray"
524−showType (Nothing, Object _) = "SwaggerObject"
524+showType (Nothing, Object _) = "OpenApiObject"
src/Data/OpenApi/Lens.hs+1−1
@@ -99,7 +99,7 @@ instance At Responses where at n = responses . at n
99instance Ixed Operation where ix n = responses . ix n
99instance Ixed Operation where ix n = responses . ix n
100instance At Operation where at n = responses . at n
100instance At Operation where at n = responses . at n
101
101
102−instance HasType NamedSchema (Maybe SwaggerType) where type_ = schema.type_
102+instance HasType NamedSchema (Maybe OpenApiType) where type_ = schema.type_
103
103
104-- OVERLAPPABLE instances
104-- OVERLAPPABLE instances
105
105
src/Data/OpenApi/Optics.hs+4−4
@@ -23,7 +23,7 @@
23--
23--
24-- >>> :{
24-- >>> :{
25-- BSL.putStrLn $ encode $ (mempty :: OpenApi)
25-- BSL.putStrLn $ encode $ (mempty :: OpenApi)
26−-- & #components % #schemas .~ [ ("User", mempty & #type ?~ SwaggerString) ]
26+-- & #components % #schemas .~ [ ("User", mempty & #type ?~ OpenApiString) ]
27-- & #paths .~
27-- & #paths .~
28-- [ ("/user", mempty & #get ?~ (mempty
28-- [ ("/user", mempty & #get ?~ (mempty
29-- & at 200 ?~ ("OK" & #_Inline % #content % at "application/json" ?~ (mempty & #schema ?~ Ref (Reference "User")))
29-- & at 200 ?~ ("OK" & #_Inline % #content % at "application/json" ?~ (mempty & #schema ?~ Ref (Reference "User")))
@@ -40,7 +40,7 @@
40-- {"description":"No content"}
40-- {"description":"No content"}
41-- >>> :{
41-- >>> :{
42-- BSL.putStrLn $ encode $ (mempty :: Schema)
42-- BSL.putStrLn $ encode $ (mempty :: Schema)
43−-- & #type ?~ SwaggerBoolean
43+-- & #type ?~ OpenApiBoolean
44-- & #description ?~ "To be or not to be"
44-- & #description ?~ "To be or not to be"
45-- :}
45-- :}
46-- {"type":"boolean","description":"To be or not to be"}
46-- {"type":"boolean","description":"To be or not to be"}
@@ -155,8 +155,8 @@ instance At Operation where
155-- #type
155-- #type
156
156
157instance
157instance
158− ( a ~ Maybe SwaggerType
158+ ( a ~ Maybe OpenApiType
159− , b ~ Maybe SwaggerType
159+ , b ~ Maybe OpenApiType
160 ) => LabelOptic "type" A_Lens NamedSchema NamedSchema a b where
160 ) => LabelOptic "type" A_Lens NamedSchema NamedSchema a b where
161 labelOptic = #schema % #type
161 labelOptic = #schema % #type
162 {-# INLINE labelOptic #-}
162 {-# INLINE labelOptic #-}
src/Data/OpenApi/Schema/Generator.hs+7−7
@@ -39,21 +39,21 @@ schemaGen defns schema =
39 [ inferredType ] -> schemaGen defns (schema & type_ ?~ inferredType)
39 [ inferredType ] -> schemaGen defns (schema & type_ ?~ inferredType)
40 -- Gen is not MonadFail
40 -- Gen is not MonadFail
41 _ -> error "unable to infer schema type"
41 _ -> error "unable to infer schema type"
42− Just SwaggerBoolean -> Bool <$> elements [True, False]
42+ Just OpenApiBoolean -> Bool <$> elements [True, False]
43− Just SwaggerNull -> pure Null
43+ Just OpenApiNull -> pure Null
44− Just SwaggerNumber
44+ Just OpenApiNumber
45 | Just min <- schema ^. minimum_
45 | Just min <- schema ^. minimum_
46 , Just max <- schema ^. maximum_ ->
46 , Just max <- schema ^. maximum_ ->
47 Number . fromFloatDigits <$>
47 Number . fromFloatDigits <$>
48 choose (toRealFloat min, toRealFloat max :: Double)
48 choose (toRealFloat min, toRealFloat max :: Double)
49 | otherwise -> Number .fromFloatDigits <$> (arbitrary :: Gen Double)
49 | otherwise -> Number .fromFloatDigits <$> (arbitrary :: Gen Double)
50− Just SwaggerInteger
50+ Just OpenApiInteger
51 | Just min <- schema ^. minimum_
51 | Just min <- schema ^. minimum_
52 , Just max <- schema ^. maximum_ ->
52 , Just max <- schema ^. maximum_ ->
53 Number . fromInteger <$>
53 Number . fromInteger <$>
54 choose (truncate min, truncate max)
54 choose (truncate min, truncate max)
55 | otherwise -> Number . fromInteger <$> arbitrary
55 | otherwise -> Number . fromInteger <$> arbitrary
56− Just SwaggerArray
56+ Just OpenApiArray
57 | Just 0 <- schema ^. maxLength -> pure $ Array V.empty
57 | Just 0 <- schema ^. maxLength -> pure $ Array V.empty
58 | Just items <- schema ^. items ->
58 | Just items <- schema ^. items ->
59 case items of
59 case items of
@@ -68,14 +68,14 @@ schemaGen defns schema =
68 SwaggerItemsArray refs ->
68 SwaggerItemsArray refs ->
69 let itemGens = schemaGen defns . dereference defns <$> refs
69 let itemGens = schemaGen defns . dereference defns <$> refs
70 in fmap (Array . V.fromList) $ sequence itemGens
70 in fmap (Array . V.fromList) $ sequence itemGens
71− Just SwaggerString -> do
71+ Just OpenApiString -> do
72 size <- getSize
72 size <- getSize
73 let minLength' = fromMaybe 0 $ fromInteger <$> schema ^. minLength
73 let minLength' = fromMaybe 0 $ fromInteger <$> schema ^. minLength
74 let maxLength' = fromMaybe size $ fromInteger <$> schema ^. maxLength
74 let maxLength' = fromMaybe size $ fromInteger <$> schema ^. maxLength
75 length <- choose (minLength', max minLength' maxLength')
75 length <- choose (minLength', max minLength' maxLength')
76 str <- vectorOf length arbitrary
76 str <- vectorOf length arbitrary
77 return . String $ T.pack str
77 return . String $ T.pack str
78− Just SwaggerObject -> do
78+ Just OpenApiObject -> do
79 size <- getSize
79 size <- getSize
80 let props = dereference defns <$> schema ^. properties
80 let props = dereference defns <$> schema ^. properties
81 reqKeys = S.fromList $ schema ^. required
81 reqKeys = S.fromList $ schema ^. required
src/Data/OpenApi/Schema/Validation.hs+3−3
@@ -71,11 +71,11 @@ import Data.OpenApi.Internal.Schema.Validation
71-- generally fails for @null@ JSON:
71-- generally fails for @null@ JSON:
72--
72--
73-- >>> validateToJSON (Nothing :: Maybe String)
73-- >>> validateToJSON (Nothing :: Maybe String)
74−-- ["expected JSON value of type SwaggerString"]
74+-- ["expected JSON value of type OpenApiString"]
75-- >>> validateToJSON ([Just "hello", Nothing] :: [Maybe String])
75-- >>> validateToJSON ([Just "hello", Nothing] :: [Maybe String])
76−-- ["expected JSON value of type SwaggerString"]
76+-- ["expected JSON value of type OpenApiString"]
77-- >>> validateToJSON (123, Nothing :: Maybe String)
77-- >>> validateToJSON (123, Nothing :: Maybe String)
78−-- ["expected JSON value of type SwaggerString"]
78+-- ["expected JSON value of type OpenApiString"]
79--
79--
80-- However, when @'Maybe' a@ is a type of a record field,
80-- However, when @'Maybe' a@ is a type of a record field,
81-- validation takes @'required'@ property of the @'Schema'@
81-- validation takes @'required'@ property of the @'Schema'@
test/Data/OpenApi/Schema/GeneratorSpec.hs+4−4
@@ -103,7 +103,7 @@ instance FromJSON WrongType where
103instance ToSchema WrongType where
103instance ToSchema WrongType where
104 declareNamedSchema _ = return . NamedSchema (Just "WrongType") $
104 declareNamedSchema _ = return . NamedSchema (Just "WrongType") $
105 mempty
105 mempty
106− & type_ ?~ SwaggerObject
106+ & type_ ?~ OpenApiObject
107
107
108
108
109data MissingRequired = MissingRequired
109data MissingRequired = MissingRequired
@@ -123,7 +123,7 @@ instance ToSchema MissingRequired where
123 boolSchema <- declareSchemaRef (Proxy :: Proxy Bool)
123 boolSchema <- declareSchemaRef (Proxy :: Proxy Bool)
124 return . NamedSchema (Just "MissingRequired") $
124 return . NamedSchema (Just "MissingRequired") $
125 mempty
125 mempty
126− & type_ ?~ SwaggerObject
126+ & type_ ?~ OpenApiObject
127 & properties .~ [("propA", stringSchema)
127 & properties .~ [("propA", stringSchema)
128 ,("propB", boolSchema)
128 ,("propB", boolSchema)
129 ]
129 ]
@@ -145,7 +145,7 @@ instance ToSchema MissingProperty where
145 stringSchema <- declareSchemaRef (Proxy :: Proxy String)
145 stringSchema <- declareSchemaRef (Proxy :: Proxy String)
146 return . NamedSchema (Just "MissingProperty") $
146 return . NamedSchema (Just "MissingProperty") $
147 mempty
147 mempty
148− & type_ ?~ SwaggerObject
148+ & type_ ?~ OpenApiObject
149 & properties .~ [("propC", stringSchema)]
149 & properties .~ [("propC", stringSchema)]
150 & required .~ ["propC"]
150 & required .~ ["propC"]
151
151
@@ -163,6 +163,6 @@ instance ToSchema WrongPropType where
163 boolSchema <- declareSchemaRef (Proxy :: Proxy Bool)
163 boolSchema <- declareSchemaRef (Proxy :: Proxy Bool)
164 return . NamedSchema (Just "WrongPropType") $
164 return . NamedSchema (Just "WrongPropType") $
165 mempty
165 mempty
166− & type_ ?~ SwaggerObject
166+ & type_ ?~ OpenApiObject
167 & properties .~ [("propE", boolSchema)]
167 & properties .~ [("propE", boolSchema)]
168 & required .~ ["propE"]
168 & required .~ ["propE"]
test/Data/OpenApi/Schema/ValidationSpec.hs+1−1
@@ -277,7 +277,7 @@ instance ToJSON FreeForm where
277
277
278instance ToSchema FreeForm where
278instance ToSchema FreeForm where
279 declareNamedSchema _ = pure $ NamedSchema (Just $ T.pack "FreeForm") $ mempty
279 declareNamedSchema _ = pure $ NamedSchema (Just $ T.pack "FreeForm") $ mempty
280− & type_ ?~ SwaggerObject
280+ & type_ ?~ OpenApiObject
281 & additionalProperties ?~ AdditionalPropertiesAllowed True
281 & additionalProperties ?~ AdditionalPropertiesAllowed True
282
282
283instance Arbitrary FreeForm where
283instance Arbitrary FreeForm where
test/Data/OpenApiSpec.hs+28−28
@@ -132,15 +132,15 @@ operationExample = mempty
132 & description ?~ "ID of pet that needs to be updated"
132 & description ?~ "ID of pet that needs to be updated"
133 & required ?~ True
133 & required ?~ True
134 & in_ .~ ParamPath
134 & in_ .~ ParamPath
135− & schema ?~ Inline (mempty & type_ ?~ SwaggerString))]
135+ & schema ?~ Inline (mempty & type_ ?~ OpenApiString))]
136 & requestBody ?~ Inline (
136 & requestBody ?~ Inline (
137 mempty & content . at "application/x-www-form-urlencoded" ?~ (mempty & schema ?~ (Inline (mempty
137 mempty & content . at "application/x-www-form-urlencoded" ?~ (mempty & schema ?~ (Inline (mempty
138 & properties . at "petId" ?~ Inline (mempty
138 & properties . at "petId" ?~ Inline (mempty
139 & description ?~ "Updated name of the pet"
139 & description ?~ "Updated name of the pet"
140− & type_ ?~ SwaggerString)
140+ & type_ ?~ OpenApiString)
141 & properties . at "status" ?~ Inline (mempty
141 & properties . at "status" ?~ Inline (mempty
142 & description ?~ "Updated status of the pet"
142 & description ?~ "Updated status of the pet"
143− & type_ ?~ SwaggerString)))))
143+ & type_ ?~ OpenApiString)))))
144 & at 200 ?~ "Pet updated."
144 & at 200 ?~ "Pet updated."
145 & at 405 ?~ "Invalid input"
145 & at 405 ?~ "Invalid input"
146 & security .~ [SecurityRequirement [("petstore_auth", ["write:pets", "read:pets"])]]
146 & security .~ [SecurityRequirement [("petstore_auth", ["write:pets", "read:pets"])]]
@@ -208,7 +208,7 @@ operationExampleJSON = [aesonQQ|
208
208
209schemaPrimitiveExample :: Schema
209schemaPrimitiveExample :: Schema
210schemaPrimitiveExample = mempty
210schemaPrimitiveExample = mempty
211− & type_ ?~ SwaggerString
211+ & type_ ?~ OpenApiString
212 & format ?~ "email"
212 & format ?~ "email"
213
213
214schemaPrimitiveExampleJSON :: Value
214schemaPrimitiveExampleJSON :: Value
@@ -221,14 +221,14 @@ schemaPrimitiveExampleJSON = [aesonQQ|
221
221
222schemaSimpleModelExample :: Schema
222schemaSimpleModelExample :: Schema
223schemaSimpleModelExample = mempty
223schemaSimpleModelExample = mempty
224− & type_ ?~ SwaggerObject
224+ & type_ ?~ OpenApiObject
225 & required .~ [ "name" ]
225 & required .~ [ "name" ]
226 & properties .~
226 & properties .~
227− [ ("name", Inline (mempty & type_ ?~ SwaggerString))
227+ [ ("name", Inline (mempty & type_ ?~ OpenApiString))
228 , ("address", Ref (Reference "Address"))
228 , ("address", Ref (Reference "Address"))
229 , ("age", Inline $ mempty
229 , ("age", Inline $ mempty
230 & minimum_ ?~ 0
230 & minimum_ ?~ 0
231− & type_ ?~ SwaggerInteger
231+ & type_ ?~ OpenApiInteger
232 & format ?~ "int32" ) ]
232 & format ?~ "int32" ) ]
233
233
234schemaSimpleModelExampleJSON :: Value
234schemaSimpleModelExampleJSON :: Value
@@ -253,8 +253,8 @@ schemaSimpleModelExampleJSON = [aesonQQ|
253
253
254schemaModelDictExample :: Schema
254schemaModelDictExample :: Schema
255schemaModelDictExample = mempty
255schemaModelDictExample = mempty
256− & type_ ?~ SwaggerObject
256+ & type_ ?~ OpenApiObject
257− & additionalProperties ?~ AdditionalPropertiesSchema (Inline (mempty & type_ ?~ SwaggerString))
257+ & additionalProperties ?~ AdditionalPropertiesSchema (Inline (mempty & type_ ?~ OpenApiString))
258
258
259schemaModelDictExampleJSON :: Value
259schemaModelDictExampleJSON :: Value
260schemaModelDictExampleJSON = [aesonQQ|
260schemaModelDictExampleJSON = [aesonQQ|
@@ -268,7 +268,7 @@ schemaModelDictExampleJSON = [aesonQQ|
268
268
269schemaAdditionalExample :: Schema
269schemaAdditionalExample :: Schema
270schemaAdditionalExample = mempty
270schemaAdditionalExample = mempty
271− & type_ ?~ SwaggerObject
271+ & type_ ?~ OpenApiObject
272 & additionalProperties ?~ AdditionalPropertiesAllowed True
272 & additionalProperties ?~ AdditionalPropertiesAllowed True
273
273
274schemaAdditionalExampleJSON :: Value
274schemaAdditionalExampleJSON :: Value
@@ -281,13 +281,13 @@ schemaAdditionalExampleJSON = [aesonQQ|
281
281
282schemaWithExampleExample :: Schema
282schemaWithExampleExample :: Schema
283schemaWithExampleExample = mempty
283schemaWithExampleExample = mempty
284− & type_ ?~ SwaggerObject
284+ & type_ ?~ OpenApiObject
285 & properties .~
285 & properties .~
286 [ ("id", Inline $ mempty
286 [ ("id", Inline $ mempty
287− & type_ ?~ SwaggerInteger
287+ & type_ ?~ OpenApiInteger
288 & format ?~ "int64" )
288 & format ?~ "int64" )
289 , ("name", Inline $ mempty
289 , ("name", Inline $ mempty
290− & type_ ?~ SwaggerString) ]
290+ & type_ ?~ OpenApiString) ]
291 & required .~ [ "name" ]
291 & required .~ [ "name" ]
292 & example ?~ [aesonQQ|
292 & example ?~ [aesonQQ|
293 {
293 {
@@ -326,19 +326,19 @@ schemaWithExampleExampleJSON = [aesonQQ|
326definitionsExample :: HashMap Text Schema
326definitionsExample :: HashMap Text Schema
327definitionsExample =
327definitionsExample =
328 [ ("Category", mempty
328 [ ("Category", mempty
329− & type_ ?~ SwaggerObject
329+ & type_ ?~ OpenApiObject
330 & properties .~
330 & properties .~
331 [ ("id", Inline $ mempty
331 [ ("id", Inline $ mempty
332− & type_ ?~ SwaggerInteger
332+ & type_ ?~ OpenApiInteger
333 & format ?~ "int64")
333 & format ?~ "int64")
334− , ("name", Inline (mempty & type_ ?~ SwaggerString)) ] )
334+ , ("name", Inline (mempty & type_ ?~ OpenApiString)) ] )
335 , ("Tag", mempty
335 , ("Tag", mempty
336− & type_ ?~ SwaggerObject
336+ & type_ ?~ OpenApiObject
337 & properties .~
337 & properties .~
338 [ ("id", Inline $ mempty
338 [ ("id", Inline $ mempty
339− & type_ ?~ SwaggerInteger
339+ & type_ ?~ OpenApiInteger
340 & format ?~ "int64")
340 & format ?~ "int64")
341− , ("name", Inline (mempty & type_ ?~ SwaggerString)) ] ) ]
341+ , ("name", Inline (mempty & type_ ?~ OpenApiString)) ] ) ]
342
342
343definitionsExampleJSON :: Value
343definitionsExampleJSON :: Value
344definitionsExampleJSON = [aesonQQ|
344definitionsExampleJSON = [aesonQQ|
@@ -382,7 +382,7 @@ paramsDefinitionExample =
382 & required ?~ True
382 & required ?~ True
383 & in_ .~ ParamQuery
383 & in_ .~ ParamQuery
384 & schema ?~ Inline (mempty
384 & schema ?~ Inline (mempty
385− & type_ ?~ SwaggerInteger
385+ & type_ ?~ OpenApiInteger
386 & format ?~ "int32" ))
386 & format ?~ "int32" ))
387 , ("limitParam", mempty
387 , ("limitParam", mempty
388 & name .~ "limit"
388 & name .~ "limit"
@@ -390,7 +390,7 @@ paramsDefinitionExample =
390 & required ?~ True
390 & required ?~ True
391 & in_ .~ ParamQuery
391 & in_ .~ ParamQuery
392 & schema ?~ Inline (mempty
392 & schema ?~ Inline (mempty
393− & type_ ?~ SwaggerInteger
393+ & type_ ?~ OpenApiInteger
394 & format ?~ "int32" )) ]
394 & format ?~ "int32" )) ]
395
395
396paramsDefinitionExampleJSON :: Value
396paramsDefinitionExampleJSON :: Value
@@ -559,7 +559,7 @@ swaggerExample = mempty
559 & description .~ "OK"
559 & description .~ "OK"
560 & content . at "application/json" ?~ (mempty
560 & content . at "application/json" ?~ (mempty
561 & schema ?~ Inline (mempty
561 & schema ?~ Inline (mempty
562− & type_ ?~ SwaggerObject
562+ & type_ ?~ OpenApiObject
563 & example ?~ [aesonQQ|
563 & example ?~ [aesonQQ|
564 {
564 {
565 "created": 100,
565 "created": 100,
@@ -568,9 +568,9 @@ swaggerExample = mempty
568 & description ?~ "This is some real Todo right here"
568 & description ?~ "This is some real Todo right here"
569 & properties .~
569 & properties .~
570 [ ("created", Inline $ mempty
570 [ ("created", Inline $ mempty
571− & type_ ?~ SwaggerInteger
571+ & type_ ?~ OpenApiInteger
572 & format ?~ "int32")
572 & format ?~ "int32")
573− , ("description", Inline (mempty & type_ ?~ SwaggerString))])))
573+ , ("description", Inline (mempty & type_ ?~ OpenApiString))])))
574 & parameters .~
574 & parameters .~
575 [ Inline $ mempty
575 [ Inline $ mempty
576 & required ?~ True
576 & required ?~ True
@@ -578,7 +578,7 @@ swaggerExample = mempty
578 & description ?~ "TodoId param"
578 & description ?~ "TodoId param"
579 & in_ .~ ParamPath
579 & in_ .~ ParamPath
580 & schema ?~ Inline (mempty
580 & schema ?~ Inline (mempty
581− & type_ ?~ SwaggerString ) ]
581+ & type_ ?~ OpenApiString ) ]
582 & tags .~ InsOrdHS.fromList [ "todo" ] ))
582 & tags .~ InsOrdHS.fromList [ "todo" ] ))
583
583
584swaggerExampleJSON :: Value
584swaggerExampleJSON :: Value
@@ -917,14 +917,14 @@ petstoreExampleJSON = [aesonQQ|
917
917
918compositionSchemaExample :: Schema
918compositionSchemaExample :: Schema
919compositionSchemaExample = mempty
919compositionSchemaExample = mempty
920− & type_ ?~ SwaggerObject
920+ & type_ ?~ OpenApiObject
921 & Data.OpenApi.allOf ?~ [
921 & Data.OpenApi.allOf ?~ [
922 Ref (Reference "Other")
922 Ref (Reference "Other")
923 , Inline (mempty
923 , Inline (mempty
924− & type_ ?~ SwaggerObject
924+ & type_ ?~ OpenApiObject
925 & properties .~
925 & properties .~
926 [ ("greet", Inline $ mempty
926 [ ("greet", Inline $ mempty
927− & type_ ?~ SwaggerString) ])
927+ & type_ ?~ OpenApiString) ])
928 ]
928 ]
929
929
930compositionSchemaExampleJSON :: Value
930compositionSchemaExampleJSON :: Value