git.iko.soy/typeable/swagger2
on master help sign in
Switch to classy field lenses

- use makeFields for records - remove prefixes even for ParamSchema accessors - Swagger record field names had to gain "swagger" prefix again - also remove Paths as a redundant structure

commit40e22087e89339720a8ad3687e6d7a425c0677bc authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateThu 21 Jan 2016, 15:59 (11 years ago) parenta6d7769
8 files changed+263−259
src/Data/Swagger.hs+11−12 src/Data/Swagger/Internal.hs+18−34 src/Data/Swagger/Internal/ParamSchema.hs+31−31 src/Data/Swagger/Internal/Schema.hs+36−36 src/Data/Swagger/Internal/Utils.hs+22 src/Data/Swagger/Lens.hs+78−79 swagger2.cabal+1 test/Data/SwaggerSpec.hs+66−67
src/Data/Swagger.hs+11−12
@@ -33,8 +33,7 @@ module Data.Swagger (
3333 Contact(..),
3434 License(..),
3535
36− -- ** Paths
37− Paths(..),
36+ -- ** PathItem
3837 PathItem(..),
3938
4039 -- ** Operations
@@ -164,13 +163,13 @@ import Data.Swagger.Internal
164163-- also make it fairly simple to construct/modify any part of the specification:
165164--
166165-- >>> :{
167−-- encode $ mempty & pathsMap .~
168−-- [ ("/user", mempty & pathItemGet ?~ (mempty
169−-- & operationProduces ?~ MimeList ["application/json"]
170−-- & operationResponses .~ (mempty
171−-- & responsesResponses . at 200 ?~ Inline (mempty & responseSchema ?~ Ref (Reference "#/definitions/User")))))]
166+-- encode $ (mempty :: Swagger) & paths .~
167+-- [ ("/user", mempty & get ?~ (mempty
168+-- & produces ?~ MimeList ["application/json"]
169+-- & responses .~ (mempty
170+-- & responses . at 200 ?~ Inline (mempty & schema ?~ Ref (Reference "#/definitions/User")))))]
172171-- :}
173−-- "{\"/user\":{\"get\":{\"responses\":{\"200\":{\"schema\":{\"$ref\":\"#/definitions/#/definitions/User\"},\"description\":\"\"}},\"produces\":[\"application/json\"]}}}"
172+-- "{\"swagger\":\"2.0\",\"info\":{\"version\":\"\",\"title\":\"\"},\"paths\":{\"/user\":{\"get\":{\"responses\":{\"200\":{\"schema\":{\"$ref\":\"#/definitions/#/definitions/User\"},\"description\":\"\"}},\"produces\":[\"application/json\"]}}}}"
174173--
175174-- In the snippet above we declare API paths with a single path @/user@ providing method @GET@
176175-- which produces @application/json@ output and should respond with code @200@ and body specified
@@ -181,10 +180,10 @@ import Data.Swagger.Internal
181180-- and allow them to be used by any type that has a @'ParamSchema'@:
182181--
183182-- >>> :{
184−-- encode $ mempty
185−-- & schemaTitle ?~ "Email"
186−-- & schemaType .~ SwaggerString
187−-- & schemaFormat ?~ "email"
183+-- encode $ (mempty :: Schema)
184+-- & title ?~ "Email"
185+-- & type_ .~ SwaggerString
186+-- & format ?~ "email"
188187-- :}
189188-- "{\"format\":\"email\",\"title\":\"Email\",\"type\":\"string\"}"
190189
src/Data/Swagger/Internal.hs+18−34
@@ -40,61 +40,63 @@ type Definitions = HashMap Text
4040data Swagger = Swagger
4141 { -- | Provides metadata about the API.
4242 -- The metadata can be used by the clients if needed.
43− _info :: Info
43+ _swaggerInfo :: Info
4444
4545 -- | The host (name or ip) serving the API. It MAY include a port.
4646 -- If the host is not included, the host serving the documentation is to be used (including the port).
47− , _host :: Maybe Host
47+ , _swaggerHost :: Maybe Host
4848
4949 -- | The base path on which the API is served, which is relative to the host.
5050 -- If it is not included, the API is served directly under the host.
5151 -- The value MUST start with a leading slash (/).
52− , _basePath :: Maybe FilePath
52+ , _swaggerBasePath :: Maybe FilePath
5353
5454 -- | The transfer protocol of the API.
5555 -- If the schemes is not included, the default scheme to be used is the one used to access the Swagger definition itself.
56− , _schemes :: Maybe [Scheme]
56+ , _swaggerSchemes :: Maybe [Scheme]
5757
5858 -- | A list of MIME types the APIs can consume.
5959 -- This is global to all APIs but can be overridden on specific API calls.
60− , _consumes :: MimeList
60+ , _swaggerConsumes :: MimeList
6161
6262 -- | A list of MIME types the APIs can produce.
6363 -- This is global to all APIs but can be overridden on specific API calls.
64− , _produces :: MimeList
64+ , _swaggerProduces :: MimeList
6565
6666 -- | The available paths and operations for the API.
67− , _paths :: Paths
67+ -- Holds the relative paths to the individual endpoints.
68+ -- The path is appended to the @'basePath'@ in order to construct the full URL.
69+ , _swaggerPaths :: HashMap FilePath PathItem
6870
6971 -- | An object to hold data types produced and consumed by operations.
70− , _definitions :: Definitions Schema
72+ , _swaggerDefinitions :: Definitions Schema
7173
7274 -- | An object to hold parameters that can be used across operations.
7375 -- This property does not define global parameters for all operations.
74− , _parameters :: Definitions Param
76+ , _swaggerParameters :: Definitions Param
7577
7678 -- | An object to hold responses that can be used across operations.
7779 -- This property does not define global responses for all operations.
78− , _responses :: Definitions Response
80+ , _swaggerResponses :: Definitions Response
7981
8082 -- | Security scheme definitions that can be used across the specification.
81− , _securityDefinitions :: Definitions SecurityScheme
83+ , _swaggerSecurityDefinitions :: Definitions SecurityScheme
8284
8385 -- | A declaration of which security schemes are applied for the API as a whole.
8486 -- The list of values describes alternative security schemes that can be used
8587 -- (that is, there is a logical OR between the security requirements).
8688 -- Individual operations can override this definition.
87− , _security :: [SecurityRequirement]
89+ , _swaggerSecurity :: [SecurityRequirement]
8890
8991 -- | A list of tags used by the specification with additional metadata.
9092 -- The order of the tags can be used to reflect on their order by the parsing tools.
9193 -- Not all tags that are used by the Operation Object must be declared.
9294 -- The tags that are not declared may be organized randomly or based on the tools' logic.
9395 -- Each tag name in the list MUST be unique.
94− , _tags :: [Tag]
96+ , _swaggerTags :: [Tag]
9597
9698 -- | Additional external documentation.
97− , _externalDocs :: Maybe ExternalDocs
99+ , _swaggerExternalDocs :: Maybe ExternalDocs
98100 } deriving (Eq, Show, Generic, Data, Typeable)
99101
100102-- | The object provides metadata about the API.
@@ -170,13 +172,6 @@ data Scheme
170172 | Wss
171173 deriving (Eq, Show, Generic, Data, Typeable)
172174
173−-- | The available paths and operations for the API.
174−data Paths = Paths
175− { -- | Holds the relative paths to the individual endpoints.
176− -- The path is appended to the @'basePath'@ in order to construct the full URL.
177− _pathsMap :: HashMap FilePath PathItem
178− } deriving (Eq, Show, Generic, Data, Typeable)
179−
180175-- | Describes the operations available on a single path.
181176-- A @'PathItem'@ may be empty, due to ACL constraints.
182177-- The path itself is still exposed to the documentation viewer
@@ -719,10 +714,6 @@ instance Monoid Info where
719714 mempty = genericMempty
720715 mappend = genericMappend
721716
722−instance Monoid Paths where
723− mempty = genericMempty
724− mappend = genericMappend
725−
726717instance Monoid PathItem where
727718 mempty = genericMempty
728719 mappend = genericMappend
@@ -772,7 +763,6 @@ instance Monoid Example where
772763-- =======================================================================
773764
774765instance SwaggerMonoid Info
775−instance SwaggerMonoid Paths
776766instance SwaggerMonoid PathItem
777767instance SwaggerMonoid Schema
778768instance SwaggerMonoid (ParamSchema t)
@@ -907,7 +897,7 @@ instance ToJSON SecuritySchemeType where
907897 <+> object [ "type" .= ("oauth2" :: Text) ]
908898
909899instance ToJSON Swagger where
910− toJSON = omitEmpties . addVersion . genericToJSON (jsonPrefix "")
900+ toJSON = omitEmpties . addVersion . genericToJSON (jsonPrefix "swagger")
911901 where
912902 addVersion (Object o) = Object (HashMap.insert "swagger" "2.0" o)
913903 addVersion _ = error "impossible"
@@ -937,9 +927,6 @@ instance ToJSON Host where
937927 Nothing -> host
938928 Just port -> host ++ ":" ++ show port
939929
940−instance ToJSON Paths where
941− toJSON (Paths m) = toJSON m
942−
943930instance ToJSON MimeList where
944931 toJSON (MimeList xs) = toJSON (map show xs)
945932
@@ -1037,7 +1024,7 @@ instance FromJSON Swagger where
10371024 parseJSON js@(Object o) = do
10381025 (version :: Text) <- o .: "swagger"
10391026 when (version /= "2.0") empty
1040− (genericParseJSON (jsonPrefix "")
1027+ (genericParseJSON (jsonPrefix "swagger")
10411028 `withDefaults` [ "consumes" .= (mempty :: MimeList)
10421029 , "produces" .= (mempty :: MimeList)
10431030 , "security" .= ([] :: [SecurityRequirement])
@@ -1080,9 +1067,6 @@ instance FromJSON Host where
10801067 [host, portStr] = map Text.unpack [hostText, portText]
10811068 parseJSON _ = empty
10821069
1083−instance FromJSON Paths where
1084− parseJSON js = Paths <$> parseJSON js
1085−
10861070instance FromJSON MimeList where
10871071 parseJSON js = (MimeList . map fromString) <$> parseJSON js
10881072
src/Data/Swagger/Internal/ParamSchema.hs+31−31
@@ -42,8 +42,8 @@ import Data.Swagger.SchemaOptions
4242--
4343-- instance ToParamSchema Direction where
4444-- toParamSchema = mempty
45−-- & schemaType .~ SwaggerString
46−-- & schemaEnum .~ [ \"Up\", \"Down\" ]
45+-- & type_ .~ SwaggerString
46+-- & enum_ .~ [ \"Up\", \"Down\" ]
4747-- @
4848--
4949-- Instead of manually writing your @'ToParamSchema'@ instance you can
@@ -74,23 +74,23 @@ class ToParamSchema a where
7474 toParamSchema = genericToParamSchema defaultSchemaOptions
7575
7676instance {-# OVERLAPPING #-} ToParamSchema String where
77− toParamSchema _ = mempty & schemaType .~ SwaggerString
77+ toParamSchema _ = mempty & type_ .~ SwaggerString
7878
7979instance ToParamSchema Bool where
80− toParamSchema _ = mempty & schemaType .~ SwaggerBoolean
80+ toParamSchema _ = mempty & type_ .~ SwaggerBoolean
8181
8282instance ToParamSchema Integer where
83− toParamSchema _ = mempty & schemaType .~ SwaggerInteger
83+ toParamSchema _ = mempty & type_ .~ SwaggerInteger
8484
8585instance ToParamSchema Int where toParamSchema = toParamSchemaBoundedIntegral
8686instance ToParamSchema Int8 where toParamSchema = toParamSchemaBoundedIntegral
8787instance ToParamSchema Int16 where toParamSchema = toParamSchemaBoundedIntegral
8888
8989instance ToParamSchema Int32 where
90− toParamSchema proxy = toParamSchemaBoundedIntegral proxy & schemaFormat ?~ "int32"
90+ toParamSchema proxy = toParamSchemaBoundedIntegral proxy & format ?~ "int32"
9191
9292instance ToParamSchema Int64 where
93− toParamSchema proxy = toParamSchemaBoundedIntegral proxy & schemaFormat ?~ "int64"
93+ toParamSchema proxy = toParamSchemaBoundedIntegral proxy & format ?~ "int64"
9494
9595instance ToParamSchema Word where toParamSchema = toParamSchemaBoundedIntegral
9696instance ToParamSchema Word8 where toParamSchema = toParamSchemaBoundedIntegral
@@ -104,52 +104,52 @@ instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
104104-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
105105toParamSchemaBoundedIntegral :: forall proxy a t. (Bounded a, Integral a) => proxy a -> ParamSchema t
106106toParamSchemaBoundedIntegral _ = mempty
107− & schemaType .~ SwaggerInteger
108− & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
109− & schemaMaximum ?~ fromInteger (toInteger (maxBound :: a))
107+ & type_ .~ SwaggerInteger
108+ & minimum_ ?~ fromInteger (toInteger (minBound :: a))
109+ & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
110110
111111instance ToParamSchema Char where
112112 toParamSchema _ = mempty
113− & schemaType .~ SwaggerString
114− & schemaMaxLength ?~ 1
115− & schemaMinLength ?~ 1
113+ & type_ .~ SwaggerString
114+ & maxLength ?~ 1
115+ & minLength ?~ 1
116116
117117instance ToParamSchema Scientific where
118− toParamSchema _ = mempty & schemaType .~ SwaggerNumber
118+ toParamSchema _ = mempty & type_ .~ SwaggerNumber
119119
120120instance ToParamSchema Double where
121121 toParamSchema _ = mempty
122− & schemaType .~ SwaggerNumber
123− & schemaFormat ?~ "double"
122+ & type_ .~ SwaggerNumber
123+ & format ?~ "double"
124124
125125instance ToParamSchema Float where
126126 toParamSchema _ = mempty
127− & schemaType .~ SwaggerNumber
128− & schemaFormat ?~ "float"
127+ & type_ .~ SwaggerNumber
128+ & format ?~ "float"
129129
130130timeParamSchema :: String -> ParamSchema t
131−timeParamSchema format = mempty
132− & schemaType .~ SwaggerString
133− & schemaFormat ?~ T.pack format
131+timeParamSchema fmt = mempty
132+ & type_ .~ SwaggerString
133+ & format ?~ T.pack fmt
134134
135135-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
136136instance ToParamSchema Day where
137137 toParamSchema _ = timeParamSchema "date"
138138
139139-- |
140−-- >>> toParamSchema (Proxy :: Proxy LocalTime) ^. schemaFormat
140+-- >>> toParamSchema (Proxy :: Proxy LocalTime) ^. format
141141-- Just "yyyy-mm-ddThh:MM:ss"
142142instance ToParamSchema LocalTime where
143143 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss"
144144
145145-- |
146−-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ^. schemaFormat
146+-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ^. format
147147-- Just "yyyy-mm-ddThh:MM:ss+hhMM"
148148instance ToParamSchema ZonedTime where
149149 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss+hhMM"
150150
151151-- |
152−-- >>> toParamSchema (Proxy :: Proxy UTCTime) ^. schemaFormat
152+-- >>> toParamSchema (Proxy :: Proxy UTCTime) ^. format
153153-- Just "yyyy-mm-ddThh:MM:ssZ"
154154instance ToParamSchema UTCTime where
155155 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
@@ -173,12 +173,12 @@ instance ToParamSchema a => ToParamSchema (Dual a) where toParamSchema _ = to
173173
174174instance ToParamSchema a => ToParamSchema [a] where
175175 toParamSchema _ = mempty
176− & schemaType .~ SwaggerArray
177− & schemaItems ?~ SwaggerItemsPrimitive Nothing (toParamSchema (Proxy :: Proxy a))
176+ & type_ .~ SwaggerArray
177+ & items ?~ SwaggerItemsPrimitive Nothing (toParamSchema (Proxy :: Proxy a))
178178
179179instance ToParamSchema a => ToParamSchema (Set a) where
180180 toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
181− & schemaUniqueItems ?~ True
181+ & uniqueItems ?~ True
182182
183183instance ToParamSchema a => ToParamSchema (HashSet a) where
184184 toParamSchema _ = toParamSchema (Proxy :: Proxy (Set a))
@@ -188,8 +188,8 @@ instance ToParamSchema a => ToParamSchema (HashSet a) where
188188-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
189189instance ToParamSchema () where
190190 toParamSchema _ = mempty
191− & schemaType .~ SwaggerString
192− & schemaEnum ?~ ["_"]
191+ & type_ .~ SwaggerString
192+ & enum_ ?~ ["_"]
193193
194194-- | A configurable generic @'ParamSchema'@ creator.
195195--
@@ -226,8 +226,8 @@ instance (GEnumParamSchema f, GEnumParamSchema g) => GEnumParamSchema (f :+: g)
226226
227227instance Constructor c => GEnumParamSchema (C1 c U1) where
228228 genumParamSchema opts _ s = s
229− & schemaType .~ SwaggerString
230− & schemaEnum %~ addEnumValue tag
229+ & type_ .~ SwaggerString
230+ & enum_ %~ addEnumValue tag
231231 where
232232 tag = toJSON (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
233233
src/Data/Swagger/Internal/Schema.hs+36−36
@@ -76,12 +76,12 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
7676-- declareNamedSchema = pure (Just \"Coord\", schema)
7777-- where
7878-- schema = mempty
79−-- & schemaType .~ SwaggerObject
80−-- & schemaProperties .~
79+-- & type_ .~ SwaggerObject
80+-- & properties .~
8181-- [ (\"x\", toSchemaRef (Proxy :: Proxy Double))
8282-- , (\"y\", toSchemaRef (Proxy :: Proxy Double))
8383-- ]
84−-- & schemaRequired .~ [ \"x\", \"y\" ]
84+-- & required .~ [ \"x\", \"y\" ]
8585-- @
8686--
8787-- Instead of manually writing your @'ToSchema'@ instance you can
@@ -117,14 +117,14 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
117117
118118-- | Convert a type into an optionally named schema.
119119--
120−-- >>> toNamedSchema (Proxy :: Proxy String) ^. namedSchemaName
120+-- >>> toNamedSchema (Proxy :: Proxy String) ^. name
121121-- Nothing
122−-- >>> encode (toNamedSchema (Proxy :: Proxy String) ^. namedSchemaSchema)
122+-- >>> encode (toNamedSchema (Proxy :: Proxy String) ^. schema)
123123-- "{\"type\":\"string\"}"
124124--
125−-- >>> toNamedSchema (Proxy :: Proxy Day) ^. namedSchemaName
125+-- >>> toNamedSchema (Proxy :: Proxy Day) ^. name
126126-- Just "Day"
127−-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. namedSchemaSchema)
127+-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
128128-- "{\"format\":\"date\",\"type\":\"string\"}"
129129toNamedSchema :: ToSchema a => proxy a -> NamedSchema
130130toNamedSchema = undeclare . declareNamedSchema
@@ -262,8 +262,8 @@ instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
262262 declareNamedSchema _ = do
263263 ref <- declareSchemaRef (Proxy :: Proxy a)
264264 return $ unnamed $ mempty
265− & schemaType .~ SwaggerArray
266− & schemaItems ?~ SwaggerItemsObject ref
265+ & type_ .~ SwaggerArray
266+ & items ?~ SwaggerItemsObject ref
267267
268268instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
269269instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
@@ -300,16 +300,16 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f
300300instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f, ToSchema g) => ToSchema (a, b, c, d, e, f, g)
301301
302302timeSchema :: T.Text -> Schema
303−timeSchema format = mempty
304− & schemaType .~ SwaggerString
305− & schemaFormat ?~ format
303+timeSchema fmt = mempty
304+ & type_ .~ SwaggerString
305+ & format ?~ fmt
306306
307307-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
308308instance ToSchema Day where
309309 declareNamedSchema _ = pure $ named "Day" (timeSchema "date")
310310
311311-- |
312−-- >>> toSchema (Proxy :: Proxy LocalTime) ^. schemaFormat
312+-- >>> toSchema (Proxy :: Proxy LocalTime) ^. format
313313-- Just "yyyy-mm-ddThh:MM:ss"
314314instance ToSchema LocalTime where
315315 declareNamedSchema _ = pure $ named "LocalTime" (timeSchema "yyyy-mm-ddThh:MM:ss")
@@ -322,7 +322,7 @@ instance ToSchema NominalDiffTime where
322322 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Integer)
323323
324324-- |
325−-- >>> toSchema (Proxy :: Proxy UTCTime) ^. schemaFormat
325+-- >>> toSchema (Proxy :: Proxy UTCTime) ^. format
326326-- Just "yyyy-mm-ddThh:MM:ssZ"
327327instance ToSchema UTCTime where
328328 declareNamedSchema _ = pure $ named "UTCTime" (timeSchema "yyyy-mm-ddThh:MM:ssZ")
@@ -340,8 +340,8 @@ instance ToSchema a => ToSchema (Map String a) where
340340 declareNamedSchema _ = do
341341 schema <- declareSchema (Proxy :: Proxy a)
342342 return $ unnamed $ mempty
343− & schemaType .~ SwaggerObject
344− & schemaAdditionalProperties ?~ schema
343+ & type_ .~ SwaggerObject
344+ & additionalProperties ?~ schema
345345
346346instance ToSchema a => ToSchema (Map T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
347347instance ToSchema a => ToSchema (Map TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
@@ -354,7 +354,7 @@ instance ToSchema a => ToSchema (Set a) where
354354 declareNamedSchema _ = do
355355 schema <- declareSchema (Proxy :: Proxy [a])
356356 return $ unnamed $ schema
357− & schemaUniqueItems ?~ True
357+ & uniqueItems ?~ True
358358
359359instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
360360
@@ -373,9 +373,9 @@ instance ToSchema a => ToSchema (Dual a) where declareNamedSchema _ = unname
373373-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
374374toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
375375toSchemaBoundedIntegral _ = mempty
376− & schemaType .~ SwaggerInteger
377− & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
378− & schemaMaximum ?~ fromInteger (toInteger (maxBound :: a))
376+ & type_ .~ SwaggerInteger
377+ & minimum_ ?~ fromInteger (toInteger (minBound :: a))
378+ & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
379379
380380-- | Default generic named schema for @'Bounded'@, @'Integral'@ types.
381381genericToNamedSchemaBoundedIntegral :: forall a d f proxy.
@@ -411,13 +411,13 @@ paramSchemaToNamedSchema opts proxy = NamedSchema (gdatatypeSchemaName opts (Pro
411411
412412-- | Lift a plain @'ParamSchema'@ into a model @'Schema'@.
413413paramSchemaToSchema :: forall a proxy. ToParamSchema a => proxy a -> Schema
414−paramSchemaToSchema _ = mempty & schemaParamSchema .~ toParamSchema (Proxy :: Proxy a)
414+paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
415415
416416nullarySchema :: Schema
417417nullarySchema = mempty
418− & schemaType .~ SwaggerArray
419− & schemaEnum ?~ [ toJSON () ]
420− & schemaItems ?~ SwaggerItemsArray []
418+ & type_ .~ SwaggerArray
419+ & enum_ ?~ [ toJSON () ]
420+ & items ?~ SwaggerItemsArray []
421421
422422gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
423423gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
@@ -446,7 +446,7 @@ instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
446446 gdeclareNamedSchema opts _ s
447447 | unwrapUnaryRecords opts = fieldSchema
448448 | otherwise =
449− case schema ^. schemaItems of
449+ case schema ^. items of
450450 Just (SwaggerItemsArray [_]) -> fieldSchema
451451 _ -> do
452452 declare defs
@@ -487,13 +487,13 @@ withFieldSchema opts _ isRequiredField schema = do
487487 return $
488488 if T.null fname
489489 then schema
490− & schemaType .~ SwaggerArray
491− & schemaItems %~ appendItem ref
490+ & type_ .~ SwaggerArray
491+ & items %~ appendItem ref
492492 else schema
493− & schemaType .~ SwaggerObject
494− & schemaProperties . at fname ?~ ref
493+ & type_ .~ SwaggerObject
494+ & properties . at fname ?~ ref
495495 & if isRequiredField
496− then schemaRequired %~ (fname :)
496+ then required %~ (fname :)
497497 else id
498498 where
499499 fname = T.pack (fieldLabelModifier opts (selName (Proxy3 :: Proxy3 s f p)))
@@ -524,8 +524,8 @@ gdeclareNamedSumSchema opts proxy s
524524 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
525525
526526 toStringTag schema = mempty
527− & schemaType .~ SwaggerString
528− & schemaEnum ?~ map toJSON (schema ^.. schemaProperties.ifolded.asIndex)
527+ & type_ .~ SwaggerString
528+ & enum_ ?~ map toJSON (schema ^.. properties.ifolded.asIndex)
529529
530530type AllNullary = All
531531
@@ -540,10 +540,10 @@ gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
540540gsumConToSchema opts _ schema = do
541541 ref <- gdeclareSchemaRef opts (Proxy :: Proxy (C1 c f))
542542 return $ schema
543− & schemaType .~ SwaggerObject
544− & schemaProperties . at tag ?~ ref
545− & schemaMaxProperties ?~ 1
546− & schemaMinProperties ?~ 1
543+ & type_ .~ SwaggerObject
544+ & properties . at tag ?~ ref
545+ & maxProperties ?~ 1
546+ & minProperties ?~ 1
547547 where
548548 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
549549
src/Data/Swagger/Internal/Utils.hs+22
@@ -8,6 +8,8 @@ module Data.Swagger.Internal.Utils where
88
99import Control.Arrow (first)
1010import Control.Applicative
11+import Control.Lens ((&), (%~))
12+import Control.Lens.TH
1113import Data.Aeson
1214import Data.Aeson.Types
1315import Data.Char
@@ -19,8 +21,28 @@ import Data.Map (Map)
1921import Data.Monoid
2022import Data.Text (Text)
2123import GHC.Generics
24+import Language.Haskell.TH (mkName)
2225import Text.Read (readMaybe)
2326
27+swaggerFieldRules :: LensRules
28+swaggerFieldRules = defaultFieldRules & lensField %~ swaggerFieldNamer
29+ where
30+ swaggerFieldNamer namer dname fnames fname =
31+ map fixDefName (namer dname fnames fname)
32+
33+ fixDefName (MethodName cname mname) = MethodName cname (fixName mname)
34+ fixDefName (TopName name) = TopName (fixName name)
35+
36+ fixName = mkName . fixName' . show
37+
38+ fixName' "in" = "in_" -- keyword
39+ fixName' "type" = "type_" -- keyword
40+ fixName' "default" = "default_" -- keyword
41+ fixName' "minimum" = "minimum_" -- Prelude conflict
42+ fixName' "maximum" = "maximum_" -- Prelude conflict
43+ fixName' "enum" = "enum_" -- Control.Lens conflict
44+ fixName' n = n
45+
2446gunfoldEnum :: String -> [a] -> (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
2547gunfoldEnum tname xs _k z c = case lookup (constrIndex c) (zip [1..] xs) of
2648 Just x -> z x
src/Data/Swagger/Lens.hs+78−79
@@ -1,50 +1,51 @@
1+{-# LANGUAGE FlexibleContexts #-}
12{-# LANGUAGE FlexibleInstances #-}
23{-# LANGUAGE FunctionalDependencies #-}
34{-# LANGUAGE GADTs #-}
45{-# LANGUAGE MultiParamTypeClasses #-}
56{-# LANGUAGE RankNTypes #-}
67{-# LANGUAGE TemplateHaskell #-}
8+{-# LANGUAGE UndecidableInstances #-}
79module Data.Swagger.Lens where
810
911import Control.Lens
1012import Data.Aeson (Value)
1113import Data.Scientific (Scientific)
1214import Data.Swagger.Internal
15+import Data.Swagger.Internal.Utils
1316import Data.Text (Text)
1417
1518-- =======================================================================
1619-- * TH derived lenses
1720
1821-- ** 'Swagger' lenses
19−makeLenses ''Swagger
22+makeFields ''Swagger
2023-- ** 'Host' lenses
21−makeLenses ''Host
24+makeFields ''Host
2225-- ** 'Info' lenses
23−makeLenses ''Info
26+makeFields ''Info
2427-- ** 'Contact' lenses
25−makeLenses ''Contact
28+makeFields ''Contact
2629-- ** 'License' lenses
27−makeLenses ''License
28−-- ** 'Paths' lenses
29−makeLenses ''Paths
30+makeFields ''License
3031-- ** 'PathItem' lenses
31−makeLenses ''PathItem
32+makeFields ''PathItem
3233-- ** 'Tag' lenses
33−makeLenses ''Tag
34+makeFields ''Tag
3435-- ** 'Operation' lenses
35−makeLenses ''Operation
36+makeFields ''Operation
3637-- ** 'Param' lenses
37−makeLenses ''Param
38+makeFields ''Param
3839-- ** 'ParamAnySchema' prisms
3940makePrisms ''ParamAnySchema
4041-- ** 'ParamOtherSchema' lenses
41−makeLenses ''ParamOtherSchema
42+makeLensesWith swaggerFieldRules ''ParamOtherSchema
4243-- ** 'Header' lenses
43−makeLenses ''Header
44+makeFields ''Header
4445-- ** 'Schema' lenses
45−makeLenses ''Schema
46+makeFields ''Schema
4647-- ** 'NamedSchema' lenses
47−makeLenses ''NamedSchema
48+makeFields ''NamedSchema
4849
4950-- ** 'SwaggerItems' prisms
5051
@@ -66,94 +67,92 @@ _SwaggerItemsPrimitive :: forall t p f. (Profunctor p, Bifunctor p, Functor f) =
6667_SwaggerItemsPrimitive = unto (\(c, p) -> SwaggerItemsPrimitive c p)
6768
6869-- ** 'ParamSchema' lenses
69−makeLenses ''ParamSchema
70+makeLensesWith swaggerFieldRules ''ParamSchema
7071-- ** 'Xml' lenses
71−makeLenses ''Xml
72+makeFields ''Xml
7273-- ** 'Responses' lenses
73−makeLenses ''Responses
74+makeLensesWith swaggerFieldRules ''Responses
7475-- ** 'Response' lenses
75−makeLenses ''Response
76+makeFields ''Response
7677-- ** 'SecurityScheme' lenses
77−makeLenses ''SecurityScheme
78+makeLensesWith swaggerFieldRules ''SecurityScheme
7879-- ** 'SecuritySchemeType' prisms
7980makePrisms ''SecuritySchemeType
8081-- ** 'ApiKeyParams' lenses
81−makeLenses ''ApiKeyParams
82+makeFields ''ApiKeyParams
8283-- ** 'OAuth2Params' lenses
83−makeLenses ''OAuth2Params
84+makeFields ''OAuth2Params
8485-- ** 'ExternalDocs' lenses
85−makeLenses ''ExternalDocs
86+makeFields ''ExternalDocs
8687
87−-- =======================================================================
88−-- * Helper classy lenses
89−
90−class HasDescription s d | s -> d where
91− description :: Lens' s d
92−
93−instance HasDescription Response Text where description = responseDescription
94−instance HasDescription Info (Maybe Text) where description = infoDescription
95−instance HasDescription Tag (Maybe Text) where description = tagDescription
96−instance HasDescription Operation (Maybe Text) where description = operationDescription
97−instance HasDescription Param (Maybe Text) where description = paramDescription
98−instance HasDescription Header (Maybe Text) where description = headerDescription
99−instance HasDescription Schema (Maybe Text) where description = schemaDescription
100−instance HasDescription SecurityScheme (Maybe Text) where description = securitySchemeDescription
101−instance HasDescription ExternalDocs (Maybe Text) where description = externalDocsDescription
102−
103−class HasParamSchema s t | s -> t where
104− parameterSchema :: Lens' s (ParamSchema t)
105−
106−instance HasParamSchema Schema Schema where parameterSchema = schemaParamSchema
107−instance HasParamSchema ParamOtherSchema ParamOtherSchema where parameterSchema = paramOtherSchemaParamSchema
108−instance HasParamSchema Header Header where parameterSchema = headerParamSchema
109−instance HasParamSchema (ParamSchema t) t where parameterSchema = id
110−instance HasParamSchema NamedSchema Schema where parameterSchema = namedSchemaSchema.parameterSchema
88+-- =============================================================
89+-- More helpful instances for easier access to schema properties
11190
112−schemaType :: HasParamSchema s t => Lens' s (SwaggerType t)
113−schemaType = parameterSchema.paramSchemaType
91+-- HasType instances
92+instance HasType Header (SwaggerType Header) where type_ = paramSchema.type_
93+instance HasType Schema (SwaggerType Schema) where type_ = paramSchema.type_
94+instance HasType NamedSchema (SwaggerType Schema) where type_ = schema.paramSchema.type_
95+instance HasType ParamOtherSchema (SwaggerType ParamOtherSchema) where type_ = paramSchema.type_
11496
115−schemaFormat :: HasParamSchema s t => Lens' s (Maybe Format)
116−schemaFormat = parameterSchema.paramSchemaFormat
97+-- HasDefault instances
98+instance HasDefault Header (Maybe Value) where default_ = paramSchema.default_
99+instance HasDefault Schema (Maybe Value) where default_ = paramSchema.default_
100+instance HasDefault ParamOtherSchema (Maybe Value) where default_ = paramSchema.default_
117101
118−schemaItems :: HasParamSchema s t => Lens' s (Maybe (SwaggerItems t))
119−schemaItems = parameterSchema.paramSchemaItems
102+-- OVERLAPPABLE instances
120103
121−schemaDefault :: HasParamSchema s t => Lens' s (Maybe Value)
122−schemaDefault = parameterSchema.paramSchemaDefault
104+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
105+ => HasFormat s (Maybe Format) where
106+ format = paramSchema.format
123107
124−schemaMaximum :: HasParamSchema s t => Lens' s (Maybe Scientific)
125−schemaMaximum = parameterSchema.paramSchemaMaximum
108+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
109+ => HasItems s (Maybe (SwaggerItems t)) where
110+ items = paramSchema.items
126111
127−schemaExclusiveMaximum :: HasParamSchema s t => Lens' s (Maybe Bool)
128−schemaExclusiveMaximum = parameterSchema.paramSchemaExclusiveMaximum
112+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
113+ => HasMaximum s (Maybe Scientific) where
114+ maximum_ = paramSchema.maximum_
129115
130−schemaMinimum :: HasParamSchema s t => Lens' s (Maybe Scientific)
131−schemaMinimum = parameterSchema.paramSchemaMinimum
116+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
117+ => HasExclusiveMaximum s (Maybe Bool) where
118+ exclusiveMaximum = paramSchema.exclusiveMaximum
132119
133−schemaExclusiveMinimum :: HasParamSchema s t => Lens' s (Maybe Bool)
134−schemaExclusiveMinimum = parameterSchema.paramSchemaExclusiveMinimum
120+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
121+ => HasMinimum s (Maybe Scientific) where
122+ minimum_ = paramSchema.minimum_
135123
136−schemaMaxLength :: HasParamSchema s t => Lens' s (Maybe Integer)
137−schemaMaxLength = parameterSchema.paramSchemaMaxLength
124+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
125+ => HasExclusiveMinimum s (Maybe Bool) where
126+ exclusiveMinimum = paramSchema.exclusiveMinimum
138127
139−schemaMinLength :: HasParamSchema s t => Lens' s (Maybe Integer)
140−schemaMinLength = parameterSchema.paramSchemaMinLength
128+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
129+ => HasMaxLength s (Maybe Integer) where
130+ maxLength = paramSchema.maxLength
141131
142−schemaPattern :: HasParamSchema s t => Lens' s (Maybe Text)
143−schemaPattern = parameterSchema.paramSchemaPattern
132+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
133+ => HasMinLength s (Maybe Integer) where
134+ minLength = paramSchema.minLength
144135
145−schemaMaxItems :: HasParamSchema s t => Lens' s (Maybe Integer)
146−schemaMaxItems = parameterSchema.paramSchemaMaxItems
136+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
137+ => HasPattern s (Maybe Text) where
138+ pattern = paramSchema.pattern
147139
148−schemaMinItems :: HasParamSchema s t => Lens' s (Maybe Integer)
149−schemaMinItems = parameterSchema.paramSchemaMinItems
140+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
141+ => HasMaxItems s (Maybe Integer) where
142+ maxItems = paramSchema.maxItems
150143
151−schemaUniqueItems :: HasParamSchema s t => Lens' s (Maybe Bool)
152−schemaUniqueItems = parameterSchema.paramSchemaUniqueItems
144+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
145+ => HasMinItems s (Maybe Integer) where
146+ minItems = paramSchema.minItems
153147
154−schemaEnum :: HasParamSchema s t => Lens' s (Maybe [Value])
155−schemaEnum = parameterSchema.paramSchemaEnum
148+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
149+ => HasUniqueItems s (Maybe Bool) where
150+ uniqueItems = paramSchema.uniqueItems
156151
157−schemaMultipleOf :: HasParamSchema s t => Lens' s (Maybe Scientific)
158−schemaMultipleOf = parameterSchema.paramSchemaMultipleOf
152+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
153+ => HasEnum s (Maybe [Value]) where
154+ enum_ = paramSchema.enum_
159155
156+instance {-# OVERLAPPABLE #-} HasParamSchema s (ParamSchema t)
157+ => HasMultipleOf s (Maybe Scientific) where
158+ multipleOf = paramSchema.multipleOf
swagger2.cabal+1
@@ -40,6 +40,7 @@ library
4040 , mtl
4141 , network
4242 , text
43+ , template-haskell
4344 , time
4445 , unordered-containers
4546 , lens
test/Data/SwaggerSpec.hs+66−67
@@ -151,9 +151,9 @@ operationExample = mempty
151151 ]
152152
153153 stringSchema :: ParamLocation -> ParamOtherSchema
154− stringSchema i = mempty
155− & paramOtherSchemaIn .~ i
156− & schemaType .~ SwaggerString
154+ stringSchema loc = mempty
155+ & in_ .~ loc
156+ & type_ .~ SwaggerString
157157
158158operationExampleJSON :: Value
159159operationExampleJSON = [aesonQQ|
@@ -219,8 +219,8 @@ operationExampleJSON = [aesonQQ|
219219
220220schemaPrimitiveExample :: Schema
221221schemaPrimitiveExample = mempty
222− & schemaType .~ SwaggerString
223− & schemaFormat ?~ "email"
222+ & type_ .~ SwaggerString
223+ & format ?~ "email"
224224
225225schemaPrimitiveExampleJSON :: Value
226226schemaPrimitiveExampleJSON = [aesonQQ|
@@ -232,15 +232,15 @@ schemaPrimitiveExampleJSON = [aesonQQ|
232232
233233schemaSimpleModelExample :: Schema
234234schemaSimpleModelExample = mempty
235− & schemaType .~ SwaggerObject
236− & schemaRequired .~ [ "name" ]
237− & schemaProperties .~
238− [ ("name", Inline (mempty & schemaType .~ SwaggerString))
235+ & type_ .~ SwaggerObject
236+ & required .~ [ "name" ]
237+ & properties .~
238+ [ ("name", Inline (mempty & type_ .~ SwaggerString))
239239 , ("address", Ref (Reference "Address"))
240240 , ("age", Inline $ mempty
241− & schemaMinimum ?~ 0
242− & schemaType .~ SwaggerInteger
243− & schemaFormat ?~ "int32" ) ]
241+ & minimum_ ?~ 0
242+ & type_ .~ SwaggerInteger
243+ & format ?~ "int32" ) ]
244244
245245schemaSimpleModelExampleJSON :: Value
246246schemaSimpleModelExampleJSON = [aesonQQ|
@@ -267,8 +267,8 @@ schemaSimpleModelExampleJSON = [aesonQQ|
267267
268268schemaModelDictExample :: Schema
269269schemaModelDictExample = mempty
270− & schemaType .~ SwaggerObject
271− & schemaAdditionalProperties ?~ (mempty & schemaType .~ SwaggerString)
270+ & type_ .~ SwaggerObject
271+ & additionalProperties ?~ (mempty & type_ .~ SwaggerString)
272272
273273schemaModelDictExampleJSON :: Value
274274schemaModelDictExampleJSON = [aesonQQ|
@@ -281,12 +281,12 @@ schemaModelDictExampleJSON = [aesonQQ|
281281|]
282282
283283schemaWithExampleExample :: Schema
284−schemaWithExampleExample = (mempty & schemaType .~ SwaggerObject)
284+schemaWithExampleExample = (mempty & type_ .~ SwaggerObject)
285285 { _schemaProperties =
286286 [ ("id", Inline $ mempty
287− & schemaType .~ SwaggerInteger
288− & schemaFormat ?~ "int64" )
289− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ]
287+ & type_ .~ SwaggerInteger
288+ & format ?~ "int64" )
289+ , ("name", Inline (mempty & type_ .~ SwaggerString)) ]
290290 , _schemaRequired = [ "name" ]
291291 , _schemaExample = Just [aesonQQ|
292292 {
@@ -325,19 +325,19 @@ schemaWithExampleExampleJSON = [aesonQQ|
325325definitionsExample :: HashMap Text Schema
326326definitionsExample =
327327 [ ("Category", mempty
328− & schemaType .~ SwaggerObject
329− & schemaProperties .~
328+ & type_ .~ SwaggerObject
329+ & properties .~
330330 [ ("id", Inline $ mempty
331− & schemaType .~ SwaggerInteger
332− & schemaFormat ?~ "int64")
333− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ] )
331+ & type_ .~ SwaggerInteger
332+ & format ?~ "int64")
333+ , ("name", Inline (mempty & type_ .~ SwaggerString)) ] )
334334 , ("Tag", mempty
335− & schemaType .~ SwaggerObject
336− & schemaProperties .~
335+ & type_ .~ SwaggerObject
336+ & properties .~
337337 [ ("id", Inline $ mempty
338− & schemaType .~ SwaggerInteger
339− & schemaFormat ?~ "int64")
340− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ] ) ]
338+ & type_ .~ SwaggerInteger
339+ & format ?~ "int64")
340+ , ("name", Inline (mempty & type_ .~ SwaggerString)) ] ) ]
341341
342342definitionsExampleJSON :: Value
343343definitionsExampleJSON = [aesonQQ|
@@ -380,17 +380,17 @@ paramsDefinitionExample =
380380 , _paramDescription = Just "number of items to skip"
381381 , _paramRequired = Just True
382382 , _paramSchema = ParamOther $ mempty
383− & paramOtherSchemaIn .~ ParamQuery
384− & schemaType .~ SwaggerInteger
385− & schemaFormat ?~ "int32" })
383+ & in_ .~ ParamQuery
384+ & type_ .~ SwaggerInteger
385+ & format ?~ "int32" })
386386 , ("limitParam", mempty
387387 { _paramName = "limit"
388388 , _paramDescription = Just "max records to return"
389389 , _paramRequired = Just True
390390 , _paramSchema = ParamOther $ mempty
391− & paramOtherSchemaIn .~ ParamQuery
392− & schemaType .~ SwaggerInteger
393− & schemaFormat ?~ "int32" }) ]
391+ & in_ .~ ParamQuery
392+ & type_ .~ SwaggerInteger
393+ & format ?~ "int32" }) ]
394394
395395paramsDefinitionExampleJSON :: Value
396396paramsDefinitionExampleJSON = [aesonQQ|
@@ -478,45 +478,44 @@ securityDefinitionsExampleJSON = [aesonQQ|
478478
479479swaggerExample :: Swagger
480480swaggerExample = mempty
481− { _basePath = Just "/"
482− , _schemes = Just [Http]
483− , _info = mempty
481+ { _swaggerBasePath = Just "/"
482+ , _swaggerSchemes = Just [Http]
483+ , _swaggerInfo = mempty
484484 { _infoVersion = "1.0"
485485 , _infoTitle = "Todo API"
486486 , _infoLicense = Just License
487487 { _licenseName = "MIT"
488488 , _licenseUrl = Just (URL "http://mit.com") }
489489 , _infoDescription = Just "This is a an API that tests servant-swagger support for a Todo API" }
490− , _paths = mempty
491− { _pathsMap =
492− [ ("/todo/{id}", mempty
493− { _pathItemGet = Just mempty
494− { _operationResponses = mempty
495− { _responsesResponses =
496− [ (200, Inline mempty
497− { _responseSchema = Just $ Inline (mempty & schemaType .~ SwaggerObject)
498− { _schemaExample = Just [aesonQQ|
499− {
500− "created": 100,
501− "description": "get milk"
502− } |]
503− , _schemaDescription = Just "This is some real Todo right here"
504− , _schemaProperties =
505− [ ("created", Inline $ mempty
506− & schemaType .~ SwaggerInteger
507− & schemaFormat ?~ "int32")
508− , ("description", Inline (mempty & schemaType .~ SwaggerString)) ] }
509− , _responseDescription = "OK" }) ] }
510− , _operationProduces = Just (MimeList [ "application/json" ])
511− , _operationParameters =
512− [ Inline mempty
513− { _paramRequired = Just True
514− , _paramName = "id"
515− , _paramDescription = Just "TodoId param"
516− , _paramSchema = ParamOther $ mempty
517− & paramOtherSchemaIn .~ ParamPath
518− & schemaType .~ SwaggerString } ]
519− , _operationTags = [ "todo" ] } }) ] } }
490+ , _swaggerPaths =
491+ [ ("/todo/{id}", mempty
492+ { _pathItemGet = Just mempty
493+ { _operationResponses = mempty
494+ { _responsesResponses =
495+ [ (200, Inline mempty
496+ { _responseSchema = Just $ Inline (mempty & type_ .~ SwaggerObject)
497+ { _schemaExample = Just [aesonQQ|
498+ {
499+ "created": 100,
500+ "description": "get milk"
501+ } |]
502+ , _schemaDescription = Just "This is some real Todo right here"
503+ , _schemaProperties =
504+ [ ("created", Inline $ mempty
505+ & type_ .~ SwaggerInteger
506+ & format ?~ "int32")
507+ , ("description", Inline (mempty & type_ .~ SwaggerString)) ] }
508+ , _responseDescription = "OK" }) ] }
509+ , _operationProduces = Just (MimeList [ "application/json" ])
510+ , _operationParameters =
511+ [ Inline mempty
512+ { _paramRequired = Just True
513+ , _paramName = "id"
514+ , _paramDescription = Just "TodoId param"
515+ , _paramSchema = ParamOther $ mempty
516+ & in_ .~ ParamPath
517+ & type_ .~ SwaggerString } ]
518+ , _operationTags = [ "todo" ] } }) ] }
520519
521520swaggerExampleJSON :: Value
522521swaggerExampleJSON = [aesonQQ|