git.iko.soy/typeable/openapi3
on master help sign in
change SwaggerType to OpenApiType
commit1d2e9d260fd80a7f610671d5b0e69a585fa9c406 authorPaweł Nosal <pawel.nosal@ocado.com> dateTue 4 Aug 2020, 09:34 (6 years ago) parent03b5707
13 files changed+154−154
examples/hackage.hs+1−1 src/Data/OpenApi.hs+4−4 src/Data/OpenApi/Internal.hs+15−15 src/Data/OpenApi/Internal/ParamSchema.hs+21−21 src/Data/OpenApi/Internal/Schema.hs+34−34 src/Data/OpenApi/Internal/Schema/Validation.hs+31−31 src/Data/OpenApi/Lens.hs+1−1 src/Data/OpenApi/Optics.hs+4−4 src/Data/OpenApi/Schema/Generator.hs+7−7 src/Data/OpenApi/Schema/Validation.hs+3−3 test/Data/OpenApi/Schema/GeneratorSpec.hs+4−4 test/Data/OpenApi/Schema/ValidationSpec.hs+1−1 test/Data/OpenApiSpec.hs+28−28
examples/hackage.hs+1−1
@@ -27,7 +27,7 @@ instance ToSchema UserSummary where
2727 usernameSchema <- declareSchemaRef (Proxy :: Proxy Username)
2828 useridSchema <- declareSchemaRef (Proxy :: Proxy Int)
2929 return $ NamedSchema (Just "UserSummary") $ mempty
30− & type_ ?~ SwaggerObject
30+ & type_ ?~ OpenApiObject
3131 & properties .~
3232 [ ("summaryUsername", usernameSchema )
3333 , ("summaryUserid" , useridSchema )
src/Data/OpenApi.hs+4−4
@@ -56,7 +56,7 @@ module Data.OpenApi (
5656 TagName,
5757
5858 -- ** Types and formats
59− SwaggerType(..),
59+ OpenApiType(..),
6060 Format,
6161 Definitions,
6262 Style(..),
@@ -194,7 +194,7 @@ import Data.OpenApi.Internal
194194--
195195-- >>> :{
196196-- BSL.putStrLn $ encode $ (mempty :: OpenApi)
197−-- & components . schemas .~ [ ("User", mempty & type_ ?~ SwaggerString) ]
197+-- & components . schemas .~ [ ("User", mempty & type_ ?~ OpenApiString) ]
198198-- & paths .~
199199-- [ ("/user", mempty & get ?~ (mempty
200200-- & at 200 ?~ ("OK" & _Inline.content.at "application/json" ?~ (mempty & schema ?~ Ref (Reference "User")))
@@ -216,7 +216,7 @@ import Data.OpenApi.Internal
216216-- {"description":"No content"}
217217-- >>> :{
218218-- BSL.putStrLn $ encode $ (mempty :: Schema)
219−-- & type_ ?~ SwaggerBoolean
219+-- & type_ ?~ OpenApiBoolean
220220-- & description ?~ "To be or not to be"
221221-- :}
222222-- {"type":"boolean","description":"To be or not to be"}
@@ -244,7 +244,7 @@ import Data.OpenApi.Internal
244244-- @'ParamSchema'@ and @'Schema'@ are the two core types for data model specification.
245245--
246246-- @'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'@).
248248--
249249-- @'Schema'@ is used for request and response bodies and allows specifying objects
250250-- with properties in addition to what @'ParamSchema'@ provides.
src/Data/OpenApi/Internal.hs+15−15
@@ -571,7 +571,7 @@ data Link = Link
571571 , _linkServer :: Maybe Server
572572 } deriving (Eq, Show, Generic, Typeable, Data)
573573
574−-- | Items for @'SwaggerArray'@ schemas.
574+-- | Items for @'OpenApiArray'@ schemas.
575575--
576576-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
577577-- it will incorporate Json Schema mostly verbatim.
@@ -584,14 +584,14 @@ data SwaggerItems where
584584 SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems
585585 deriving (Eq, Show, Typeable, Data)
586586
587−data SwaggerType where
588− SwaggerString :: SwaggerType
589− SwaggerNumber :: SwaggerType
590− SwaggerInteger :: SwaggerType
591− SwaggerBoolean :: SwaggerType
592− SwaggerArray :: SwaggerType
593− SwaggerNull :: SwaggerType
594− SwaggerObject :: SwaggerType
587+data OpenApiType where
588+ OpenApiString :: OpenApiType
589+ OpenApiNumber :: OpenApiType
590+ OpenApiInteger :: OpenApiType
591+ OpenApiBoolean :: OpenApiType
592+ OpenApiArray :: OpenApiType
593+ OpenApiNull :: OpenApiType
594+ OpenApiObject :: OpenApiType
595595 deriving (Eq, Show, Typeable, Generic, Data)
596596
597597data ParamLocation
@@ -643,7 +643,7 @@ data Schema = Schema
643643 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
644644 _schemaDefault :: Maybe Value
645645
646− , _schemaType :: Maybe SwaggerType
646+ , _schemaType :: Maybe OpenApiType
647647 , _schemaFormat :: Maybe Format
648648 , _schemaItems :: Maybe SwaggerItems
649649 , _schemaMaximum :: Maybe Scientific
@@ -1085,8 +1085,8 @@ instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
10851085instance SwaggerMonoid MimeList
10861086deriving instance SwaggerMonoid URL
10871087
1088−instance SwaggerMonoid SwaggerType where
1089− swaggerMempty = SwaggerString
1088+instance SwaggerMonoid OpenApiType where
1089+ swaggerMempty = OpenApiString
10901090 swaggerMappend _ y = y
10911091
10921092instance SwaggerMonoid ParamLocation where
@@ -1109,7 +1109,7 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
11091109instance ToJSON Style where
11101110 toJSON = genericToJSON (jsonPrefix "Style")
11111111
1112−instance ToJSON SwaggerType where
1112+instance ToJSON OpenApiType where
11131113 toJSON = genericToJSON (jsonPrefix "Swagger")
11141114
11151115instance ToJSON ParamLocation where
@@ -1164,7 +1164,7 @@ instance ToJSON OAuth2AuthorizationCodeFlow where
11641164instance FromJSON Style where
11651165 parseJSON = genericParseJSON (jsonPrefix "Style")
11661166
1167−instance FromJSON SwaggerType where
1167+instance FromJSON OpenApiType where
11681168 parseJSON = genericParseJSON (jsonPrefix "Swagger")
11691169
11701170instance FromJSON ParamLocation where
@@ -1545,7 +1545,7 @@ instance AesonDefaultValue OAuth2AuthorizationCodeFlow
15451545instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
15461546instance AesonDefaultValue Responses
15471547instance AesonDefaultValue SecuritySchemeType
1548−instance AesonDefaultValue SwaggerType
1548+instance AesonDefaultValue OpenApiType
15491549instance AesonDefaultValue MimeList where defaultValue = Just mempty
15501550instance AesonDefaultValue Info
15511551instance AesonDefaultValue ParamLocation
src/Data/OpenApi/Internal/ParamSchema.hs+21−21
@@ -52,20 +52,20 @@ import GHC.TypeLits (TypeError, ErrorMessage(..))
5252-- | Default schema for binary data (any sequence of octets).
5353binarySchema :: Schema
5454binarySchema = mempty
55− & type_ ?~ SwaggerString
55+ & type_ ?~ OpenApiString
5656 & format ?~ "binary"
5757
5858-- | Default schema for binary data (base64 encoded).
5959byteSchema :: Schema
6060byteSchema = mempty
61− & type_ ?~ SwaggerString
61+ & type_ ?~ OpenApiString
6262 & format ?~ "byte"
6363
6464-- | Default schema for password string.
6565-- @"password"@ format is used to hint UIs the input needs to be obscured.
6666passwordSchema :: Schema
6767passwordSchema = mempty
68− & type_ ?~ SwaggerString
68+ & type_ ?~ OpenApiString
6969 & format ?~ "password"
7070
7171-- | Convert a type into a plain @'Schema'@.
@@ -87,7 +87,7 @@ passwordSchema = mempty
8787--
8888-- instance ToParamSchema Direction where
8989-- toParamSchema _ = mempty
90−-- & type_ ?~ SwaggerString
90+-- & type_ ?~ OpenApiString
9191-- & enum_ ?~ [ \"Up\", \"Down\" ]
9292-- @
9393--
@@ -119,17 +119,17 @@ class ToParamSchema a where
119119 toParamSchema = genericToParamSchema defaultSchemaOptions
120120
121121instance {-# OVERLAPPING #-} ToParamSchema String where
122− toParamSchema _ = mempty & type_ ?~ SwaggerString
122+ toParamSchema _ = mempty & type_ ?~ OpenApiString
123123
124124instance ToParamSchema Bool where
125− toParamSchema _ = mempty & type_ ?~ SwaggerBoolean
125+ toParamSchema _ = mempty & type_ ?~ OpenApiBoolean
126126
127127instance ToParamSchema Integer where
128− toParamSchema _ = mempty & type_ ?~ SwaggerInteger
128+ toParamSchema _ = mempty & type_ ?~ OpenApiInteger
129129
130130instance ToParamSchema Natural where
131131 toParamSchema _ = mempty
132− & type_ ?~ SwaggerInteger
132+ & type_ ?~ OpenApiInteger
133133 & minimum_ ?~ 0
134134 & exclusiveMinimum ?~ False
135135
@@ -159,37 +159,37 @@ instance ToParamSchema Word64 where
159159-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
160160toParamSchemaBoundedIntegral :: forall a t. (Bounded a, Integral a) => Proxy a -> Schema
161161toParamSchemaBoundedIntegral _ = mempty
162− & type_ ?~ SwaggerInteger
162+ & type_ ?~ OpenApiInteger
163163 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
164164 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
165165
166166instance ToParamSchema Char where
167167 toParamSchema _ = mempty
168− & type_ ?~ SwaggerString
168+ & type_ ?~ OpenApiString
169169 & maxLength ?~ 1
170170 & minLength ?~ 1
171171
172172instance ToParamSchema Scientific where
173− toParamSchema _ = mempty & type_ ?~ SwaggerNumber
173+ toParamSchema _ = mempty & type_ ?~ OpenApiNumber
174174
175175instance HasResolution a => ToParamSchema (Fixed a) where
176176 toParamSchema _ = mempty
177− & type_ ?~ SwaggerNumber
177+ & type_ ?~ OpenApiNumber
178178 & multipleOf ?~ (recip . fromInteger $ resolution (Proxy :: Proxy a))
179179
180180instance ToParamSchema Double where
181181 toParamSchema _ = mempty
182− & type_ ?~ SwaggerNumber
182+ & type_ ?~ OpenApiNumber
183183 & format ?~ "double"
184184
185185instance ToParamSchema Float where
186186 toParamSchema _ = mempty
187− & type_ ?~ SwaggerNumber
187+ & type_ ?~ OpenApiNumber
188188 & format ?~ "float"
189189
190190timeParamSchema :: String -> Schema
191191timeParamSchema fmt = mempty
192− & type_ ?~ SwaggerString
192+ & type_ ?~ OpenApiString
193193 & format ?~ T.pack fmt
194194
195195-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -231,12 +231,12 @@ instance ToParamSchema TL.Text where
231231
232232instance ToParamSchema Version where
233233 toParamSchema _ = mempty
234− & type_ ?~ SwaggerString
234+ & type_ ?~ OpenApiString
235235 & pattern ?~ "^\\d+(\\.\\d+)*$"
236236
237237instance ToParamSchema SetCookie where
238238 toParamSchema _ = mempty
239− & type_ ?~ SwaggerString
239+ & type_ ?~ OpenApiString
240240
241241type family ToParamSchemaByteStringError bs where
242242 ToParamSchemaByteStringError bs = TypeError
@@ -259,7 +259,7 @@ instance ToParamSchema a => ToParamSchema (Identity a) where toParamSchema _ = t
259259
260260instance ToParamSchema a => ToParamSchema [a] where
261261 toParamSchema _ = mempty
262− & type_ ?~ SwaggerArray
262+ & type_ ?~ OpenApiArray
263263 & items ?~ SwaggerItemsObject (Inline $ toParamSchema (Proxy :: Proxy a))
264264
265265instance ToParamSchema a => ToParamSchema (V.Vector a) where toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
@@ -279,12 +279,12 @@ instance ToParamSchema a => ToParamSchema (HashSet a) where
279279-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
280280instance ToParamSchema () where
281281 toParamSchema _ = mempty
282− & type_ ?~ SwaggerString
282+ & type_ ?~ OpenApiString
283283 & enum_ ?~ ["_"]
284284
285285instance ToParamSchema UUID where
286286 toParamSchema _ = mempty
287− & type_ ?~ SwaggerString
287+ & type_ ?~ OpenApiString
288288 & format ?~ "uuid"
289289
290290-- | A configurable generic @'Schema'@ creator.
@@ -322,7 +322,7 @@ instance (GEnumParamSchema f, GEnumParamSchema g) => GEnumParamSchema (f :+: g)
322322
323323instance Constructor c => GEnumParamSchema (C1 c U1) where
324324 genumParamSchema opts _ s = s
325− & type_ ?~ SwaggerString
325+ & type_ ?~ OpenApiString
326326 & enum_ %~ addEnumValue tag
327327 where
328328 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
105105-- declareNamedSchema _ = do
106106-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
107107-- return $ NamedSchema (Just \"Coord\") $ mempty
108−-- & type_ ?~ SwaggerObject
108+-- & type_ ?~ OpenApiObject
109109-- & properties .~
110110-- [ (\"x\", doubleSchema)
111111-- , (\"y\", doubleSchema)
@@ -312,12 +312,12 @@ sketchSchema = sketch . toJSON
312312 sketch js@(Bool _) = go js
313313 sketch js = go js & example ?~ js
314314
315− go Null = mempty & type_ ?~ SwaggerNull
316− go (Bool _) = mempty & type_ ?~ SwaggerBoolean
317− go (String _) = mempty & type_ ?~ SwaggerString
318− go (Number _) = mempty & type_ ?~ SwaggerNumber
315+ go Null = mempty & type_ ?~ OpenApiNull
316+ go (Bool _) = mempty & type_ ?~ OpenApiBoolean
317+ go (String _) = mempty & type_ ?~ OpenApiString
318+ go (Number _) = mempty & type_ ?~ OpenApiNumber
319319 go (Array xs) = mempty
320− & type_ ?~ SwaggerArray
320+ & type_ ?~ OpenApiArray
321321 & items ?~ case ischema of
322322 Just s -> SwaggerItemsObject (Inline s)
323323 _ -> SwaggerItemsArray (map Inline ys)
@@ -329,7 +329,7 @@ sketchSchema = sketch . toJSON
329329 (z:_) | allSame -> Just z
330330 _ -> Nothing
331331 go (Object o) = mempty
332− & type_ ?~ SwaggerObject
332+ & type_ ?~ OpenApiObject
333333 & required .~ HashMap.keys o
334334 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
335335
@@ -352,24 +352,24 @@ sketchSchema = sketch . toJSON
352352sketchStrictSchema :: ToJSON a => a -> Schema
353353sketchStrictSchema = go . toJSON
354354 where
355− go Null = mempty & type_ ?~ SwaggerNull
355+ go Null = mempty & type_ ?~ OpenApiNull
356356 go js@(Bool _) = mempty
357− & type_ ?~ SwaggerBoolean
357+ & type_ ?~ OpenApiBoolean
358358 & enum_ ?~ [js]
359359 go js@(String s) = mempty
360− & type_ ?~ SwaggerString
360+ & type_ ?~ OpenApiString
361361 & maxLength ?~ fromIntegral (T.length s)
362362 & minLength ?~ fromIntegral (T.length s)
363363 & pattern ?~ s
364364 & enum_ ?~ [js]
365365 go js@(Number n) = mempty
366− & type_ ?~ SwaggerNumber
366+ & type_ ?~ OpenApiNumber
367367 & maximum_ ?~ n
368368 & minimum_ ?~ n
369369 & multipleOf ?~ n
370370 & enum_ ?~ [js]
371371 go js@(Array xs) = mempty
372− & type_ ?~ SwaggerArray
372+ & type_ ?~ OpenApiArray
373373 & maxItems ?~ fromIntegral sz
374374 & minItems ?~ fromIntegral sz
375375 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
@@ -379,7 +379,7 @@ sketchStrictSchema = go . toJSON
379379 sz = length xs
380380 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
381381 go js@(Object o) = mempty
382− & type_ ?~ SwaggerObject
382+ & type_ ?~ OpenApiObject
383383 & required .~ names
384384 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
385385 & maxProperties ?~ fromIntegral (length names)
@@ -395,7 +395,7 @@ instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
395395 declareNamedSchema _ = do
396396 ref <- declareSchemaRef (Proxy :: Proxy a)
397397 return $ unnamed $ mempty
398− & type_ ?~ SwaggerArray
398+ & type_ ?~ OpenApiArray
399399 & items ?~ SwaggerItemsObject ref
400400
401401instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
@@ -447,7 +447,7 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f
447447
448448timeSchema :: T.Text -> Schema
449449timeSchema fmt = mempty
450− & type_ ?~ SwaggerString
450+ & type_ ?~ OpenApiString
451451 & format ?~ fmt
452452
453453-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -505,7 +505,7 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
505505 declareObjectMapSchema = do
506506 schema <- declareSchemaRef (Proxy :: Proxy v)
507507 return $ unnamed $ mempty
508− & type_ ?~ SwaggerObject
508+ & type_ ?~ OpenApiObject
509509 & additionalProperties ?~ AdditionalPropertiesSchema schema
510510
511511instance (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
513513
514514instance {-# OVERLAPPING #-} ToSchema Object where
515515 declareNamedSchema _ = pure $ NamedSchema (Just "Object") $ mempty
516− & type_ ?~ SwaggerObject
516+ & type_ ?~ OpenApiObject
517517 & description ?~ "Arbitrary JSON object."
518518 & additionalProperties ?~ AdditionalPropertiesAllowed True
519519
@@ -554,7 +554,7 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
554554-- {"maximum":32767,"minimum":-32768,"type":"integer"}
555555toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
556556toSchemaBoundedIntegral _ = mempty
557− & type_ ?~ SwaggerInteger
557+ & type_ ?~ OpenApiInteger
558558 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
559559 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
560560
@@ -600,7 +600,7 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
600600 let allKeys = [minBound..maxBound :: key]
601601 mkPair k = (keyToText k, valueRef)
602602 return $ mempty
603− & type_ ?~ SwaggerObject
603+ & type_ ?~ OpenApiObject
604604 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
605605
606606-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
@@ -659,7 +659,7 @@ paramSchemaToSchema = toParamSchema
659659
660660nullarySchema :: Schema
661661nullarySchema = mempty
662− & type_ ?~ SwaggerArray
662+ & type_ ?~ OpenApiArray
663663 & items ?~ SwaggerItemsArray []
664664
665665gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
@@ -730,12 +730,12 @@ withFieldSchema opts _ isRequiredField schema = do
730730 return $
731731 if T.null fname
732732 then schema
733− & type_ ?~ SwaggerArray
733+ & type_ ?~ OpenApiArray
734734 & items %~ appendItem ref
735735 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
736736 & minItems %~ Just . maybe 1 (+1) -- increment minItems
737737 else schema
738− & type_ ?~ SwaggerObject
738+ & type_ ?~ OpenApiObject
739739 & properties . at fname ?~ ref
740740 & if isRequiredField
741741 then required %~ (++ [fname])
@@ -770,14 +770,14 @@ gdeclareNamedSumSchema opts proxy _
770770 | otherwise = do
771771 (schemas, _) <- runWriterT declareSumSchema
772772 return $ unnamed $ mempty
773− & type_ ?~ SwaggerObject
773+ & type_ ?~ OpenApiObject
774774 & oneOf ?~ (snd <$> schemas)
775775 where
776776 declareSumSchema = gsumToSchema opts proxy
777777 (sumSchemas, All allNullary) = undeclare (runWriterT declareSumSchema)
778778
779779 toStringTag schemas = mempty
780− & type_ ?~ SwaggerString
780+ & type_ ?~ OpenApiString
781781 & enum_ ?~ map (String . fst) sumSchemas
782782
783783type AllNullary = All
@@ -799,15 +799,15 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
799799 case ref of
800800 -- If subschema is an object and constructor is a record, we add tag directly
801801 -- 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
803803 & 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])
805805
806806 -- If it is not a record, we need to put subschema into "contents" field.
807807 _ | not isRecord -> Inline $ mempty
808− & type_ ?~ SwaggerObject
808+ & type_ ?~ OpenApiObject
809809 & 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])
811811 -- If constructor is nullary, there is no content.
812812 & case ref of
813813 Just r -> (properties . at (T.pack contentsField) ?~ r) . (required <>~ [T.pack contentsField])
@@ -815,17 +815,17 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
815815
816816 -- In the remaining cases we combine "tag" object and "contents" object using allOf.
817817 _ -> Inline $ mempty
818− & type_ ?~ SwaggerObject
818+ & type_ ?~ OpenApiObject
819819 & allOf ?~ [Inline $ mempty
820− & type_ ?~ SwaggerObject
820+ & type_ ?~ OpenApiObject
821821 & 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])]
823823 & if isRecord
824824 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]
826826 UntaggedValue -> refOrEnum -- Aeson encodes nullary constructors as strings in this case.
827827 ObjectWithSingleField -> Inline $ mempty
828− & type_ ?~ SwaggerObject
828+ & type_ ?~ OpenApiObject
829829 & required .~ [tag]
830830 & properties . at tag ?~ refOrNullary
831831 TwoElemArray -> error "unrepresentable in OpenAPI 3"
@@ -833,7 +833,7 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
833833 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
834834 isRecord = conIsRecord (Proxy3 :: Proxy3 c f p)
835835 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
837837
838838gsumConToSchema :: (GToSchema (C1 c f), Constructor c) =>
839839 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
423423-- This is like 'inferParamSchemaTypes', but also works for objects:
424424--
425425-- >>> inferSchemaTypes <$> decode "{\"minProperties\": 1}"
426−-- Just [SwaggerObject]
427−inferSchemaTypes :: Schema -> [SwaggerType]
426+-- Just [OpenApiObject]
427+inferSchemaTypes :: Schema -> [OpenApiType]
428428inferSchemaTypes sch = inferParamSchemaTypes sch ++
429− [ SwaggerObject | any ($ sch)
429+ [ OpenApiObject | any ($ sch)
430430 [ has (additionalProperties._Just)
431431 , has (maxProperties._Just)
432432 , has (minProperties._Just)
@@ -436,30 +436,30 @@ inferSchemaTypes sch = inferParamSchemaTypes sch ++
436436-- | Infer schema type based on used properties.
437437--
438438-- >>> inferSchemaTypes <$> decode "{\"minLength\": 2}"
439−-- Just [SwaggerString]
439+-- Just [OpenApiString]
440440--
441441-- >>> inferSchemaTypes <$> decode "{\"maxItems\": 0}"
442−-- Just [SwaggerArray]
442+-- Just [OpenApiArray]
443443--
444−-- From numeric properties 'SwaggerInteger' type is inferred.
445−-- If you want 'SwaggerNumber' instead, you must specify it explicitly.
444+-- From numeric properties 'OpenApiInteger' type is inferred.
445+-- If you want 'OpenApiNumber' instead, you must specify it explicitly.
446446--
447447-- >>> inferSchemaTypes <$> decode "{\"minimum\": 1}"
448−-- Just [SwaggerInteger]
449−inferParamSchemaTypes :: Schema -> [SwaggerType]
448+-- Just [OpenApiInteger]
449+inferParamSchemaTypes :: Schema -> [OpenApiType]
450450inferParamSchemaTypes sch = concat
451− [ [ SwaggerArray | any ($ sch)
451+ [ [ OpenApiArray | any ($ sch)
452452 [ has (items._Just)
453453 , has (maxItems._Just)
454454 , has (minItems._Just)
455455 , has (uniqueItems._Just) ] ]
456− , [ SwaggerInteger | any ($ sch)
456+ , [ OpenApiInteger | any ($ sch)
457457 [ has (exclusiveMaximum._Just)
458458 , has (exclusiveMinimum._Just)
459459 , has (maximum_._Just)
460460 , has (minimum_._Just)
461461 , has (multipleOf._Just) ] ]
462− , [ SwaggerString | any ($ sch)
462+ , [ OpenApiString | any ($ sch)
463463 [ has (maxLength._Just)
464464 , has (minLength._Just)
465465 , has (pattern._Just) ] ]
@@ -483,13 +483,13 @@ validateSchemaType val = withSchema $ \sch ->
483483
484484 _ ->
485485 case (sch ^. type_, val) of
486− (Just SwaggerNull, Null) -> valid
487− (Just SwaggerBoolean, Bool _) -> valid
488− (Just SwaggerInteger, Number n) -> validateInteger n
489− (Just SwaggerNumber, Number n) -> validateNumber n
490− (Just SwaggerString, String s) -> validateString s
491− (Just SwaggerArray, Array xs) -> validateArray xs
492− (Just SwaggerObject, Object o) -> validateObject o
486+ (Just OpenApiNull, Null) -> valid
487+ (Just OpenApiBoolean, Bool _) -> valid
488+ (Just OpenApiInteger, Number n) -> validateInteger n
489+ (Just OpenApiNumber, Number n) -> validateNumber n
490+ (Just OpenApiString, String s) -> validateString s
491+ (Just OpenApiArray, Array xs) -> validateArray xs
492+ (Just OpenApiObject, Object o) -> validateObject o
493493 (Nothing, Null) -> valid
494494 (Nothing, Bool _) -> valid
495495 -- Number by default
@@ -502,11 +502,11 @@ validateSchemaType val = withSchema $ \sch ->
502502validateParamSchemaType :: Value -> Validation Schema ()
503503validateParamSchemaType val = withSchema $ \sch ->
504504 case (sch ^. type_, val) of
505− (Just SwaggerBoolean, Bool _) -> valid
506− (Just SwaggerInteger, Number n) -> validateInteger n
507− (Just SwaggerNumber, Number n) -> validateNumber n
508− (Just SwaggerString, String s) -> validateString s
509− (Just SwaggerArray, Array xs) -> validateArray xs
505+ (Just OpenApiBoolean, Bool _) -> valid
506+ (Just OpenApiInteger, Number n) -> validateInteger n
507+ (Just OpenApiNumber, Number n) -> validateNumber n
508+ (Just OpenApiString, String s) -> validateString s
509+ (Just OpenApiArray, Array xs) -> validateArray xs
510510 (Nothing, Bool _) -> valid
511511 -- Number by default
512512 (Nothing, Number n) -> validateNumber n
@@ -514,11 +514,11 @@ validateParamSchemaType val = withSchema $ \sch ->
514514 (Nothing, Array xs) -> validateArray xs
515515 bad -> invalid $ "expected JSON value of type " ++ showType bad
516516
517−showType :: (Maybe SwaggerType, Value) -> String
517+showType :: (Maybe OpenApiType, Value) -> String
518518showType (Just ty, _) = show ty
519−showType (Nothing, Null) = "SwaggerNull"
520−showType (Nothing, Bool _) = "SwaggerBoolean"
521−showType (Nothing, Number _) = "SwaggerNumber"
522−showType (Nothing, String _) = "SwaggerString"
523−showType (Nothing, Array _) = "SwaggerArray"
524−showType (Nothing, Object _) = "SwaggerObject"
519+showType (Nothing, Null) = "OpenApiNull"
520+showType (Nothing, Bool _) = "OpenApiBoolean"
521+showType (Nothing, Number _) = "OpenApiNumber"
522+showType (Nothing, String _) = "OpenApiString"
523+showType (Nothing, Array _) = "OpenApiArray"
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
9999instance Ixed Operation where ix n = responses . ix n
100100instance At Operation where at n = responses . at n
101101
102−instance HasType NamedSchema (Maybe SwaggerType) where type_ = schema.type_
102+instance HasType NamedSchema (Maybe OpenApiType) where type_ = schema.type_
103103
104104-- OVERLAPPABLE instances
105105
src/Data/OpenApi/Optics.hs+4−4
@@ -23,7 +23,7 @@
2323--
2424-- >>> :{
2525-- BSL.putStrLn $ encode $ (mempty :: OpenApi)
26−-- & #components % #schemas .~ [ ("User", mempty & #type ?~ SwaggerString) ]
26+-- & #components % #schemas .~ [ ("User", mempty & #type ?~ OpenApiString) ]
2727-- & #paths .~
2828-- [ ("/user", mempty & #get ?~ (mempty
2929-- & at 200 ?~ ("OK" & #_Inline % #content % at "application/json" ?~ (mempty & #schema ?~ Ref (Reference "User")))
@@ -40,7 +40,7 @@
4040-- {"description":"No content"}
4141-- >>> :{
4242-- BSL.putStrLn $ encode $ (mempty :: Schema)
43−-- & #type ?~ SwaggerBoolean
43+-- & #type ?~ OpenApiBoolean
4444-- & #description ?~ "To be or not to be"
4545-- :}
4646-- {"type":"boolean","description":"To be or not to be"}
@@ -155,8 +155,8 @@ instance At Operation where
155155-- #type
156156
157157instance
158− ( a ~ Maybe SwaggerType
159− , b ~ Maybe SwaggerType
158+ ( a ~ Maybe OpenApiType
159+ , b ~ Maybe OpenApiType
160160 ) => LabelOptic "type" A_Lens NamedSchema NamedSchema a b where
161161 labelOptic = #schema % #type
162162 {-# INLINE labelOptic #-}
src/Data/OpenApi/Schema/Generator.hs+7−7
@@ -39,21 +39,21 @@ schemaGen defns schema =
3939 [ inferredType ] -> schemaGen defns (schema & type_ ?~ inferredType)
4040 -- Gen is not MonadFail
4141 _ -> error "unable to infer schema type"
42− Just SwaggerBoolean -> Bool <$> elements [True, False]
43− Just SwaggerNull -> pure Null
44− Just SwaggerNumber
42+ Just OpenApiBoolean -> Bool <$> elements [True, False]
43+ Just OpenApiNull -> pure Null
44+ Just OpenApiNumber
4545 | Just min <- schema ^. minimum_
4646 , Just max <- schema ^. maximum_ ->
4747 Number . fromFloatDigits <$>
4848 choose (toRealFloat min, toRealFloat max :: Double)
4949 | otherwise -> Number .fromFloatDigits <$> (arbitrary :: Gen Double)
50− Just SwaggerInteger
50+ Just OpenApiInteger
5151 | Just min <- schema ^. minimum_
5252 , Just max <- schema ^. maximum_ ->
5353 Number . fromInteger <$>
5454 choose (truncate min, truncate max)
5555 | otherwise -> Number . fromInteger <$> arbitrary
56− Just SwaggerArray
56+ Just OpenApiArray
5757 | Just 0 <- schema ^. maxLength -> pure $ Array V.empty
5858 | Just items <- schema ^. items ->
5959 case items of
@@ -68,14 +68,14 @@ schemaGen defns schema =
6868 SwaggerItemsArray refs ->
6969 let itemGens = schemaGen defns . dereference defns <$> refs
7070 in fmap (Array . V.fromList) $ sequence itemGens
71− Just SwaggerString -> do
71+ Just OpenApiString -> do
7272 size <- getSize
7373 let minLength' = fromMaybe 0 $ fromInteger <$> schema ^. minLength
7474 let maxLength' = fromMaybe size $ fromInteger <$> schema ^. maxLength
7575 length <- choose (minLength', max minLength' maxLength')
7676 str <- vectorOf length arbitrary
7777 return . String $ T.pack str
78− Just SwaggerObject -> do
78+ Just OpenApiObject -> do
7979 size <- getSize
8080 let props = dereference defns <$> schema ^. properties
8181 reqKeys = S.fromList $ schema ^. required
src/Data/OpenApi/Schema/Validation.hs+3−3
@@ -71,11 +71,11 @@ import Data.OpenApi.Internal.Schema.Validation
7171-- generally fails for @null@ JSON:
7272--
7373-- >>> validateToJSON (Nothing :: Maybe String)
74−-- ["expected JSON value of type SwaggerString"]
74+-- ["expected JSON value of type OpenApiString"]
7575-- >>> validateToJSON ([Just "hello", Nothing] :: [Maybe String])
76−-- ["expected JSON value of type SwaggerString"]
76+-- ["expected JSON value of type OpenApiString"]
7777-- >>> validateToJSON (123, Nothing :: Maybe String)
78−-- ["expected JSON value of type SwaggerString"]
78+-- ["expected JSON value of type OpenApiString"]
7979--
8080-- However, when @'Maybe' a@ is a type of a record field,
8181-- validation takes @'required'@ property of the @'Schema'@
test/Data/OpenApi/Schema/GeneratorSpec.hs+4−4
@@ -103,7 +103,7 @@ instance FromJSON WrongType where
103103instance ToSchema WrongType where
104104 declareNamedSchema _ = return . NamedSchema (Just "WrongType") $
105105 mempty
106− & type_ ?~ SwaggerObject
106+ & type_ ?~ OpenApiObject
107107
108108
109109data MissingRequired = MissingRequired
@@ -123,7 +123,7 @@ instance ToSchema MissingRequired where
123123 boolSchema <- declareSchemaRef (Proxy :: Proxy Bool)
124124 return . NamedSchema (Just "MissingRequired") $
125125 mempty
126− & type_ ?~ SwaggerObject
126+ & type_ ?~ OpenApiObject
127127 & properties .~ [("propA", stringSchema)
128128 ,("propB", boolSchema)
129129 ]
@@ -145,7 +145,7 @@ instance ToSchema MissingProperty where
145145 stringSchema <- declareSchemaRef (Proxy :: Proxy String)
146146 return . NamedSchema (Just "MissingProperty") $
147147 mempty
148− & type_ ?~ SwaggerObject
148+ & type_ ?~ OpenApiObject
149149 & properties .~ [("propC", stringSchema)]
150150 & required .~ ["propC"]
151151
@@ -163,6 +163,6 @@ instance ToSchema WrongPropType where
163163 boolSchema <- declareSchemaRef (Proxy :: Proxy Bool)
164164 return . NamedSchema (Just "WrongPropType") $
165165 mempty
166− & type_ ?~ SwaggerObject
166+ & type_ ?~ OpenApiObject
167167 & properties .~ [("propE", boolSchema)]
168168 & required .~ ["propE"]
test/Data/OpenApi/Schema/ValidationSpec.hs+1−1
@@ -277,7 +277,7 @@ instance ToJSON FreeForm where
277277
278278instance ToSchema FreeForm where
279279 declareNamedSchema _ = pure $ NamedSchema (Just $ T.pack "FreeForm") $ mempty
280− & type_ ?~ SwaggerObject
280+ & type_ ?~ OpenApiObject
281281 & additionalProperties ?~ AdditionalPropertiesAllowed True
282282
283283instance Arbitrary FreeForm where
test/Data/OpenApiSpec.hs+28−28
@@ -132,15 +132,15 @@ operationExample = mempty
132132 & description ?~ "ID of pet that needs to be updated"
133133 & required ?~ True
134134 & in_ .~ ParamPath
135− & schema ?~ Inline (mempty & type_ ?~ SwaggerString))]
135+ & schema ?~ Inline (mempty & type_ ?~ OpenApiString))]
136136 & requestBody ?~ Inline (
137137 mempty & content . at "application/x-www-form-urlencoded" ?~ (mempty & schema ?~ (Inline (mempty
138138 & properties . at "petId" ?~ Inline (mempty
139139 & description ?~ "Updated name of the pet"
140− & type_ ?~ SwaggerString)
140+ & type_ ?~ OpenApiString)
141141 & properties . at "status" ?~ Inline (mempty
142142 & description ?~ "Updated status of the pet"
143− & type_ ?~ SwaggerString)))))
143+ & type_ ?~ OpenApiString)))))
144144 & at 200 ?~ "Pet updated."
145145 & at 405 ?~ "Invalid input"
146146 & security .~ [SecurityRequirement [("petstore_auth", ["write:pets", "read:pets"])]]
@@ -208,7 +208,7 @@ operationExampleJSON = [aesonQQ|
208208
209209schemaPrimitiveExample :: Schema
210210schemaPrimitiveExample = mempty
211− & type_ ?~ SwaggerString
211+ & type_ ?~ OpenApiString
212212 & format ?~ "email"
213213
214214schemaPrimitiveExampleJSON :: Value
@@ -221,14 +221,14 @@ schemaPrimitiveExampleJSON = [aesonQQ|
221221
222222schemaSimpleModelExample :: Schema
223223schemaSimpleModelExample = mempty
224− & type_ ?~ SwaggerObject
224+ & type_ ?~ OpenApiObject
225225 & required .~ [ "name" ]
226226 & properties .~
227− [ ("name", Inline (mempty & type_ ?~ SwaggerString))
227+ [ ("name", Inline (mempty & type_ ?~ OpenApiString))
228228 , ("address", Ref (Reference "Address"))
229229 , ("age", Inline $ mempty
230230 & minimum_ ?~ 0
231− & type_ ?~ SwaggerInteger
231+ & type_ ?~ OpenApiInteger
232232 & format ?~ "int32" ) ]
233233
234234schemaSimpleModelExampleJSON :: Value
@@ -253,8 +253,8 @@ schemaSimpleModelExampleJSON = [aesonQQ|
253253
254254schemaModelDictExample :: Schema
255255schemaModelDictExample = mempty
256− & type_ ?~ SwaggerObject
257− & additionalProperties ?~ AdditionalPropertiesSchema (Inline (mempty & type_ ?~ SwaggerString))
256+ & type_ ?~ OpenApiObject
257+ & additionalProperties ?~ AdditionalPropertiesSchema (Inline (mempty & type_ ?~ OpenApiString))
258258
259259schemaModelDictExampleJSON :: Value
260260schemaModelDictExampleJSON = [aesonQQ|
@@ -268,7 +268,7 @@ schemaModelDictExampleJSON = [aesonQQ|
268268
269269schemaAdditionalExample :: Schema
270270schemaAdditionalExample = mempty
271− & type_ ?~ SwaggerObject
271+ & type_ ?~ OpenApiObject
272272 & additionalProperties ?~ AdditionalPropertiesAllowed True
273273
274274schemaAdditionalExampleJSON :: Value
@@ -281,13 +281,13 @@ schemaAdditionalExampleJSON = [aesonQQ|
281281
282282schemaWithExampleExample :: Schema
283283schemaWithExampleExample = mempty
284− & type_ ?~ SwaggerObject
284+ & type_ ?~ OpenApiObject
285285 & properties .~
286286 [ ("id", Inline $ mempty
287− & type_ ?~ SwaggerInteger
287+ & type_ ?~ OpenApiInteger
288288 & format ?~ "int64" )
289289 , ("name", Inline $ mempty
290− & type_ ?~ SwaggerString) ]
290+ & type_ ?~ OpenApiString) ]
291291 & required .~ [ "name" ]
292292 & example ?~ [aesonQQ|
293293 {
@@ -326,19 +326,19 @@ schemaWithExampleExampleJSON = [aesonQQ|
326326definitionsExample :: HashMap Text Schema
327327definitionsExample =
328328 [ ("Category", mempty
329− & type_ ?~ SwaggerObject
329+ & type_ ?~ OpenApiObject
330330 & properties .~
331331 [ ("id", Inline $ mempty
332− & type_ ?~ SwaggerInteger
332+ & type_ ?~ OpenApiInteger
333333 & format ?~ "int64")
334− , ("name", Inline (mempty & type_ ?~ SwaggerString)) ] )
334+ , ("name", Inline (mempty & type_ ?~ OpenApiString)) ] )
335335 , ("Tag", mempty
336− & type_ ?~ SwaggerObject
336+ & type_ ?~ OpenApiObject
337337 & properties .~
338338 [ ("id", Inline $ mempty
339− & type_ ?~ SwaggerInteger
339+ & type_ ?~ OpenApiInteger
340340 & format ?~ "int64")
341− , ("name", Inline (mempty & type_ ?~ SwaggerString)) ] ) ]
341+ , ("name", Inline (mempty & type_ ?~ OpenApiString)) ] ) ]
342342
343343definitionsExampleJSON :: Value
344344definitionsExampleJSON = [aesonQQ|
@@ -382,7 +382,7 @@ paramsDefinitionExample =
382382 & required ?~ True
383383 & in_ .~ ParamQuery
384384 & schema ?~ Inline (mempty
385− & type_ ?~ SwaggerInteger
385+ & type_ ?~ OpenApiInteger
386386 & format ?~ "int32" ))
387387 , ("limitParam", mempty
388388 & name .~ "limit"
@@ -390,7 +390,7 @@ paramsDefinitionExample =
390390 & required ?~ True
391391 & in_ .~ ParamQuery
392392 & schema ?~ Inline (mempty
393− & type_ ?~ SwaggerInteger
393+ & type_ ?~ OpenApiInteger
394394 & format ?~ "int32" )) ]
395395
396396paramsDefinitionExampleJSON :: Value
@@ -559,7 +559,7 @@ swaggerExample = mempty
559559 & description .~ "OK"
560560 & content . at "application/json" ?~ (mempty
561561 & schema ?~ Inline (mempty
562− & type_ ?~ SwaggerObject
562+ & type_ ?~ OpenApiObject
563563 & example ?~ [aesonQQ|
564564 {
565565 "created": 100,
@@ -568,9 +568,9 @@ swaggerExample = mempty
568568 & description ?~ "This is some real Todo right here"
569569 & properties .~
570570 [ ("created", Inline $ mempty
571− & type_ ?~ SwaggerInteger
571+ & type_ ?~ OpenApiInteger
572572 & format ?~ "int32")
573− , ("description", Inline (mempty & type_ ?~ SwaggerString))])))
573+ , ("description", Inline (mempty & type_ ?~ OpenApiString))])))
574574 & parameters .~
575575 [ Inline $ mempty
576576 & required ?~ True
@@ -578,7 +578,7 @@ swaggerExample = mempty
578578 & description ?~ "TodoId param"
579579 & in_ .~ ParamPath
580580 & schema ?~ Inline (mempty
581− & type_ ?~ SwaggerString ) ]
581+ & type_ ?~ OpenApiString ) ]
582582 & tags .~ InsOrdHS.fromList [ "todo" ] ))
583583
584584swaggerExampleJSON :: Value
@@ -917,14 +917,14 @@ petstoreExampleJSON = [aesonQQ|
917917
918918compositionSchemaExample :: Schema
919919compositionSchemaExample = mempty
920− & type_ ?~ SwaggerObject
920+ & type_ ?~ OpenApiObject
921921 & Data.OpenApi.allOf ?~ [
922922 Ref (Reference "Other")
923923 , Inline (mempty
924− & type_ ?~ SwaggerObject
924+ & type_ ?~ OpenApiObject
925925 & properties .~
926926 [ ("greet", Inline $ mempty
927− & type_ ?~ SwaggerString) ])
927+ & type_ ?~ OpenApiString) ])
928928 ]
929929
930930compositionSchemaExampleJSON :: Value