@@ -1,6 +1,8 @@
11{-# LANGUAGE DeriveGeneric #-}
22{-# LANGUAGE DeriveTraversable #-}
3+{-# LANGUAGE FlexibleContexts #-}
34{-# LANGUAGE FlexibleInstances #-}
5+{-# LANGUAGE GADTs #-}
46{-# LANGUAGE GeneralizedNewtypeDeriving #-}
57{-# LANGUAGE OverloadedStrings #-}
68{-# LANGUAGE RecordWildCards #-}
@@ -64,7 +66,7 @@ data Swagger = Swagger
6466
6567 -- | An object to hold parameters that can be used across operations.
6668 -- This property does not define global parameters for all operations.
67− , _parameters :: HashMap Text Parameter
69+ , _parameters :: HashMap Text Param
6870
6971 -- | An object to hold responses that can be used across operations.
7072 -- This property does not define global responses for all operations.
@@ -187,7 +189,7 @@ data PathItem = PathItem
187189 -- These parameters can be overridden at the operation level, but cannot be removed there.
188190 -- The list MUST NOT include duplicated parameters.
189191 -- A unique parameter is defined by a combination of a name and location.
190− , _pathItemParameters :: [Referenced Parameter]
192+ , _pathItemParameters :: [Referenced Param]
191193 } deriving (Eq, Show, Generic)
192194
193195-- | Describes a single API operation on a path.
@@ -228,7 +230,7 @@ data Operation = Operation
228230 -- the new definition will override it, but can never remove it.
229231 -- The list MUST NOT include duplicated parameters.
230232 -- A unique parameter is defined by a combination of a name and location.
231− , _operationParameters :: [Referenced Parameter]
233+ , _operationParameters :: [Referenced Param]
232234
233235 -- | The list of possible responses as they are returned from executing this operation.
234236 , _operationResponses :: Responses
@@ -255,81 +257,70 @@ newtype MimeList = MimeList { getMimeList :: [MediaType] }
255257
256258-- | Describes a single operation parameter.
257259-- A unique parameter is defined by a combination of a name and location.
258−data Parameter = Parameter
260+data Param = Param
259261 { -- | The name of the parameter.
260262 -- Parameter names are case sensitive.
261− _parameterName :: Text
263+ _paramName :: Text
262264
263265 -- | A brief description of the parameter.
264266 -- This could contain examples of use.
265267 -- GFM syntax can be used for rich text representation.
266− , _parameterDescription :: Maybe Text
268+ , _paramDescription :: Maybe Text
267269
268270 -- | Determines whether this parameter is mandatory.
269271 -- If the parameter is in "path", this property is required and its value MUST be true.
270272 -- Otherwise, the property MAY be included and its default value is @False@.
271− , _parameterRequired :: Maybe Bool
273+ , _paramRequired :: Maybe Bool
272274
273275 -- | Parameter schema.
274− , _parameterSchema :: ParameterSchema
276+ , _paramSchema :: ParamAnySchema
275277 } deriving (Eq, Show, Generic)
276278
277−data ParameterSchema
278− = ParameterBody (Referenced Schema)
279− | ParameterOther ParameterOtherSchema
279+data ParamAnySchema
280+ = ParamBody (Referenced Schema)
281+ | ParamOther ParamOtherSchema
280282 deriving (Eq, Show)
281283
282−data ParameterOtherSchema = ParameterOtherSchema
284+data ParamOtherSchema = ParamOtherSchema
283285 { -- | The location of the parameter.
284− _parameterOtherSchemaIn :: ParameterLocation
285−
286− -- | The type of the parameter.
287− -- Since the parameter is not located at the request body,
288− -- it is limited to simple types (that is, not an object).
289− -- If type is @'ParamFile'@, the @consumes@ MUST be either
290− -- "multipart/form-data" or " application/x-www-form-urlencoded"
291− -- and the parameter MUST be in @'ParameterFormData'@.
292− , _parameterOtherSchemaType :: ParameterType
293−
294− -- | The extending format for the previously mentioned type.
295− , _parameterOtherSchemaFormat :: Maybe Format
286+ _paramOtherSchemaIn :: ParamLocation
296287
297288 -- | Sets the ability to pass empty-valued parameters.
298− -- This is valid only for either @'ParameterQuery'@ or @'ParameterFormData'@
289+ -- This is valid only for either @'ParamQuery'@ or @'ParamFormData'@
299290 -- and allows you to send a parameter with a name only or an empty value.
300291 -- Default value is @False@.
301− , _parameterOtherSchemaAllowEmptyValue :: Maybe Bool
302−
303− -- | __Required if type is @'ParamArray'@__.
304− -- Describes the type of items in the array.
305− , _parameterOtherSchemaItems :: Maybe Items
292+ , _paramOtherSchemaAllowEmptyValue :: Maybe Bool
306293
307294 -- | Determines the format of the array if @'ParamArray'@ is used.
308295 -- Default value is csv.
309− , _parameterOtherSchemaCollectionFormat :: Maybe CollectionFormat
296+ , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
310297
311− , _parameterOtherSchemaCommon :: SchemaCommon
298+ , _paramOtherSchemaParamSchema :: ParamSchema ParamOtherSchema Items
312299 } deriving (Eq, Show, Generic)
313300
314−data ParameterType
315− = ParamString
316− | ParamNumber
317− | ParamInteger
318− | ParamBoolean
319− | ParamArray
320− | ParamFile
321− deriving (Eq, Show)
301+data SwaggerType t where
302+ SwaggerString :: SwaggerType t
303+ SwaggerNumber :: SwaggerType t
304+ SwaggerInteger :: SwaggerType t
305+ SwaggerBoolean :: SwaggerType t
306+ SwaggerArray :: SwaggerType t
307+ SwaggerFile :: SwaggerType ParamOtherSchema
308+ SwaggerNull :: SwaggerType Schema
309+ SwaggerObject :: SwaggerType Schema
322310
323−data ParameterLocation
311+deriving instance Eq (SwaggerType t)
312+deriving instance Show (SwaggerType t)
313+
314+data ParamLocation
324315 = -- | Parameters that are appended to the URL.
325316 -- For example, in @/items?id=###@, the query parameter is @id@.
326− ParameterQuery
317+ ParamQuery
327318 -- | Custom headers that are expected as part of the request.
328− | ParameterHeader
319+ | ParamHeader
329320 -- | Used together with Path Templating, where the parameter value is actually part of the operation's URL.
330321 -- This does not include the host or base path of the API.
331322 -- For example, in @/items/{itemId}@, the path parameter is @itemId@.
332− | ParameterPath
323+ | ParamPath
333324 -- | Used to describe the payload of an HTTP request when either @application/x-www-form-urlencoded@
334325 -- or @multipart/form-data@ are used as the content type of the request
335326 -- (in Swagger's definition, the @consumes@ property of an operation).
@@ -337,58 +328,36 @@ data ParameterLocation
337328 -- Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation.
338329 -- Form parameters have a different format based on the content-type used
339330 -- (for further details, consult <http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4>).
340− | ParameterFormData
331+ | ParamFormData
341332 deriving (Eq, Show)
342333
343334type Format = Text
344335
345336-- | Determines the format of the array.
346−data CollectionFormat
347− = CollectionCSV -- ^ Comma separated values: @foo,bar@.
348− | CollectionSSV -- ^ Space separated values: @foo bar@.
349− | CollectionTSV -- ^ Tab separated values: @foo\\tbar@.
350− | CollectionPipes -- ^ Pipe separated values: @foo|bar@.
351− | CollectionMulti -- ^ Corresponds to multiple parameter instances
352− -- instead of multiple values for a single instance @foo=bar&foo=baz@.
353− -- This is valid only for parameters in @'ParameterQuery'@ or @'ParameterFormData'@.
354− deriving (Eq, Show)
355−
356−data ItemsType
357− = ItemsString
358− | ItemsNumber
359− | ItemsInteger
360− | ItemsBoolean
361− | ItemsArray
362− deriving (Eq, Show)
363−
364−data SchemaType
365− = SchemaArray
366− | SchemaBoolean
367− | SchemaInteger
368− | SchemaNumber
369− | SchemaNull
370− | SchemaObject
371− | SchemaString
372− deriving (Eq, Show)
373−
374−-- | Determines the format of the nested array.
375−data ItemsCollectionFormat
376− = ItemsCollectionCSV -- ^ Comma separated values: @foo,bar@.
377− | ItemsCollectionSSV -- ^ Space separated values: @foo bar@.
378− | ItemsCollectionTSV -- ^ Tab separated values: @foo\\tbar@.
379− | ItemsCollectionPipes -- ^ Pipe separated values: @foo|bar@.
380− deriving (Eq, Show)
337+data CollectionFormat t where
338+ -- Comma separated values: @foo,bar@.
339+ CollectionCSV :: CollectionFormat t
340+ -- Space separated values: @foo bar@.
341+ CollectionSSV :: CollectionFormat t
342+ -- Tab separated values: @foo\\tbar@.
343+ CollectionTSV :: CollectionFormat t
344+ -- Pipe separated values: @foo|bar@.
345+ CollectionPipes :: CollectionFormat t
346+ -- Corresponds to multiple parameter instances
347+ -- instead of multiple values for a single instance @foo=bar&foo=baz@.
348+ -- This is valid only for parameters in @'ParamQuery'@ or @'ParamFormData'@.
349+ CollectionMulti :: CollectionFormat Param
350+
351+deriving instance Eq (CollectionFormat t)
352+deriving instance Show (CollectionFormat t)
381353
382354type ParamName = Text
383355
384356data Schema = Schema
385− { _schemaType :: SchemaType
386− , _schemaFormat :: Maybe Format
387− , _schemaTitle :: Maybe Text
357+ { _schemaTitle :: Maybe Text
388358 , _schemaDescription :: Maybe Text
389359 , _schemaRequired :: [ParamName]
390360
391− , _schemaItems :: Maybe SchemaItems
392361 , _schemaAllOf :: Maybe [Schema]
393362 , _schemaProperties :: HashMap Text (Referenced Schema)
394363 , _schemaAdditionalProperties :: Maybe Schema
@@ -402,7 +371,7 @@ data Schema = Schema
402371 , _schemaMaxProperties :: Maybe Integer
403372 , _schemaMinProperties :: Maybe Integer
404373
405− , _schemaSchemaCommon :: SchemaCommon
374+ , _schemaParamSchema :: ParamSchema Schema SchemaItems
406375 } deriving (Eq, Show, Generic)
407376
408377data SchemaItems
@@ -410,26 +379,29 @@ data SchemaItems
410379 | SchemaItemsArray [Referenced Schema]
411380 deriving (Eq, Show)
412381
413−data SchemaCommon = SchemaCommon
382+data ParamSchema t items = ParamSchema
414383 { -- | Declares the value of the parameter that the server will use if none is provided,
415384 -- for example a @"count"@ to control the number of results per page might default to @100@
416385 -- if not supplied by the client in the request.
417386 -- (Note: "default" has no meaning for required parameters.)
418387 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
419− _schemaCommonDefault :: Maybe Value
420−
421− , _schemaCommonMaximum :: Maybe Scientific
422− , _schemaCommonExclusiveMaximum :: Maybe Bool
423− , _schemaCommonMinimum :: Maybe Scientific
424− , _schemaCommonExclusiveMinimum :: Maybe Bool
425− , _schemaCommonMaxLength :: Maybe Integer
426− , _schemaCommonMinLength :: Maybe Integer
427− , _schemaCommonPattern :: Maybe Text
428− , _schemaCommonMaxItems :: Maybe Integer
429− , _schemaCommonMinItems :: Maybe Integer
430− , _schemaCommonUniqueItems :: Maybe Bool
431− , _schemaCommonEnum :: Maybe [Value]
432− , _schemaCommonMultipleOf :: Maybe Scientific
388+ _paramSchemaDefault :: Maybe Value
389+
390+ , _paramSchemaType :: SwaggerType t
391+ , _paramSchemaFormat :: Maybe Format
392+ , _paramSchemaItems :: Maybe items
393+ , _paramSchemaMaximum :: Maybe Scientific
394+ , _paramSchemaExclusiveMaximum :: Maybe Bool
395+ , _paramSchemaMinimum :: Maybe Scientific
396+ , _paramSchemaExclusiveMinimum :: Maybe Bool
397+ , _paramSchemaMaxLength :: Maybe Integer
398+ , _paramSchemaMinLength :: Maybe Integer
399+ , _paramSchemaPattern :: Maybe Text
400+ , _paramSchemaMaxItems :: Maybe Integer
401+ , _paramSchemaMinItems :: Maybe Integer
402+ , _paramSchemaUniqueItems :: Maybe Bool
403+ , _paramSchemaEnum :: Maybe [Value]
404+ , _paramSchemaMultipleOf :: Maybe Scientific
433405 } deriving (Eq, Show, Generic)
434406
435407data Xml = Xml
@@ -461,21 +433,11 @@ data Xml = Xml
461433 } deriving (Eq, Show, Generic)
462434
463435data Items = Items
464− { -- | The internal type of the array.
465− _itemsType :: ItemsType
466−
467− -- | The extending format for the previously mentioned type.
468− , _itemsFormat :: Maybe Format
469−
470− -- | __Required if type is @'ItemsArray'@.__
471− -- Describes the type of items in the array.
472− , _itemsItems :: Maybe Items
473−
474− -- | Determines the format of the array if type array is used.
436+ { -- | Determines the format of the array if type array is used.
475437 -- Default value is @'ItemsCollectionCSV'@.
476− , _itemsCollectionFormat :: Maybe ItemsCollectionFormat
438+ _itemsCollectionFormat :: Maybe (CollectionFormat Items)
477439
478− , _itemsCommon :: SchemaCommon
440+ , _itemsParamSchema :: ParamSchema Items Items
479441 } deriving (Eq, Show, Generic)
480442
481443-- | A container for the expected responses of an operation.
@@ -521,21 +483,11 @@ data Header = Header
521483 { -- | A short description of the header.
522484 _headerDescription :: Maybe Text
523485
524− -- | The type of the object.
525− , _headerType :: ItemsType
526−
527− -- | The extending format for the previously mentioned type. See Data Type Formats for further details.
528− , _headerFormat :: Maybe Format
529−
530− -- | __Required if type is @'ItemsArray'@__.
531− -- Describes the type of items in the array.
532− , _headerItems :: Maybe Items
533−
534486 -- | Determines the format of the array if type array is used.
535487 -- Default value is @'ItemsCollectionCSV'@.
536− , _headerCollectionFormat :: Maybe ItemsCollectionFormat
488+ , _headerCollectionFormat :: Maybe (CollectionFormat Items)
537489
538− , _headerCommon :: SchemaCommon
490+ , _headerParamSchema :: ParamSchema Header Items
539491 } deriving (Eq, Show, Generic)
540492
541493data Example = Example { getExample :: Map MediaType Value }
@@ -657,15 +609,15 @@ instance Monoid Schema where
657609 mempty = genericMempty
658610 mappend = genericMappend
659611
660−instance Monoid SchemaCommon where
612+instance Monoid (ParamSchema t i) where
661613 mempty = genericMempty
662614 mappend = genericMappend
663615
664−instance Monoid Parameter where
616+instance Monoid Param where
665617 mempty = genericMempty
666618 mappend = genericMappend
667619
668−instance Monoid ParameterOtherSchema where
620+instance Monoid ParamOtherSchema where
669621 mempty = genericMempty
670622 mappend = genericMappend
671623
@@ -693,9 +645,9 @@ instance SwaggerMonoid Info
693645instance SwaggerMonoid Paths
694646instance SwaggerMonoid PathItem
695647instance SwaggerMonoid Schema
696−instance SwaggerMonoid SchemaCommon
697−instance SwaggerMonoid Parameter
698−instance SwaggerMonoid ParameterOtherSchema
648+instance SwaggerMonoid (ParamSchema t i)
649+instance SwaggerMonoid Param
650+instance SwaggerMonoid ParamOtherSchema
699651instance SwaggerMonoid Responses
700652instance SwaggerMonoid Response
701653instance SwaggerMonoid ExternalDocs
@@ -704,16 +656,12 @@ instance SwaggerMonoid Operation
704656instance SwaggerMonoid MimeList
705657deriving instance SwaggerMonoid URL
706658
707−instance SwaggerMonoid SchemaType where
708− swaggerMempty = SchemaNull
709− swaggerMappend _ y = y
710−
711−instance SwaggerMonoid ParameterType where
712− swaggerMempty = ParamString
659+instance SwaggerMonoid (SwaggerType t) where
660+ swaggerMempty = SwaggerString
713661 swaggerMappend _ y = y
714662
715−instance SwaggerMonoid ParameterLocation where
716− swaggerMempty = ParameterQuery
663+instance SwaggerMonoid ParamLocation where
664+ swaggerMempty = ParamQuery
717665 swaggerMappend _ y = y
718666
719667instance SwaggerMonoid (HashMap Text Schema) where
@@ -729,7 +677,7 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
729677 swaggerMappend (Inline x) (Inline y) = Inline (x <> y)
730678 swaggerMappend _ y = y
731679
732−instance SwaggerMonoid (HashMap Text Parameter) where
680+instance SwaggerMonoid (HashMap Text Param) where
733681 swaggerMempty = HashMap.empty
734682 swaggerMappend = HashMap.unionWith mappend
735683
@@ -753,28 +701,22 @@ instance SwaggerMonoid (HashMap HttpStatusCode (Referenced Response)) where
753701 swaggerMempty = HashMap.empty
754702 swaggerMappend = flip HashMap.union
755703
756−instance SwaggerMonoid ParameterSchema where
757− swaggerMempty = ParameterOther swaggerMempty
758− swaggerMappend (ParameterBody x) (ParameterBody y) = ParameterBody (swaggerMappend x y)
759− swaggerMappend (ParameterOther x) (ParameterOther y) = ParameterOther (swaggerMappend x y)
704+instance SwaggerMonoid ParamAnySchema where
705+ swaggerMempty = ParamOther swaggerMempty
706+ swaggerMappend (ParamBody x) (ParamBody y) = ParamBody (swaggerMappend x y)
707+ swaggerMappend (ParamOther x) (ParamOther y) = ParamOther (swaggerMappend x y)
760708 swaggerMappend _ y = y
761709
762710-- =======================================================================
763711-- TH derived ToJSON and FromJSON instances
764712-- =======================================================================
765713
766−deriveJSON (jsonPrefix "Parameter") ''ParameterLocation
767−deriveJSON (jsonPrefix "Param") ''ParameterType
714+deriveJSON (jsonPrefix "Param") ''ParamLocation
768715deriveJSON' ''Info
769716deriveJSON' ''Contact
770717deriveJSON' ''License
771−deriveJSON (jsonPrefix "Schema") ''SchemaType
772−deriveJSON (jsonPrefix "Items") ''ItemsType
773−deriveJSON (jsonPrefix "ItemsCollection") ''ItemsCollectionFormat
774−deriveJSON (jsonPrefix "Collection") ''CollectionFormat
775718deriveJSON (jsonPrefix "ApiKey") ''ApiKeyLocation
776719deriveJSON (jsonPrefix "apiKey") ''ApiKeyParams
777−deriveJSON' ''SchemaCommon
778720deriveJSONDefault ''Scheme
779721deriveJSON' ''Tag
780722deriveJSON' ''ExternalDocs
@@ -826,13 +768,13 @@ instance ToJSON SecurityScheme where
826768 toJSON = genericToJSONWithSub "type" (jsonPrefix "securityScheme")
827769
828770instance ToJSON Schema where
829− toJSON = genericToJSONWithSub "schemaCommon" (jsonPrefix "schema")
771+ toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "schema")
830772
831773instance ToJSON Header where
832− toJSON = genericToJSONWithSub "common" (jsonPrefix "header")
774+ toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "header")
833775
834776instance ToJSON Items where
835− toJSON = genericToJSONWithSub "common" (jsonPrefix "items")
777+ toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "items")
836778
837779instance ToJSON Host where
838780 toJSON (Host host mport) = toJSON $
@@ -846,15 +788,15 @@ instance ToJSON Paths where
846788instance ToJSON MimeList where
847789 toJSON (MimeList xs) = toJSON (map show xs)
848790
849−instance ToJSON Parameter where
850− toJSON = genericToJSONWithSub "schema" (jsonPrefix "parameter")
791+instance ToJSON Param where
792+ toJSON = genericToJSONWithSub "schema" (jsonPrefix "param")
851793
852−instance ToJSON ParameterSchema where
853− toJSON (ParameterBody s) = object [ "in" .= ("body" :: Text), "schema" .= s ]
854− toJSON (ParameterOther s) = toJSON s
794+instance ToJSON ParamAnySchema where
795+ toJSON (ParamBody s) = object [ "in" .= ("body" :: Text), "schema" .= s ]
796+ toJSON (ParamOther s) = toJSON s
855797
856−instance ToJSON ParameterOtherSchema where
857− toJSON = genericToJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
798+instance ToJSON ParamOtherSchema where
799+ toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
858800
859801instance ToJSON SchemaItems where
860802 toJSON (SchemaItemsObject x) = toJSON x
@@ -873,6 +815,26 @@ instance ToJSON a => ToJSON (Referenced a) where
873815 toJSON (Ref ref) = toJSON ref
874816 toJSON (Inline x) = toJSON x
875817
818+instance ToJSON (SwaggerType t) where
819+ toJSON SwaggerArray = "array"
820+ toJSON SwaggerString = "string"
821+ toJSON SwaggerInteger = "integer"
822+ toJSON SwaggerNumber = "number"
823+ toJSON SwaggerBoolean = "boolean"
824+ toJSON SwaggerFile = "file"
825+ toJSON SwaggerNull = "null"
826+ toJSON SwaggerObject = "object"
827+
828+instance ToJSON (CollectionFormat t) where
829+ toJSON CollectionCSV = "csv"
830+ toJSON CollectionSSV = "ssv"
831+ toJSON CollectionTSV = "tsv"
832+ toJSON CollectionPipes = "pipes"
833+ toJSON CollectionMulti = "multi"
834+
835+instance ToJSON i => ToJSON (ParamSchema t i) where
836+ toJSON = genericToJSON (jsonPrefix "paramSchema")
837+
876838-- =======================================================================
877839-- Manual FromJSON instances
878840-- =======================================================================
@@ -913,7 +875,7 @@ instance FromJSON Swagger where
913875 , "security" .= ([] :: [SecurityRequirement])
914876 , "tags" .= ([] :: [Tag])
915877 , "definitions" .= (mempty :: HashMap Text Schema)
916− , "parameters" .= (mempty :: HashMap Text Parameter)
878+ , "parameters" .= (mempty :: HashMap Text Param)
917879 , "responses" .= (mempty :: HashMap Text Response)
918880 , "securityDefinitions" .= (mempty :: HashMap Text SecurityScheme)
919881 ] ) js
@@ -923,15 +885,15 @@ instance FromJSON SecurityScheme where
923885 parseJSON = genericParseJSONWithSub "type" (jsonPrefix "securityScheme")
924886
925887instance FromJSON Schema where
926− parseJSON = genericParseJSONWithSub "schemaCommon" (jsonPrefix "schema")
888+ parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "schema")
927889 `withDefaults` [ "properties" .= (mempty :: HashMap Text Schema)
928890 , "required" .= ([] :: [ParamName]) ]
929891
930892instance FromJSON Header where
931− parseJSON = genericParseJSONWithSub "common" (jsonPrefix "header")
893+ parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "header")
932894
933895instance FromJSON Items where
934− parseJSON = genericParseJSONWithSub "common" (jsonPrefix "items")
896+ parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "items")
935897
936898instance FromJSON Host where
937899 parseJSON (String s) =
@@ -949,21 +911,21 @@ instance FromJSON Paths where
949911instance FromJSON MimeList where
950912 parseJSON js = (MimeList . map fromString) <$> parseJSON js
951913
952−instance FromJSON Parameter where
953− parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "parameter")
914+instance FromJSON Param where
915+ parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "param")
954916
955−instance FromJSON ParameterSchema where
917+instance FromJSON ParamAnySchema where
956918 parseJSON js@(Object o) = do
957919 (i :: Text) <- o .: "in"
958920 case i of
959921 "body" -> do
960922 schema <- o .: "schema"
961− ParameterBody <$> parseJSON schema
962− _ -> ParameterOther <$> parseJSON js
923+ ParamBody <$> parseJSON schema
924+ _ -> ParamOther <$> parseJSON js
963925 parseJSON _ = empty
964926
965−instance FromJSON ParameterOtherSchema where
966− parseJSON = genericParseJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
927+instance FromJSON ParamOtherSchema where
928+ parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
967929
968930instance FromJSON SchemaItems where
969931 parseJSON js@(Object _) = SchemaItemsObject <$> parseJSON js
@@ -991,7 +953,7 @@ instance FromJSON Operation where
991953
992954instance FromJSON PathItem where
993955 parseJSON = genericParseJSON (jsonPrefix "pathItem")
994− `withDefaults` [ "parameters" .= ([] :: [Parameter]) ]
956+ `withDefaults` [ "parameters" .= ([] :: [Param]) ]
995957
996958instance FromJSON Reference where
997959 parseJSON (Object o) = Reference <$> o .: "$ref"
@@ -1005,3 +967,23 @@ instance FromJSON a => FromJSON (Referenced a) where
1005967instance FromJSON Xml where
1006968 parseJSON = genericParseJSON (jsonPrefix "xml")
1007969
970+instance FromJSON (SwaggerType Schema) where
971+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray, SwaggerNull, SwaggerObject]
972+
973+instance FromJSON (SwaggerType ParamOtherSchema) where
974+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray, SwaggerFile]
975+
976+instance {-# OVERLAPPABLE #-} FromJSON (SwaggerType t) where
977+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray]
978+
979+instance FromJSON (CollectionFormat Param) where
980+ parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes, CollectionMulti]
981+
982+instance FromJSON (CollectionFormat Items) where
983+ parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
984+
985+-- NOTE: The constraint @FromJSON (SwaggerType t)@ is necessary here!
986+-- Without the constraint the general instance will be used
987+-- that only accepts common types (i.e. NOT object, null or file).
988+instance (FromJSON (SwaggerType t), FromJSON i) => FromJSON (ParamSchema t i) where
989+ parseJSON = genericParseJSON (jsonPrefix "ParamSchema")