git.iko.soy/typeable/swagger2
on master help sign in
Rename Parameter to Param
commit98a59470c7438f5035d12d55f8d5ed70c089d15f authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateMon 7 Dec 2015, 22:33 (11 years ago) parentce3fe0a
4 files changed+111−111
src/Data/Swagger.hs+5−5 src/Data/Swagger/Internal.hs+59−59 src/Data/Swagger/Lens.hs+5−5 test/Data/SwaggerSpec.hs+42−42
src/Data/Swagger.hs+5−5
@@ -27,7 +27,7 @@ module Data.Swagger (
2727 Operation(..),
2828
2929 -- * Types and formats
30− ParameterType(..),
30+ ParamType(..),
3131 ItemsType(..),
3232 SchemaType(..),
3333 Format,
@@ -35,10 +35,10 @@ module Data.Swagger (
3535 ItemsCollectionFormat(..),
3636
3737 -- * Parameters
38− Parameter(..),
39− ParameterSchema(..),
40− ParameterOtherSchema(..),
41− ParameterLocation(..),
38+ Param(..),
39+ ParamSchema(..),
40+ ParamOtherSchema(..),
41+ ParamLocation(..),
4242 ParamName,
4343 Items(..),
4444 Header(..),
src/Data/Swagger/Internal.hs+59−59
@@ -64,7 +64,7 @@ data Swagger = Swagger
6464
6565 -- | An object to hold parameters that can be used across operations.
6666 -- This property does not define global parameters for all operations.
67− , _parameters :: HashMap Text Parameter
67+ , _parameters :: HashMap Text Param
6868
6969 -- | An object to hold responses that can be used across operations.
7070 -- This property does not define global responses for all operations.
@@ -187,7 +187,7 @@ data PathItem = PathItem
187187 -- These parameters can be overridden at the operation level, but cannot be removed there.
188188 -- The list MUST NOT include duplicated parameters.
189189 -- A unique parameter is defined by a combination of a name and location.
190− , _pathItemParameters :: [Referenced Parameter]
190+ , _pathItemParameters :: [Referenced Param]
191191 } deriving (Eq, Show, Generic)
192192
193193-- | Describes a single API operation on a path.
@@ -228,7 +228,7 @@ data Operation = Operation
228228 -- the new definition will override it, but can never remove it.
229229 -- The list MUST NOT include duplicated parameters.
230230 -- A unique parameter is defined by a combination of a name and location.
231− , _operationParameters :: [Referenced Parameter]
231+ , _operationParameters :: [Referenced Param]
232232
233233 -- | The list of possible responses as they are returned from executing this operation.
234234 , _operationResponses :: Responses
@@ -255,63 +255,63 @@ newtype MimeList = MimeList { getMimeList :: [MediaType] }
255255
256256-- | Describes a single operation parameter.
257257-- A unique parameter is defined by a combination of a name and location.
258−data Parameter = Parameter
258+data Param = Param
259259 { -- | The name of the parameter.
260260 -- Parameter names are case sensitive.
261− _parameterName :: Text
261+ _paramName :: Text
262262
263263 -- | A brief description of the parameter.
264264 -- This could contain examples of use.
265265 -- GFM syntax can be used for rich text representation.
266− , _parameterDescription :: Maybe Text
266+ , _paramDescription :: Maybe Text
267267
268268 -- | Determines whether this parameter is mandatory.
269269 -- If the parameter is in "path", this property is required and its value MUST be true.
270270 -- Otherwise, the property MAY be included and its default value is @False@.
271− , _parameterRequired :: Maybe Bool
271+ , _paramRequired :: Maybe Bool
272272
273273 -- | Parameter schema.
274− , _parameterSchema :: ParameterSchema
274+ , _paramSchema :: ParamSchema
275275 } deriving (Eq, Show, Generic)
276276
277−data ParameterSchema
278− = ParameterBody (Referenced Schema)
279− | ParameterOther ParameterOtherSchema
277+data ParamSchema
278+ = ParamBody (Referenced Schema)
279+ | ParamOther ParamOtherSchema
280280 deriving (Eq, Show)
281281
282−data ParameterOtherSchema = ParameterOtherSchema
282+data ParamOtherSchema = ParamOtherSchema
283283 { -- | The location of the parameter.
284− _parameterOtherSchemaIn :: ParameterLocation
284+ _paramOtherSchemaIn :: ParamLocation
285285
286286 -- | The type of the parameter.
287287 -- Since the parameter is not located at the request body,
288288 -- it is limited to simple types (that is, not an object).
289289 -- If type is @'ParamFile'@, the @consumes@ MUST be either
290290 -- "multipart/form-data" or " application/x-www-form-urlencoded"
291− -- and the parameter MUST be in @'ParameterFormData'@.
292− , _parameterOtherSchemaType :: ParameterType
291+ -- and the parameter MUST be in @'ParamFormData'@.
292+ , _paramOtherSchemaType :: ParamType
293293
294294 -- | The extending format for the previously mentioned type.
295− , _parameterOtherSchemaFormat :: Maybe Format
295+ , _paramOtherSchemaFormat :: Maybe Format
296296
297297 -- | Sets the ability to pass empty-valued parameters.
298− -- This is valid only for either @'ParameterQuery'@ or @'ParameterFormData'@
298+ -- This is valid only for either @'ParamQuery'@ or @'ParamFormData'@
299299 -- and allows you to send a parameter with a name only or an empty value.
300300 -- Default value is @False@.
301− , _parameterOtherSchemaAllowEmptyValue :: Maybe Bool
301+ , _paramOtherSchemaAllowEmptyValue :: Maybe Bool
302302
303303 -- | __Required if type is @'ParamArray'@__.
304304 -- Describes the type of items in the array.
305− , _parameterOtherSchemaItems :: Maybe Items
305+ , _paramOtherSchemaItems :: Maybe Items
306306
307307 -- | Determines the format of the array if @'ParamArray'@ is used.
308308 -- Default value is csv.
309− , _parameterOtherSchemaCollectionFormat :: Maybe CollectionFormat
309+ , _paramOtherSchemaCollectionFormat :: Maybe CollectionFormat
310310
311− , _parameterOtherSchemaCommon :: SchemaCommon
311+ , _paramOtherSchemaCommon :: SchemaCommon
312312 } deriving (Eq, Show, Generic)
313313
314−data ParameterType
314+data ParamType
315315 = ParamString
316316 | ParamNumber
317317 | ParamInteger
@@ -320,16 +320,16 @@ data ParameterType
320320 | ParamFile
321321 deriving (Eq, Show)
322322
323−data ParameterLocation
323+data ParamLocation
324324 = -- | Parameters that are appended to the URL.
325325 -- For example, in @/items?id=###@, the query parameter is @id@.
326− ParameterQuery
326+ ParamQuery
327327 -- | Custom headers that are expected as part of the request.
328− | ParameterHeader
328+ | ParamHeader
329329 -- | Used together with Path Templating, where the parameter value is actually part of the operation's URL.
330330 -- This does not include the host or base path of the API.
331331 -- For example, in @/items/{itemId}@, the path parameter is @itemId@.
332− | ParameterPath
332+ | ParamPath
333333 -- | Used to describe the payload of an HTTP request when either @application/x-www-form-urlencoded@
334334 -- or @multipart/form-data@ are used as the content type of the request
335335 -- (in Swagger's definition, the @consumes@ property of an operation).
@@ -337,7 +337,7 @@ data ParameterLocation
337337 -- Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation.
338338 -- Form parameters have a different format based on the content-type used
339339 -- (for further details, consult <http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4>).
340− | ParameterFormData
340+ | ParamFormData
341341 deriving (Eq, Show)
342342
343343type Format = Text
@@ -349,8 +349,8 @@ data CollectionFormat
349349 | CollectionTSV -- ^ Tab separated values: @foo\\tbar@.
350350 | CollectionPipes -- ^ Pipe separated values: @foo|bar@.
351351 | 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'@.
352+ -- instead of multiple values for a single instance @foo=bar&foo=baz@.
353+ -- This is valid only for parameters in @'ParamQuery'@ or @'ParamFormData'@.
354354 deriving (Eq, Show)
355355
356356data ItemsType
@@ -661,11 +661,11 @@ instance Monoid SchemaCommon where
661661 mempty = genericMempty
662662 mappend = genericMappend
663663
664−instance Monoid Parameter where
664+instance Monoid Param where
665665 mempty = genericMempty
666666 mappend = genericMappend
667667
668−instance Monoid ParameterOtherSchema where
668+instance Monoid ParamOtherSchema where
669669 mempty = genericMempty
670670 mappend = genericMappend
671671
@@ -694,8 +694,8 @@ instance SwaggerMonoid Paths
694694instance SwaggerMonoid PathItem
695695instance SwaggerMonoid Schema
696696instance SwaggerMonoid SchemaCommon
697−instance SwaggerMonoid Parameter
698−instance SwaggerMonoid ParameterOtherSchema
697+instance SwaggerMonoid Param
698+instance SwaggerMonoid ParamOtherSchema
699699instance SwaggerMonoid Responses
700700instance SwaggerMonoid Response
701701instance SwaggerMonoid ExternalDocs
@@ -708,12 +708,12 @@ instance SwaggerMonoid SchemaType where
708708 swaggerMempty = SchemaNull
709709 swaggerMappend _ y = y
710710
711−instance SwaggerMonoid ParameterType where
711+instance SwaggerMonoid ParamType where
712712 swaggerMempty = ParamString
713713 swaggerMappend _ y = y
714714
715−instance SwaggerMonoid ParameterLocation where
716− swaggerMempty = ParameterQuery
715+instance SwaggerMonoid ParamLocation where
716+ swaggerMempty = ParamQuery
717717 swaggerMappend _ y = y
718718
719719instance SwaggerMonoid (HashMap Text Schema) where
@@ -729,7 +729,7 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
729729 swaggerMappend (Inline x) (Inline y) = Inline (x <> y)
730730 swaggerMappend _ y = y
731731
732−instance SwaggerMonoid (HashMap Text Parameter) where
732+instance SwaggerMonoid (HashMap Text Param) where
733733 swaggerMempty = HashMap.empty
734734 swaggerMappend = HashMap.unionWith mappend
735735
@@ -753,18 +753,18 @@ instance SwaggerMonoid (HashMap HttpStatusCode (Referenced Response)) where
753753 swaggerMempty = HashMap.empty
754754 swaggerMappend = flip HashMap.union
755755
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)
756+instance SwaggerMonoid ParamSchema where
757+ swaggerMempty = ParamOther swaggerMempty
758+ swaggerMappend (ParamBody x) (ParamBody y) = ParamBody (swaggerMappend x y)
759+ swaggerMappend (ParamOther x) (ParamOther y) = ParamOther (swaggerMappend x y)
760760 swaggerMappend _ y = y
761761
762762-- =======================================================================
763763-- TH derived ToJSON and FromJSON instances
764764-- =======================================================================
765765
766−deriveJSON (jsonPrefix "Parameter") ''ParameterLocation
767−deriveJSON (jsonPrefix "Param") ''ParameterType
766+deriveJSON (jsonPrefix "Param") ''ParamLocation
767+deriveJSON (jsonPrefix "Param") ''ParamType
768768deriveJSON' ''Info
769769deriveJSON' ''Contact
770770deriveJSON' ''License
@@ -846,15 +846,15 @@ instance ToJSON Paths where
846846instance ToJSON MimeList where
847847 toJSON (MimeList xs) = toJSON (map show xs)
848848
849−instance ToJSON Parameter where
850− toJSON = genericToJSONWithSub "schema" (jsonPrefix "parameter")
849+instance ToJSON Param where
850+ toJSON = genericToJSONWithSub "schema" (jsonPrefix "param")
851851
852−instance ToJSON ParameterSchema where
853− toJSON (ParameterBody s) = object [ "in" .= ("body" :: Text), "schema" .= s ]
854− toJSON (ParameterOther s) = toJSON s
852+instance ToJSON ParamSchema where
853+ toJSON (ParamBody s) = object [ "in" .= ("body" :: Text), "schema" .= s ]
854+ toJSON (ParamOther s) = toJSON s
855855
856−instance ToJSON ParameterOtherSchema where
857− toJSON = genericToJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
856+instance ToJSON ParamOtherSchema where
857+ toJSON = genericToJSONWithSub "common" (jsonPrefix "paramOtherSchema")
858858
859859instance ToJSON SchemaItems where
860860 toJSON (SchemaItemsObject x) = toJSON x
@@ -913,7 +913,7 @@ instance FromJSON Swagger where
913913 , "security" .= ([] :: [SecurityRequirement])
914914 , "tags" .= ([] :: [Tag])
915915 , "definitions" .= (mempty :: HashMap Text Schema)
916− , "parameters" .= (mempty :: HashMap Text Parameter)
916+ , "parameters" .= (mempty :: HashMap Text Param)
917917 , "responses" .= (mempty :: HashMap Text Response)
918918 , "securityDefinitions" .= (mempty :: HashMap Text SecurityScheme)
919919 ] ) js
@@ -949,21 +949,21 @@ instance FromJSON Paths where
949949instance FromJSON MimeList where
950950 parseJSON js = (MimeList . map fromString) <$> parseJSON js
951951
952−instance FromJSON Parameter where
953− parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "parameter")
952+instance FromJSON Param where
953+ parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "param")
954954
955−instance FromJSON ParameterSchema where
955+instance FromJSON ParamSchema where
956956 parseJSON js@(Object o) = do
957957 (i :: Text) <- o .: "in"
958958 case i of
959959 "body" -> do
960960 schema <- o .: "schema"
961− ParameterBody <$> parseJSON schema
962− _ -> ParameterOther <$> parseJSON js
961+ ParamBody <$> parseJSON schema
962+ _ -> ParamOther <$> parseJSON js
963963 parseJSON _ = empty
964964
965−instance FromJSON ParameterOtherSchema where
966− parseJSON = genericParseJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
965+instance FromJSON ParamOtherSchema where
966+ parseJSON = genericParseJSONWithSub "common" (jsonPrefix "paramOtherSchema")
967967
968968instance FromJSON SchemaItems where
969969 parseJSON js@(Object _) = SchemaItemsObject <$> parseJSON js
@@ -991,7 +991,7 @@ instance FromJSON Operation where
991991
992992instance FromJSON PathItem where
993993 parseJSON = genericParseJSON (jsonPrefix "pathItem")
994− `withDefaults` [ "parameters" .= ([] :: [Parameter]) ]
994+ `withDefaults` [ "parameters" .= ([] :: [Param]) ]
995995
996996instance FromJSON Reference where
997997 parseJSON (Object o) = Reference <$> o .: "$ref"
src/Data/Swagger/Lens.hs+5−5
@@ -23,9 +23,9 @@ makeLenses ''Paths
2323makeLenses ''PathItem
2424makeLenses ''Tag
2525makeLenses ''Operation
26−makeLenses ''Parameter
27−makePrisms ''ParameterSchema
28−makeLenses ''ParameterOtherSchema
26+makeLenses ''Param
27+makePrisms ''ParamSchema
28+makeLenses ''ParamOtherSchema
2929makeLenses ''Items
3030makeLenses ''Header
3131makeLenses ''Schema
@@ -51,7 +51,7 @@ instance HasDescription Response Text where description = responseDescript
5151instance HasDescription Info (Maybe Text) where description = infoDescription
5252instance HasDescription Tag (Maybe Text) where description = tagDescription
5353instance HasDescription Operation (Maybe Text) where description = operationDescription
54−instance HasDescription Parameter (Maybe Text) where description = parameterDescription
54+instance HasDescription Param (Maybe Text) where description = paramDescription
5555instance HasDescription Header (Maybe Text) where description = headerDescription
5656instance HasDescription Schema (Maybe Text) where description = schemaDescription
5757instance HasDescription SecurityScheme (Maybe Text) where description = securitySchemeDescription
@@ -61,7 +61,7 @@ class HasSchemaCommon s where
6161 schemaCommon :: Lens' s SchemaCommon
6262
6363instance HasSchemaCommon Schema where schemaCommon = schemaSchemaCommon
64−instance HasSchemaCommon ParameterOtherSchema where schemaCommon = parameterOtherSchemaCommon
64+instance HasSchemaCommon ParamOtherSchema where schemaCommon = paramOtherSchemaCommon
6565instance HasSchemaCommon Items where schemaCommon = itemsCommon
6666instance HasSchemaCommon Header where schemaCommon = headerCommon
6767instance HasSchemaCommon SchemaCommon where schemaCommon = id
test/Data/SwaggerSpec.hs+42−42
@@ -25,7 +25,7 @@ spec = do
2525 context "Model with Map/Dictionary Properties" $ schemaModelDictExample <~> schemaModelDictExampleJSON
2626 context "Model with Example" $ schemaWithExampleExample <~> schemaWithExampleExampleJSON
2727 describe "Definitions Object" $ definitionsExample <~> definitionsExampleJSON
28− describe "Parameters Definition Object" $ parametersDefinitionExample <~> parametersDefinitionExampleJSON
28+ describe "Parameters Definition Object" $ paramsDefinitionExample <~> paramsDefinitionExampleJSON
2929 describe "Responses Definition Object" $ responsesDefinitionExample <~> responsesDefinitionExampleJSON
3030 describe "Security Definitions Object" $ securityDefinitionsExample <~> securityDefinitionsExampleJSON
3131 describe "Swagger Object" $ do
@@ -131,26 +131,26 @@ operationExample = mempty
131131 , (405, Inline mempty { _responseDescription = "Invalid input" }) ] }
132132
133133 params = map Inline
134− [ Parameter
135− { _parameterName = "petId"
136− , _parameterDescription = Just "ID of pet that needs to be updated"
137− , _parameterRequired = Just True
138− , _parameterSchema = ParameterOther (stringSchema ParameterPath) }
139− , Parameter
140− { _parameterName = "name"
141− , _parameterDescription = Just "Updated name of the pet"
142− , _parameterRequired = Just False
143− , _parameterSchema = ParameterOther (stringSchema ParameterFormData) }
144− , Parameter
145− { _parameterName = "status"
146− , _parameterDescription = Just "Updated status of the pet"
147− , _parameterRequired = Just False
148− , _parameterSchema = ParameterOther (stringSchema ParameterFormData) }
134+ [ Param
135+ { _paramName = "petId"
136+ , _paramDescription = Just "ID of pet that needs to be updated"
137+ , _paramRequired = Just True
138+ , _paramSchema = ParamOther (stringSchema ParamPath) }
139+ , Param
140+ { _paramName = "name"
141+ , _paramDescription = Just "Updated name of the pet"
142+ , _paramRequired = Just False
143+ , _paramSchema = ParamOther (stringSchema ParamFormData) }
144+ , Param
145+ { _paramName = "status"
146+ , _paramDescription = Just "Updated status of the pet"
147+ , _paramRequired = Just False
148+ , _paramSchema = ParamOther (stringSchema ParamFormData) }
149149 ]
150150
151151 stringSchema i = mempty
152− { _parameterOtherSchemaIn = i
153− , _parameterOtherSchemaType = ParamString
152+ { _paramOtherSchemaIn = i
153+ , _paramOtherSchemaType = ParamString
154154 }
155155
156156operationExampleJSON :: Value
@@ -379,27 +379,27 @@ definitionsExampleJSON = [aesonQQ|
379379-- Parameters Definition object
380380-- =======================================================================
381381
382−parametersDefinitionExample :: HashMap Text Parameter
383−parametersDefinitionExample =
382+paramsDefinitionExample :: HashMap Text Param
383+paramsDefinitionExample =
384384 [ ("skipParam", mempty
385− { _parameterName = "skip"
386− , _parameterDescription = Just "number of items to skip"
387− , _parameterRequired = Just True
388− , _parameterSchema = ParameterOther mempty
389− { _parameterOtherSchemaIn = ParameterQuery
390− , _parameterOtherSchemaType = ParamInteger
391− , _parameterOtherSchemaFormat = Just "int32" } })
385+ { _paramName = "skip"
386+ , _paramDescription = Just "number of items to skip"
387+ , _paramRequired = Just True
388+ , _paramSchema = ParamOther mempty
389+ { _paramOtherSchemaIn = ParamQuery
390+ , _paramOtherSchemaType = ParamInteger
391+ , _paramOtherSchemaFormat = Just "int32" } })
392392 , ("limitParam", mempty
393− { _parameterName = "limit"
394− , _parameterDescription = Just "max records to return"
395− , _parameterRequired = Just True
396− , _parameterSchema = ParameterOther mempty
397− { _parameterOtherSchemaIn = ParameterQuery
398− , _parameterOtherSchemaType = ParamInteger
399− , _parameterOtherSchemaFormat = Just "int32" } }) ]
393+ { _paramName = "limit"
394+ , _paramDescription = Just "max records to return"
395+ , _paramRequired = Just True
396+ , _paramSchema = ParamOther mempty
397+ { _paramOtherSchemaIn = ParamQuery
398+ , _paramOtherSchemaType = ParamInteger
399+ , _paramOtherSchemaFormat = Just "int32" } }) ]
400400
401−parametersDefinitionExampleJSON :: Value
402−parametersDefinitionExampleJSON = [aesonQQ|
401+paramsDefinitionExampleJSON :: Value
402+paramsDefinitionExampleJSON = [aesonQQ|
403403{
404404 "skipParam": {
405405 "name": "skip",
@@ -518,12 +518,12 @@ swaggerExample = mempty
518518 , _operationProduces = Just (MimeList [ "application/json" ])
519519 , _operationParameters =
520520 [ Inline mempty
521− { _parameterRequired = Just True
522− , _parameterName = "id"
523− , _parameterDescription = Just "TodoId param"
524− , _parameterSchema = ParameterOther mempty
525− { _parameterOtherSchemaIn = ParameterPath
526− , _parameterOtherSchemaType = ParamString } } ]
521+ { _paramRequired = Just True
522+ , _paramName = "id"
523+ , _paramDescription = Just "TodoId param"
524+ , _paramSchema = ParamOther mempty
525+ { _paramOtherSchemaIn = ParamPath
526+ , _paramOtherSchemaType = ParamString } } ]
527527 , _operationTags = [ "todo" ] } }) ] } }
528528
529529swaggerExampleJSON :: Value