@@ -1,6 +1,8 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveTraversable #-}
2{-# LANGUAGE DeriveTraversable #-}
3+{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE RecordWildCards #-}
8{-# LANGUAGE RecordWildCards #-}
@@ -64,7 +66,7 @@ data Swagger = Swagger
65 -- | An object to hold parameters that can be used across operations.
67 -- | An object to hold parameters that can be used across operations.
66 -- This property does not define global parameters for all operations.
68 -- This property does not define global parameters for all operations.
67− , _parameters :: HashMap Text Parameter
69+ , _parameters :: HashMap Text Param
69 -- | An object to hold responses that can be used across operations.
71 -- | An object to hold responses that can be used across operations.
70 -- This property does not define global responses for all operations.
72 -- This property does not define global responses for all operations.
@@ -187,7 +189,7 @@ data PathItem = PathItem
187 -- These parameters can be overridden at the operation level, but cannot be removed there.
189 -- These parameters can be overridden at the operation level, but cannot be removed there.
188 -- The list MUST NOT include duplicated parameters.
190 -- The list MUST NOT include duplicated parameters.
189 -- A unique parameter is defined by a combination of a name and location.
191 -- A unique parameter is defined by a combination of a name and location.
190− , _pathItemParameters :: [Referenced Parameter]
192+ , _pathItemParameters :: [Referenced Param]
191 } deriving (Eq, Show, Generic)
193 } deriving (Eq, Show, Generic)
193-- | Describes a single API operation on a path.
195-- | Describes a single API operation on a path.
@@ -228,7 +230,7 @@ data Operation = Operation
228 -- the new definition will override it, but can never remove it.
230 -- the new definition will override it, but can never remove it.
229 -- The list MUST NOT include duplicated parameters.
231 -- The list MUST NOT include duplicated parameters.
230 -- A unique parameter is defined by a combination of a name and location.
232 -- A unique parameter is defined by a combination of a name and location.
231− , _operationParameters :: [Referenced Parameter]
233+ , _operationParameters :: [Referenced Param]
233 -- | The list of possible responses as they are returned from executing this operation.
235 -- | The list of possible responses as they are returned from executing this operation.
234 , _operationResponses :: Responses
236 , _operationResponses :: Responses
@@ -255,81 +257,70 @@ newtype MimeList = MimeList { getMimeList :: [MediaType] }
256-- | Describes a single operation parameter.
258-- | Describes a single operation parameter.
257-- A unique parameter is defined by a combination of a name and location.
259-- A unique parameter is defined by a combination of a name and location.
258−data Parameter = Parameter
260+data Param = Param
259 { -- | The name of the parameter.
261 { -- | The name of the parameter.
260 -- Parameter names are case sensitive.
262 -- Parameter names are case sensitive.
261− _parameterName :: Text
263+ _paramName :: Text
263 -- | A brief description of the parameter.
265 -- | A brief description of the parameter.
264 -- This could contain examples of use.
266 -- This could contain examples of use.
265 -- GFM syntax can be used for rich text representation.
267 -- GFM syntax can be used for rich text representation.
266− , _parameterDescription :: Maybe Text
268+ , _paramDescription :: Maybe Text
268 -- | Determines whether this parameter is mandatory.
270 -- | Determines whether this parameter is mandatory.
269 -- If the parameter is in "path", this property is required and its value MUST be true.
271 -- If the parameter is in "path", this property is required and its value MUST be true.
270 -- Otherwise, the property MAY be included and its default value is @False@.
272 -- Otherwise, the property MAY be included and its default value is @False@.
271− , _parameterRequired :: Maybe Bool
273+ , _paramRequired :: Maybe Bool
273 -- | Parameter schema.
275 -- | Parameter schema.
274− , _parameterSchema :: ParameterSchema
276+ , _paramSchema :: ParamAnySchema
275 } deriving (Eq, Show, Generic)
277 } deriving (Eq, Show, Generic)
277−data ParameterSchema
279+data ParamAnySchema
278− = ParameterBody (Referenced Schema)
280+ = ParamBody (Referenced Schema)
279− | ParameterOther ParameterOtherSchema
281+ | ParamOther ParamOtherSchema
280 deriving (Eq, Show)
282 deriving (Eq, Show)
282−data ParameterOtherSchema = ParameterOtherSchema
284+data ParamOtherSchema = ParamOtherSchema
283 { -- | The location of the parameter.
285 { -- | The location of the parameter.
284− _parameterOtherSchemaIn :: ParameterLocation
286+ _paramOtherSchemaIn :: ParamLocation
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
294− -- | The extending format for the previously mentioned type.
295− , _parameterOtherSchemaFormat :: Maybe Format
297 -- | Sets the ability to pass empty-valued parameters.
288 -- | 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'@
299 -- and allows you to send a parameter with a name only or an empty value.
290 -- and allows you to send a parameter with a name only or an empty value.
300 -- Default value is @False@.
291 -- Default value is @False@.
301− , _parameterOtherSchemaAllowEmptyValue :: Maybe Bool
292+ , _paramOtherSchemaAllowEmptyValue :: Maybe Bool
303− -- | __Required if type is @'ParamArray'@__.
304− -- Describes the type of items in the array.
305− , _parameterOtherSchemaItems :: Maybe Items
307 -- | Determines the format of the array if @'ParamArray'@ is used.
294 -- | Determines the format of the array if @'ParamArray'@ is used.
308 -- Default value is csv.
295 -- Default value is csv.
309− , _parameterOtherSchemaCollectionFormat :: Maybe CollectionFormat
296+ , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
311− , _parameterOtherSchemaCommon :: SchemaCommon
298+ , _paramOtherSchemaParamSchema :: ParamSchema ParamOtherSchema Items
312 } deriving (Eq, Show, Generic)
299 } deriving (Eq, Show, Generic)
314−data ParameterType
301+data SwaggerType t where
315− = ParamString
302+ SwaggerString :: SwaggerType t
316− | ParamNumber
303+ SwaggerNumber :: SwaggerType t
317− | ParamInteger
304+ SwaggerInteger :: SwaggerType t
318− | ParamBoolean
305+ SwaggerBoolean :: SwaggerType t
319− | ParamArray
306+ SwaggerArray :: SwaggerType t
320− | ParamFile
307+ SwaggerFile :: SwaggerType ParamOtherSchema
321− deriving (Eq, Show)
308+ SwaggerNull :: SwaggerType Schema
309+ SwaggerObject :: SwaggerType Schema
323−data ParameterLocation
311+deriving instance Eq (SwaggerType t)
312+deriving instance Show (SwaggerType t)
324 = -- | Parameters that are appended to the URL.
315 = -- | Parameters that are appended to the URL.
325 -- For example, in @/items?id=###@, the query parameter is @id@.
316 -- For example, in @/items?id=###@, the query parameter is @id@.
326− ParameterQuery
317+ ParamQuery
327 -- | Custom headers that are expected as part of the request.
318 -- | Custom headers that are expected as part of the request.
328− | ParameterHeader
319+ | ParamHeader
329 -- | Used together with Path Templating, where the parameter value is actually part of the operation's URL.
320 -- | Used together with Path Templating, where the parameter value is actually part of the operation's URL.
330 -- This does not include the host or base path of the API.
321 -- This does not include the host or base path of the API.
331 -- For example, in @/items/{itemId}@, the path parameter is @itemId@.
322 -- For example, in @/items/{itemId}@, the path parameter is @itemId@.
332− | ParameterPath
323+ | ParamPath
333 -- | Used to describe the payload of an HTTP request when either @application/x-www-form-urlencoded@
324 -- | Used to describe the payload of an HTTP request when either @application/x-www-form-urlencoded@
334 -- or @multipart/form-data@ are used as the content type of the request
325 -- or @multipart/form-data@ are used as the content type of the request
335 -- (in Swagger's definition, the @consumes@ property of an operation).
326 -- (in Swagger's definition, the @consumes@ property of an operation).
@@ -337,58 +328,36 @@ data ParameterLocation
337 -- Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation.
328 -- Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation.
338 -- Form parameters have a different format based on the content-type used
329 -- Form parameters have a different format based on the content-type used
339 -- (for further details, consult <http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4>).
330 -- (for further details, consult <http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4>).
340− | ParameterFormData
331+ | ParamFormData
341 deriving (Eq, Show)
332 deriving (Eq, Show)
343type Format = Text
334type Format = Text
345-- | Determines the format of the array.
336-- | Determines the format of the array.
346−data CollectionFormat
337+data CollectionFormat t where
338+ -- Comma separated values: @foo,bar@.
339+ CollectionCSV :: CollectionFormat t
347− = CollectionCSV -- ^ Comma separated values: @foo,bar@.
340+ -- Space separated values: @foo bar@.
341+ CollectionSSV :: CollectionFormat t
348− | CollectionSSV -- ^ Space separated values: @foo bar@.
342+ -- Tab separated values: @foo\\tbar@.
343+ CollectionTSV :: CollectionFormat t
349− | CollectionTSV -- ^ Tab separated values: @foo\\tbar@.
344+ -- Pipe separated values: @foo|bar@.
350− | CollectionPipes -- ^ Pipe separated values: @foo|bar@.
345+ CollectionPipes :: CollectionFormat t
351− | CollectionMulti -- ^ Corresponds to multiple parameter instances
346+ -- Corresponds to multiple parameter instances
352− -- instead of multiple values for a single instance @foo=bar&foo=baz@.
347+ -- instead of multiple values for a single instance @foo=bar&foo=baz@.
353− -- This is valid only for parameters in @'ParameterQuery'@ or @'ParameterFormData'@.
348+ -- This is valid only for parameters in @'ParamQuery'@ or @'ParamFormData'@.
354− deriving (Eq, Show)
349+ CollectionMulti :: CollectionFormat Param
356−data ItemsType
351+deriving instance Eq (CollectionFormat t)
372− deriving (Eq, Show)
352+deriving instance Show (CollectionFormat t)
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@.
382type ParamName = Text
354type ParamName = Text
384data Schema = Schema
356data Schema = Schema
385− { _schemaType :: SchemaType
386− , _schemaFormat :: Maybe Format
387− , _schemaTitle :: Maybe Text
357+ { _schemaTitle :: Maybe Text
388 , _schemaDescription :: Maybe Text
358 , _schemaDescription :: Maybe Text
389 , _schemaRequired :: [ParamName]
359 , _schemaRequired :: [ParamName]
391− , _schemaItems :: Maybe SchemaItems
392 , _schemaAllOf :: Maybe [Schema]
361 , _schemaAllOf :: Maybe [Schema]
393 , _schemaProperties :: HashMap Text (Referenced Schema)
362 , _schemaProperties :: HashMap Text (Referenced Schema)
394 , _schemaAdditionalProperties :: Maybe Schema
363 , _schemaAdditionalProperties :: Maybe Schema
@@ -402,7 +371,7 @@ data Schema = Schema
402 , _schemaMaxProperties :: Maybe Integer
371 , _schemaMaxProperties :: Maybe Integer
403 , _schemaMinProperties :: Maybe Integer
372 , _schemaMinProperties :: Maybe Integer
405− , _schemaSchemaCommon :: SchemaCommon
374+ , _schemaParamSchema :: ParamSchema Schema SchemaItems
406 } deriving (Eq, Show, Generic)
375 } deriving (Eq, Show, Generic)
408data SchemaItems
377data SchemaItems
@@ -410,26 +379,29 @@ data SchemaItems
410 | SchemaItemsArray [Referenced Schema]
379 | SchemaItemsArray [Referenced Schema]
411 deriving (Eq, Show)
380 deriving (Eq, Show)
413−data SchemaCommon = SchemaCommon
382+data ParamSchema t items = ParamSchema
414 { -- | Declares the value of the parameter that the server will use if none is provided,
383 { -- | Declares the value of the parameter that the server will use if none is provided,
415 -- for example a @"count"@ to control the number of results per page might default to @100@
384 -- for example a @"count"@ to control the number of results per page might default to @100@
416 -- if not supplied by the client in the request.
385 -- if not supplied by the client in the request.
417 -- (Note: "default" has no meaning for required parameters.)
386 -- (Note: "default" has no meaning for required parameters.)
418 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
387 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
419− _schemaCommonDefault :: Maybe Value
388+ _paramSchemaDefault :: Maybe Value
421− , _schemaCommonMaximum :: Maybe Scientific
390+ , _paramSchemaType :: SwaggerType t
422− , _schemaCommonExclusiveMaximum :: Maybe Bool
391+ , _paramSchemaFormat :: Maybe Format
392+ , _paramSchemaItems :: Maybe items
393+ , _paramSchemaMaximum :: Maybe Scientific
394+ , _paramSchemaExclusiveMaximum :: Maybe Bool
423− , _schemaCommonMinimum :: Maybe Scientific
395+ , _paramSchemaMinimum :: Maybe Scientific
424− , _schemaCommonExclusiveMinimum :: Maybe Bool
396+ , _paramSchemaExclusiveMinimum :: Maybe Bool
425− , _schemaCommonMaxLength :: Maybe Integer
397+ , _paramSchemaMaxLength :: Maybe Integer
426− , _schemaCommonMinLength :: Maybe Integer
398+ , _paramSchemaMinLength :: Maybe Integer
427− , _schemaCommonPattern :: Maybe Text
399+ , _paramSchemaPattern :: Maybe Text
428− , _schemaCommonMaxItems :: Maybe Integer
400+ , _paramSchemaMaxItems :: Maybe Integer
429− , _schemaCommonMinItems :: Maybe Integer
401+ , _paramSchemaMinItems :: Maybe Integer
430− , _schemaCommonUniqueItems :: Maybe Bool
402+ , _paramSchemaUniqueItems :: Maybe Bool
431− , _schemaCommonEnum :: Maybe [Value]
403+ , _paramSchemaEnum :: Maybe [Value]
432− , _schemaCommonMultipleOf :: Maybe Scientific
404+ , _paramSchemaMultipleOf :: Maybe Scientific
433 } deriving (Eq, Show, Generic)
405 } deriving (Eq, Show, Generic)
435data Xml = Xml
407data Xml = Xml
@@ -461,21 +433,11 @@ data Xml = Xml
461 } deriving (Eq, Show, Generic)
433 } deriving (Eq, Show, Generic)
463data Items = Items
435data Items = Items
464− { -- | The internal type of the array.
465− _itemsType :: ItemsType
467− -- | The extending format for the previously mentioned type.
468− , _itemsFormat :: Maybe Format
470− -- | __Required if type is @'ItemsArray'@.__
471− -- Describes the type of items in the array.
472− , _itemsItems :: Maybe Items
474− -- | Determines the format of the array if type array is used.
436+ { -- | Determines the format of the array if type array is used.
475 -- Default value is @'ItemsCollectionCSV'@.
437 -- Default value is @'ItemsCollectionCSV'@.
476− , _itemsCollectionFormat :: Maybe ItemsCollectionFormat
438+ _itemsCollectionFormat :: Maybe (CollectionFormat Items)
478− , _itemsCommon :: SchemaCommon
440+ , _itemsParamSchema :: ParamSchema Items Items
479 } deriving (Eq, Show, Generic)
441 } deriving (Eq, Show, Generic)
481-- | A container for the expected responses of an operation.
443-- | A container for the expected responses of an operation.
@@ -521,21 +483,11 @@ data Header = Header
521 { -- | A short description of the header.
483 { -- | A short description of the header.
522 _headerDescription :: Maybe Text
484 _headerDescription :: Maybe Text
524− -- | The type of the object.
525− , _headerType :: ItemsType
527− -- | The extending format for the previously mentioned type. See Data Type Formats for further details.
528− , _headerFormat :: Maybe Format
530− -- | __Required if type is @'ItemsArray'@__.
531− -- Describes the type of items in the array.
532− , _headerItems :: Maybe Items
534 -- | Determines the format of the array if type array is used.
486 -- | Determines the format of the array if type array is used.
535 -- Default value is @'ItemsCollectionCSV'@.
487 -- Default value is @'ItemsCollectionCSV'@.
536− , _headerCollectionFormat :: Maybe ItemsCollectionFormat
488+ , _headerCollectionFormat :: Maybe (CollectionFormat Items)
538− , _headerCommon :: SchemaCommon
490+ , _headerParamSchema :: ParamSchema Header Items
539 } deriving (Eq, Show, Generic)
491 } deriving (Eq, Show, Generic)
541data Example = Example { getExample :: Map MediaType Value }
493data Example = Example { getExample :: Map MediaType Value }
@@ -657,15 +609,15 @@ instance Monoid Schema where
657 mempty = genericMempty
609 mempty = genericMempty
658 mappend = genericMappend
610 mappend = genericMappend
660−instance Monoid SchemaCommon where
612+instance Monoid (ParamSchema t i) where
661 mempty = genericMempty
613 mempty = genericMempty
662 mappend = genericMappend
614 mappend = genericMappend
664−instance Monoid Parameter where
616+instance Monoid Param where
665 mempty = genericMempty
617 mempty = genericMempty
666 mappend = genericMappend
618 mappend = genericMappend
668−instance Monoid ParameterOtherSchema where
620+instance Monoid ParamOtherSchema where
669 mempty = genericMempty
621 mempty = genericMempty
670 mappend = genericMappend
622 mappend = genericMappend
@@ -693,9 +645,9 @@ instance SwaggerMonoid Info
693instance SwaggerMonoid Paths
645instance SwaggerMonoid Paths
694instance SwaggerMonoid PathItem
646instance SwaggerMonoid PathItem
695instance SwaggerMonoid Schema
647instance SwaggerMonoid Schema
696−instance SwaggerMonoid SchemaCommon
648+instance SwaggerMonoid (ParamSchema t i)
697−instance SwaggerMonoid Parameter
649+instance SwaggerMonoid Param
698−instance SwaggerMonoid ParameterOtherSchema
650+instance SwaggerMonoid ParamOtherSchema
699instance SwaggerMonoid Responses
651instance SwaggerMonoid Responses
700instance SwaggerMonoid Response
652instance SwaggerMonoid Response
701instance SwaggerMonoid ExternalDocs
653instance SwaggerMonoid ExternalDocs
@@ -704,16 +656,12 @@ instance SwaggerMonoid Operation
704instance SwaggerMonoid MimeList
656instance SwaggerMonoid MimeList
705deriving instance SwaggerMonoid URL
657deriving instance SwaggerMonoid URL
707−instance SwaggerMonoid SchemaType where
659+instance SwaggerMonoid (SwaggerType t) where
708− swaggerMempty = SchemaNull
709− swaggerMappend _ y = y
711−instance SwaggerMonoid ParameterType where
712− swaggerMempty = ParamString
660+ swaggerMempty = SwaggerString
713 swaggerMappend _ y = y
661 swaggerMappend _ y = y
715−instance SwaggerMonoid ParameterLocation where
663+instance SwaggerMonoid ParamLocation where
716− swaggerMempty = ParameterQuery
664+ swaggerMempty = ParamQuery
717 swaggerMappend _ y = y
665 swaggerMappend _ y = y
719instance SwaggerMonoid (HashMap Text Schema) where
667instance SwaggerMonoid (HashMap Text Schema) where
@@ -729,7 +677,7 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
729 swaggerMappend (Inline x) (Inline y) = Inline (x <> y)
677 swaggerMappend (Inline x) (Inline y) = Inline (x <> y)
730 swaggerMappend _ y = y
678 swaggerMappend _ y = y
732−instance SwaggerMonoid (HashMap Text Parameter) where
680+instance SwaggerMonoid (HashMap Text Param) where
733 swaggerMempty = HashMap.empty
681 swaggerMempty = HashMap.empty
734 swaggerMappend = HashMap.unionWith mappend
682 swaggerMappend = HashMap.unionWith mappend
@@ -753,28 +701,22 @@ instance SwaggerMonoid (HashMap HttpStatusCode (Referenced Response)) where
753 swaggerMempty = HashMap.empty
701 swaggerMempty = HashMap.empty
754 swaggerMappend = flip HashMap.union
702 swaggerMappend = flip HashMap.union
756−instance SwaggerMonoid ParameterSchema where
704+instance SwaggerMonoid ParamAnySchema where
757− swaggerMempty = ParameterOther swaggerMempty
705+ swaggerMempty = ParamOther swaggerMempty
758− swaggerMappend (ParameterBody x) (ParameterBody y) = ParameterBody (swaggerMappend x y)
706+ swaggerMappend (ParamBody x) (ParamBody y) = ParamBody (swaggerMappend x y)
759− swaggerMappend (ParameterOther x) (ParameterOther y) = ParameterOther (swaggerMappend x y)
707+ swaggerMappend (ParamOther x) (ParamOther y) = ParamOther (swaggerMappend x y)
760 swaggerMappend _ y = y
708 swaggerMappend _ y = y
762-- =======================================================================
710-- =======================================================================
763-- TH derived ToJSON and FromJSON instances
711-- TH derived ToJSON and FromJSON instances
764-- =======================================================================
712-- =======================================================================
766−deriveJSON (jsonPrefix "Parameter") ''ParameterLocation
714+deriveJSON (jsonPrefix "Param") ''ParamLocation
767−deriveJSON (jsonPrefix "Param") ''ParameterType
768deriveJSON' ''Info
715deriveJSON' ''Info
769deriveJSON' ''Contact
716deriveJSON' ''Contact
770deriveJSON' ''License
717deriveJSON' ''License
771−deriveJSON (jsonPrefix "Schema") ''SchemaType
772−deriveJSON (jsonPrefix "Items") ''ItemsType
773−deriveJSON (jsonPrefix "ItemsCollection") ''ItemsCollectionFormat
774−deriveJSON (jsonPrefix "Collection") ''CollectionFormat
775deriveJSON (jsonPrefix "ApiKey") ''ApiKeyLocation
718deriveJSON (jsonPrefix "ApiKey") ''ApiKeyLocation
776deriveJSON (jsonPrefix "apiKey") ''ApiKeyParams
719deriveJSON (jsonPrefix "apiKey") ''ApiKeyParams
777−deriveJSON' ''SchemaCommon
778deriveJSONDefault ''Scheme
720deriveJSONDefault ''Scheme
779deriveJSON' ''Tag
721deriveJSON' ''Tag
780deriveJSON' ''ExternalDocs
722deriveJSON' ''ExternalDocs
@@ -826,13 +768,13 @@ instance ToJSON SecurityScheme where
826 toJSON = genericToJSONWithSub "type" (jsonPrefix "securityScheme")
768 toJSON = genericToJSONWithSub "type" (jsonPrefix "securityScheme")
828instance ToJSON Schema where
770instance ToJSON Schema where
829− toJSON = genericToJSONWithSub "schemaCommon" (jsonPrefix "schema")
771+ toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "schema")
831instance ToJSON Header where
773instance ToJSON Header where
832− toJSON = genericToJSONWithSub "common" (jsonPrefix "header")
774+ toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "header")
834instance ToJSON Items where
776instance ToJSON Items where
835− toJSON = genericToJSONWithSub "common" (jsonPrefix "items")
777+ toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "items")
837instance ToJSON Host where
779instance ToJSON Host where
838 toJSON (Host host mport) = toJSON $
780 toJSON (Host host mport) = toJSON $
@@ -846,15 +788,15 @@ instance ToJSON Paths where
846instance ToJSON MimeList where
788instance ToJSON MimeList where
847 toJSON (MimeList xs) = toJSON (map show xs)
789 toJSON (MimeList xs) = toJSON (map show xs)
849−instance ToJSON Parameter where
791+instance ToJSON Param where
850− toJSON = genericToJSONWithSub "schema" (jsonPrefix "parameter")
792+ toJSON = genericToJSONWithSub "schema" (jsonPrefix "param")
852−instance ToJSON ParameterSchema where
794+instance ToJSON ParamAnySchema where
853− toJSON (ParameterBody s) = object [ "in" .= ("body" :: Text), "schema" .= s ]
795+ toJSON (ParamBody s) = object [ "in" .= ("body" :: Text), "schema" .= s ]
854− toJSON (ParameterOther s) = toJSON s
796+ toJSON (ParamOther s) = toJSON s
856−instance ToJSON ParameterOtherSchema where
798+instance ToJSON ParamOtherSchema where
857− toJSON = genericToJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
799+ toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
859instance ToJSON SchemaItems where
801instance ToJSON SchemaItems where
860 toJSON (SchemaItemsObject x) = toJSON x
802 toJSON (SchemaItemsObject x) = toJSON x
@@ -873,6 +815,26 @@ instance ToJSON a => ToJSON (Referenced a) where
873 toJSON (Ref ref) = toJSON ref
815 toJSON (Ref ref) = toJSON ref
874 toJSON (Inline x) = toJSON x
816 toJSON (Inline x) = toJSON x
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"
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"
835+instance ToJSON i => ToJSON (ParamSchema t i) where
836+ toJSON = genericToJSON (jsonPrefix "paramSchema")
876-- =======================================================================
838-- =======================================================================
877-- Manual FromJSON instances
839-- Manual FromJSON instances
878-- =======================================================================
840-- =======================================================================
@@ -913,7 +875,7 @@ instance FromJSON Swagger where
913 , "security" .= ([] :: [SecurityRequirement])
875 , "security" .= ([] :: [SecurityRequirement])
914 , "tags" .= ([] :: [Tag])
876 , "tags" .= ([] :: [Tag])
915 , "definitions" .= (mempty :: HashMap Text Schema)
877 , "definitions" .= (mempty :: HashMap Text Schema)
916− , "parameters" .= (mempty :: HashMap Text Parameter)
878+ , "parameters" .= (mempty :: HashMap Text Param)
917 , "responses" .= (mempty :: HashMap Text Response)
879 , "responses" .= (mempty :: HashMap Text Response)
918 , "securityDefinitions" .= (mempty :: HashMap Text SecurityScheme)
880 , "securityDefinitions" .= (mempty :: HashMap Text SecurityScheme)
@@ -923,15 +885,15 @@ instance FromJSON SecurityScheme where
923 parseJSON = genericParseJSONWithSub "type" (jsonPrefix "securityScheme")
885 parseJSON = genericParseJSONWithSub "type" (jsonPrefix "securityScheme")
925instance FromJSON Schema where
887instance FromJSON Schema where
926− parseJSON = genericParseJSONWithSub "schemaCommon" (jsonPrefix "schema")
888+ parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "schema")
927 `withDefaults` [ "properties" .= (mempty :: HashMap Text Schema)
889 `withDefaults` [ "properties" .= (mempty :: HashMap Text Schema)
928 , "required" .= ([] :: [ParamName]) ]
890 , "required" .= ([] :: [ParamName]) ]
930instance FromJSON Header where
892instance FromJSON Header where
931− parseJSON = genericParseJSONWithSub "common" (jsonPrefix "header")
893+ parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "header")
933instance FromJSON Items where
895instance FromJSON Items where
934− parseJSON = genericParseJSONWithSub "common" (jsonPrefix "items")
896+ parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "items")
936instance FromJSON Host where
898instance FromJSON Host where
937 parseJSON (String s) =
899 parseJSON (String s) =
@@ -949,21 +911,21 @@ instance FromJSON Paths where
949instance FromJSON MimeList where
911instance FromJSON MimeList where
950 parseJSON js = (MimeList . map fromString) <$> parseJSON js
912 parseJSON js = (MimeList . map fromString) <$> parseJSON js
952−instance FromJSON Parameter where
914+instance FromJSON Param where
953− parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "parameter")
915+ parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "param")
955−instance FromJSON ParameterSchema where
917+instance FromJSON ParamAnySchema where
956 parseJSON js@(Object o) = do
918 parseJSON js@(Object o) = do
957 (i :: Text) <- o .: "in"
919 (i :: Text) <- o .: "in"
958 case i of
920 case i of
959 "body" -> do
921 "body" -> do
960 schema <- o .: "schema"
922 schema <- o .: "schema"
961− ParameterBody <$> parseJSON schema
923+ ParamBody <$> parseJSON schema
962− _ -> ParameterOther <$> parseJSON js
924+ _ -> ParamOther <$> parseJSON js
963 parseJSON _ = empty
925 parseJSON _ = empty
965−instance FromJSON ParameterOtherSchema where
927+instance FromJSON ParamOtherSchema where
966− parseJSON = genericParseJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
928+ parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
968instance FromJSON SchemaItems where
930instance FromJSON SchemaItems where
969 parseJSON js@(Object _) = SchemaItemsObject <$> parseJSON js
931 parseJSON js@(Object _) = SchemaItemsObject <$> parseJSON js
@@ -991,7 +953,7 @@ instance FromJSON Operation where
992instance FromJSON PathItem where
954instance FromJSON PathItem where
993 parseJSON = genericParseJSON (jsonPrefix "pathItem")
955 parseJSON = genericParseJSON (jsonPrefix "pathItem")
994− `withDefaults` [ "parameters" .= ([] :: [Parameter]) ]
956+ `withDefaults` [ "parameters" .= ([] :: [Param]) ]
996instance FromJSON Reference where
958instance FromJSON Reference where
997 parseJSON (Object o) = Reference <$> o .: "$ref"
959 parseJSON (Object o) = Reference <$> o .: "$ref"
@@ -1005,3 +967,23 @@ instance FromJSON a => FromJSON (Referenced a) where
1005instance FromJSON Xml where
967instance FromJSON Xml where
1006 parseJSON = genericParseJSON (jsonPrefix "xml")
968 parseJSON = genericParseJSON (jsonPrefix "xml")
970+instance FromJSON (SwaggerType Schema) where
971+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray, SwaggerNull, SwaggerObject]
973+instance FromJSON (SwaggerType ParamOtherSchema) where
974+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray, SwaggerFile]
976+instance {-# OVERLAPPABLE #-} FromJSON (SwaggerType t) where
977+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray]
979+instance FromJSON (CollectionFormat Param) where
980+ parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes, CollectionMulti]
982+instance FromJSON (CollectionFormat Items) where
983+ parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
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")