git.iko.soy/typeable/openapi3
on master help sign in
Move type and format to SchemaCommon
badf3a1Nickolay Kudasov
src/Data/Swagger/Internal.hs+12−35
@@ -283,17 +283,6 @@ data ParamOtherSchema = ParamOtherSchema
283 { -- | The location of the parameter.
283 { -- | The location of the parameter.
284 _paramOtherSchemaIn :: ParamLocation
284 _paramOtherSchemaIn :: ParamLocation
285
285
286− -- | The type of the parameter.
287− -- Since the parameter is not located at the request body,
288− -- it is limited to simple types (that is, not an object).
289− -- If type is @'ParamFile'@, the @consumes@ MUST be either
290− -- "multipart/form-data" or " application/x-www-form-urlencoded"
291− -- and the parameter MUST be in @'ParamFormData'@.
292− , _paramOtherSchemaType :: ParamType
293−
294− -- | The extending format for the previously mentioned type.
295− , _paramOtherSchemaFormat :: Maybe Format
296−
297 -- | Sets the ability to pass empty-valued parameters.
286 -- | Sets the ability to pass empty-valued parameters.
298 -- This is valid only for either @'ParamQuery'@ or @'ParamFormData'@
287 -- 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.
288 -- and allows you to send a parameter with a name only or an empty value.
@@ -308,7 +297,7 @@ data ParamOtherSchema = ParamOtherSchema
308 -- Default value is csv.
297 -- Default value is csv.
309 , _paramOtherSchemaCollectionFormat :: Maybe CollectionFormat
298 , _paramOtherSchemaCollectionFormat :: Maybe CollectionFormat
310
299
311− , _paramOtherSchemaCommon :: SchemaCommon
300+ , _paramOtherSchemaCommon :: SchemaCommon ParamType
312 } deriving (Eq, Show, Generic)
301 } deriving (Eq, Show, Generic)
313
302
314data ParamType
303data ParamType
@@ -382,9 +371,7 @@ data ItemsCollectionFormat
382type ParamName = Text
371type ParamName = Text
383
372
384data Schema = Schema
373data Schema = Schema
385− { _schemaType :: SchemaType
386− , _schemaFormat :: Maybe Format
387− , _schemaTitle :: Maybe Text
374+ { _schemaTitle :: Maybe Text
388 , _schemaDescription :: Maybe Text
375 , _schemaDescription :: Maybe Text
389 , _schemaRequired :: [ParamName]
376 , _schemaRequired :: [ParamName]
390
377
@@ -402,7 +389,7 @@ data Schema = Schema
402 , _schemaMaxProperties :: Maybe Integer
389 , _schemaMaxProperties :: Maybe Integer
403 , _schemaMinProperties :: Maybe Integer
390 , _schemaMinProperties :: Maybe Integer
404
391
405− , _schemaSchemaCommon :: SchemaCommon
392+ , _schemaSchemaCommon :: SchemaCommon SchemaType
406 } deriving (Eq, Show, Generic)
393 } deriving (Eq, Show, Generic)
407
394
408data SchemaItems
395data SchemaItems
@@ -410,7 +397,7 @@ data SchemaItems
410 | SchemaItemsArray [Referenced Schema]
397 | SchemaItemsArray [Referenced Schema]
411 deriving (Eq, Show)
398 deriving (Eq, Show)
412
399
413−data SchemaCommon = SchemaCommon
400+data SchemaCommon typeDomain = SchemaCommon
414 { -- | Declares the value of the parameter that the server will use if none is provided,
401 { -- | 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@
402 -- 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.
403 -- if not supplied by the client in the request.
@@ -418,6 +405,8 @@ data SchemaCommon = SchemaCommon
418 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
405 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
419 _schemaCommonDefault :: Maybe Value
406 _schemaCommonDefault :: Maybe Value
420
407
408+ , _schemaCommonType :: typeDomain
409+ , _schemaCommonFormat :: Maybe Format
421 , _schemaCommonMaximum :: Maybe Scientific
410 , _schemaCommonMaximum :: Maybe Scientific
422 , _schemaCommonExclusiveMaximum :: Maybe Bool
411 , _schemaCommonExclusiveMaximum :: Maybe Bool
423 , _schemaCommonMinimum :: Maybe Scientific
412 , _schemaCommonMinimum :: Maybe Scientific
@@ -461,21 +450,15 @@ data Xml = Xml
461 } deriving (Eq, Show, Generic)
450 } deriving (Eq, Show, Generic)
462
451
463data Items = Items
452data Items = Items
464− { -- | The internal type of the array.
465− _itemsType :: ItemsType
466−
467− -- | The extending format for the previously mentioned type.
468− , _itemsFormat :: Maybe Format
469−
470− -- | __Required if type is @'ItemsArray'@.__
453+ { -- | __Required if type is @'ItemsArray'@.__
471 -- Describes the type of items in the array.
454 -- Describes the type of items in the array.
472− , _itemsItems :: Maybe Items
455+ _itemsItems :: Maybe Items
473
456
474 -- | Determines the format of the array if type array is used.
457 -- | Determines the format of the array if type array is used.
475 -- Default value is @'ItemsCollectionCSV'@.
458 -- Default value is @'ItemsCollectionCSV'@.
476 , _itemsCollectionFormat :: Maybe ItemsCollectionFormat
459 , _itemsCollectionFormat :: Maybe ItemsCollectionFormat
477
460
478− , _itemsCommon :: SchemaCommon
461+ , _itemsCommon :: SchemaCommon ItemsType
479 } deriving (Eq, Show, Generic)
462 } deriving (Eq, Show, Generic)
480
463
481-- | A container for the expected responses of an operation.
464-- | A container for the expected responses of an operation.
@@ -521,12 +504,6 @@ data Header = Header
521 { -- | A short description of the header.
504 { -- | A short description of the header.
522 _headerDescription :: Maybe Text
505 _headerDescription :: Maybe Text
523
506
524− -- | The type of the object.
525− , _headerType :: ItemsType
526−
527− -- | The extending format for the previously mentioned type. See Data Type Formats for further details.
528− , _headerFormat :: Maybe Format
529−
530 -- | __Required if type is @'ItemsArray'@__.
507 -- | __Required if type is @'ItemsArray'@__.
531 -- Describes the type of items in the array.
508 -- Describes the type of items in the array.
532 , _headerItems :: Maybe Items
509 , _headerItems :: Maybe Items
@@ -535,7 +512,7 @@ data Header = Header
535 -- Default value is @'ItemsCollectionCSV'@.
512 -- Default value is @'ItemsCollectionCSV'@.
536 , _headerCollectionFormat :: Maybe ItemsCollectionFormat
513 , _headerCollectionFormat :: Maybe ItemsCollectionFormat
537
514
538− , _headerCommon :: SchemaCommon
515+ , _headerCommon :: SchemaCommon ItemsType
539 } deriving (Eq, Show, Generic)
516 } deriving (Eq, Show, Generic)
540
517
541data Example = Example { getExample :: Map MediaType Value }
518data Example = Example { getExample :: Map MediaType Value }
@@ -657,7 +634,7 @@ instance Monoid Schema where
657 mempty = genericMempty
634 mempty = genericMempty
658 mappend = genericMappend
635 mappend = genericMappend
659
636
660−instance Monoid SchemaCommon where
637+instance SwaggerMonoid t => Monoid (SchemaCommon t) where
661 mempty = genericMempty
638 mempty = genericMempty
662 mappend = genericMappend
639 mappend = genericMappend
663
640
@@ -693,7 +670,7 @@ instance SwaggerMonoid Info
693instance SwaggerMonoid Paths
670instance SwaggerMonoid Paths
694instance SwaggerMonoid PathItem
671instance SwaggerMonoid PathItem
695instance SwaggerMonoid Schema
672instance SwaggerMonoid Schema
696−instance SwaggerMonoid SchemaCommon
673+instance SwaggerMonoid t => SwaggerMonoid (SchemaCommon t)
697instance SwaggerMonoid Param
674instance SwaggerMonoid Param
698instance SwaggerMonoid ParamOtherSchema
675instance SwaggerMonoid ParamOtherSchema
699instance SwaggerMonoid Responses
676instance SwaggerMonoid Responses
src/Data/Swagger/Internal/Param.hs+15−15
@@ -34,17 +34,17 @@ class ToParamSchema a where
34instance {-# OVERLAPPING #-} ToParamSchema String where
34instance {-# OVERLAPPING #-} ToParamSchema String where
35 toParamSchema _ loc = mempty
35 toParamSchema _ loc = mempty
36 & paramOtherSchemaIn .~ loc
36 & paramOtherSchemaIn .~ loc
37− & paramOtherSchemaType .~ ParamString
37+ & schemaType .~ ParamString
38
38
39instance ToParamSchema Bool where
39instance ToParamSchema Bool where
40 toParamSchema _ loc = mempty
40 toParamSchema _ loc = mempty
41 & paramOtherSchemaIn .~ loc
41 & paramOtherSchemaIn .~ loc
42− & paramOtherSchemaType .~ ParamBoolean
42+ & schemaType .~ ParamBoolean
43
43
44instance ToParamSchema Integer where
44instance ToParamSchema Integer where
45 toParamSchema _ loc = mempty
45 toParamSchema _ loc = mempty
46 & paramOtherSchemaIn .~ loc
46 & paramOtherSchemaIn .~ loc
47− & paramOtherSchemaType .~ ParamInteger
47+ & schemaType .~ ParamInteger
48
48
49instance ToParamSchema Int where toParamSchema = toParamSchemaBoundedIntegral
49instance ToParamSchema Int where toParamSchema = toParamSchemaBoundedIntegral
50instance ToParamSchema Int8 where toParamSchema = toParamSchemaBoundedIntegral
50instance ToParamSchema Int8 where toParamSchema = toParamSchemaBoundedIntegral
@@ -61,59 +61,59 @@ instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
61toParamSchemaBoundedIntegral :: forall proxy a. (Bounded a, Integral a) => proxy a -> ParamLocation -> ParamOtherSchema
61toParamSchemaBoundedIntegral :: forall proxy a. (Bounded a, Integral a) => proxy a -> ParamLocation -> ParamOtherSchema
62toParamSchemaBoundedIntegral _ loc = mempty
62toParamSchemaBoundedIntegral _ loc = mempty
63 & paramOtherSchemaIn .~ loc
63 & paramOtherSchemaIn .~ loc
64− & paramOtherSchemaType .~ ParamInteger
64+ & schemaType .~ ParamInteger
65 & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
65 & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
66 & schemaMaximum ?~ fromInteger (toInteger (maxBound :: a))
66 & schemaMaximum ?~ fromInteger (toInteger (maxBound :: a))
67
67
68instance ToParamSchema Char where
68instance ToParamSchema Char where
69 toParamSchema _ loc = mempty
69 toParamSchema _ loc = mempty
70 & paramOtherSchemaIn .~ loc
70 & paramOtherSchemaIn .~ loc
71− & paramOtherSchemaType .~ ParamString
71+ & schemaType .~ ParamString
72 & schemaMaxLength ?~ 1
72 & schemaMaxLength ?~ 1
73 & schemaMinLength ?~ 1
73 & schemaMinLength ?~ 1
74
74
75instance ToParamSchema Scientific where
75instance ToParamSchema Scientific where
76 toParamSchema _ loc = mempty
76 toParamSchema _ loc = mempty
77 & paramOtherSchemaIn .~ loc
77 & paramOtherSchemaIn .~ loc
78− & paramOtherSchemaType .~ ParamNumber
78+ & schemaType .~ ParamNumber
79
79
80instance ToParamSchema Double where
80instance ToParamSchema Double where
81 toParamSchema _ loc = mempty
81 toParamSchema _ loc = mempty
82 & paramOtherSchemaIn .~ loc
82 & paramOtherSchemaIn .~ loc
83− & paramOtherSchemaType .~ ParamNumber
83+ & schemaType .~ ParamNumber
84
84
85instance ToParamSchema Float where
85instance ToParamSchema Float where
86 toParamSchema _ loc = mempty
86 toParamSchema _ loc = mempty
87 & paramOtherSchemaIn .~ loc
87 & paramOtherSchemaIn .~ loc
88− & paramOtherSchemaType .~ ParamNumber
88+ & schemaType .~ ParamNumber
89
89
90timeParamSchema :: String -> ParamLocation -> ParamOtherSchema
90timeParamSchema :: String -> ParamLocation -> ParamOtherSchema
91timeParamSchema format loc = mempty
91timeParamSchema format loc = mempty
92 & paramOtherSchemaIn .~ loc
92 & paramOtherSchemaIn .~ loc
93− & paramOtherSchemaType .~ ParamString
93+ & schemaType .~ ParamString
94− & paramOtherSchemaFormat ?~ T.pack format
94+ & schemaFormat ?~ T.pack format
95 & schemaMinLength ?~ toInteger (length format)
95 & schemaMinLength ?~ toInteger (length format)
96
96
97-- |
97-- |
98−-- >>> toParamSchema (Proxy :: Proxy Day) ParamQuery ^. paramOtherSchemaFormat
98+-- >>> toParamSchema (Proxy :: Proxy Day) ParamQuery ^. schemaFormat
99-- Just "yyyy-mm-dd"
99-- Just "yyyy-mm-dd"
100instance ToParamSchema Day where
100instance ToParamSchema Day where
101 toParamSchema _ = timeParamSchema "yyyy-mm-dd"
101 toParamSchema _ = timeParamSchema "yyyy-mm-dd"
102
102
103-- |
103-- |
104−-- >>> toParamSchema (Proxy :: Proxy LocalTime) ParamQuery ^. paramOtherSchemaFormat
104+-- >>> toParamSchema (Proxy :: Proxy LocalTime) ParamQuery ^. schemaFormat
105-- Just "yyyy-mm-ddThh:MM:ss"
105-- Just "yyyy-mm-ddThh:MM:ss"
106instance ToParamSchema LocalTime where
106instance ToParamSchema LocalTime where
107 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss"
107 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss"
108
108
109-- |
109-- |
110−-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ParamQuery ^. paramOtherSchemaFormat
110+-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ParamQuery ^. schemaFormat
111-- Just "yyyy-mm-ddThh:MM:ss+hhMM"
111-- Just "yyyy-mm-ddThh:MM:ss+hhMM"
112instance ToParamSchema ZonedTime where
112instance ToParamSchema ZonedTime where
113 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss+hhMM"
113 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss+hhMM"
114
114
115-- |
115-- |
116−-- >>> toParamSchema (Proxy :: Proxy UTCTime) ParamQuery ^. paramOtherSchemaFormat
116+-- >>> toParamSchema (Proxy :: Proxy UTCTime) ParamQuery ^. schemaFormat
117-- Just "yyyy-mm-ddThh:MM:ssZ"
117-- Just "yyyy-mm-ddThh:MM:ssZ"
118instance ToParamSchema UTCTime where
118instance ToParamSchema UTCTime where
119 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
119 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
@@ -162,7 +162,7 @@ instance (GEnumParamSchema f, GEnumParamSchema g) => GEnumParamSchema (f :+: g)
162instance Constructor c => GEnumParamSchema (C1 c U1) where
162instance Constructor c => GEnumParamSchema (C1 c U1) where
163 genumParamSchema opts _ loc s = s
163 genumParamSchema opts _ loc s = s
164 & paramOtherSchemaIn .~ loc
164 & paramOtherSchemaIn .~ loc
165− & paramOtherSchemaType .~ ParamString
165+ & schemaType .~ ParamString
166 & schemaEnum %~ addEnumValue tag
166 & schemaEnum %~ addEnumValue tag
167 where
167 where
168 tag = toJSON (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
168 tag = toJSON (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
src/Data/Swagger/Lens.hs+26−20
@@ -57,51 +57,57 @@ instance HasDescription Schema (Maybe Text) where description = schemaDe
57instance HasDescription SecurityScheme (Maybe Text) where description = securitySchemeDescription
57instance HasDescription SecurityScheme (Maybe Text) where description = securitySchemeDescription
58instance HasDescription ExternalDocs (Maybe Text) where description = externalDocsDescription
58instance HasDescription ExternalDocs (Maybe Text) where description = externalDocsDescription
59
59
60−class HasSchemaCommon s where
60+class HasSchemaCommon s t | s -> t where
61− schemaCommon :: Lens' s SchemaCommon
61+ schemaCommon :: Lens' s (SchemaCommon t)
62
62
63−instance HasSchemaCommon Schema where schemaCommon = schemaSchemaCommon
63+instance HasSchemaCommon Schema SchemaType where schemaCommon = schemaSchemaCommon
64−instance HasSchemaCommon ParamOtherSchema where schemaCommon = paramOtherSchemaCommon
64+instance HasSchemaCommon ParamOtherSchema ParamType where schemaCommon = paramOtherSchemaCommon
65−instance HasSchemaCommon Items where schemaCommon = itemsCommon
65+instance HasSchemaCommon Items ItemsType where schemaCommon = itemsCommon
66−instance HasSchemaCommon Header where schemaCommon = headerCommon
66+instance HasSchemaCommon Header ItemsType where schemaCommon = headerCommon
67−instance HasSchemaCommon SchemaCommon where schemaCommon = id
67+instance HasSchemaCommon (SchemaCommon t) t where schemaCommon = id
68
68
69+schemaType :: HasSchemaCommon s t => Lens' s t
70+schemaType = schemaCommon.schemaCommonType
71+
72+schemaFormat :: HasSchemaCommon s t => Lens' s (Maybe Format)
73+schemaFormat = schemaCommon.schemaCommonFormat
74+
69−schemaDefault :: HasSchemaCommon s => Lens' s (Maybe Value)
75+schemaDefault :: HasSchemaCommon s t => Lens' s (Maybe Value)
70schemaDefault = schemaCommon.schemaCommonDefault
76schemaDefault = schemaCommon.schemaCommonDefault
71
77
72−schemaMaximum :: HasSchemaCommon s => Lens' s (Maybe Scientific)
78+schemaMaximum :: HasSchemaCommon s t => Lens' s (Maybe Scientific)
73schemaMaximum = schemaCommon.schemaCommonMaximum
79schemaMaximum = schemaCommon.schemaCommonMaximum
74
80
75−schemaExclusiveMaximum :: HasSchemaCommon s => Lens' s (Maybe Bool)
81+schemaExclusiveMaximum :: HasSchemaCommon s t => Lens' s (Maybe Bool)
76schemaExclusiveMaximum = schemaCommon.schemaCommonExclusiveMaximum
82schemaExclusiveMaximum = schemaCommon.schemaCommonExclusiveMaximum
77
83
78−schemaMinimum :: HasSchemaCommon s => Lens' s (Maybe Scientific)
84+schemaMinimum :: HasSchemaCommon s t => Lens' s (Maybe Scientific)
79schemaMinimum = schemaCommon.schemaCommonMinimum
85schemaMinimum = schemaCommon.schemaCommonMinimum
80
86
81−schemaExclusiveMinimum :: HasSchemaCommon s => Lens' s (Maybe Bool)
87+schemaExclusiveMinimum :: HasSchemaCommon s t => Lens' s (Maybe Bool)
82schemaExclusiveMinimum = schemaCommon.schemaCommonExclusiveMinimum
88schemaExclusiveMinimum = schemaCommon.schemaCommonExclusiveMinimum
83
89
84−schemaMaxLength :: HasSchemaCommon s => Lens' s (Maybe Integer)
90+schemaMaxLength :: HasSchemaCommon s t => Lens' s (Maybe Integer)
85schemaMaxLength = schemaCommon.schemaCommonMaxLength
91schemaMaxLength = schemaCommon.schemaCommonMaxLength
86
92
87−schemaMinLength :: HasSchemaCommon s => Lens' s (Maybe Integer)
93+schemaMinLength :: HasSchemaCommon s t => Lens' s (Maybe Integer)
88schemaMinLength = schemaCommon.schemaCommonMinLength
94schemaMinLength = schemaCommon.schemaCommonMinLength
89
95
90−schemaPattern :: HasSchemaCommon s => Lens' s (Maybe Text)
96+schemaPattern :: HasSchemaCommon s t => Lens' s (Maybe Text)
91schemaPattern = schemaCommon.schemaCommonPattern
97schemaPattern = schemaCommon.schemaCommonPattern
92
98
93−schemaMaxItems :: HasSchemaCommon s => Lens' s (Maybe Integer)
99+schemaMaxItems :: HasSchemaCommon s t => Lens' s (Maybe Integer)
94schemaMaxItems = schemaCommon.schemaCommonMaxItems
100schemaMaxItems = schemaCommon.schemaCommonMaxItems
95
101
96−schemaMinItems :: HasSchemaCommon s => Lens' s (Maybe Integer)
102+schemaMinItems :: HasSchemaCommon s t => Lens' s (Maybe Integer)
97schemaMinItems = schemaCommon.schemaCommonMinItems
103schemaMinItems = schemaCommon.schemaCommonMinItems
98
104
99−schemaUniqueItems :: HasSchemaCommon s => Lens' s (Maybe Bool)
105+schemaUniqueItems :: HasSchemaCommon s t => Lens' s (Maybe Bool)
100schemaUniqueItems = schemaCommon.schemaCommonUniqueItems
106schemaUniqueItems = schemaCommon.schemaCommonUniqueItems
101
107
102−schemaEnum :: HasSchemaCommon s => Lens' s (Maybe [Value])
108+schemaEnum :: HasSchemaCommon s t => Lens' s (Maybe [Value])
103schemaEnum = schemaCommon.schemaCommonEnum
109schemaEnum = schemaCommon.schemaCommonEnum
104
110
105−schemaMultipleOf :: HasSchemaCommon s => Lens' s (Maybe Scientific)
111+schemaMultipleOf :: HasSchemaCommon s t => Lens' s (Maybe Scientific)
106schemaMultipleOf = schemaCommon.schemaCommonMultipleOf
112schemaMultipleOf = schemaCommon.schemaCommonMultipleOf
107
113
swagger2.cabal+1
@@ -57,6 +57,7 @@ test-suite spec
57 , containers
57 , containers
58 , unordered-containers
58 , unordered-containers
59 , vector
59 , vector
60+ , lens
60 other-modules:
61 other-modules:
61 SpecCommon
62 SpecCommon
62 Data.SwaggerSpec
63 Data.SwaggerSpec
test/Data/SwaggerSpec.hs+52−59
@@ -4,12 +4,15 @@
4{-# LANGUAGE QuasiQuotes #-}
4{-# LANGUAGE QuasiQuotes #-}
5module Data.SwaggerSpec where
5module Data.SwaggerSpec where
6
6
7+import Control.Lens
8+
7import Data.Aeson
9import Data.Aeson
8import Data.Aeson.QQ
10import Data.Aeson.QQ
9import Data.HashMap.Strict (HashMap)
11import Data.HashMap.Strict (HashMap)
10import Data.Text (Text)
12import Data.Text (Text)
11
13
12import Data.Swagger
14import Data.Swagger
15+import Data.Swagger.Lens
13import SpecCommon
16import SpecCommon
14import Test.Hspec
17import Test.Hspec
15
18
@@ -148,10 +151,10 @@ operationExample = mempty
148 , _paramSchema = ParamOther (stringSchema ParamFormData) }
151 , _paramSchema = ParamOther (stringSchema ParamFormData) }
149 ]
152 ]
150
153
154+ stringSchema :: ParamLocation -> ParamOtherSchema
151 stringSchema i = mempty
155 stringSchema i = mempty
152− { _paramOtherSchemaIn = i
156+ & paramOtherSchemaIn .~ i
153− , _paramOtherSchemaType = ParamString
157+ & schemaType .~ ParamString
154− }
155
158
156operationExampleJSON :: Value
159operationExampleJSON :: Value
157operationExampleJSON = [aesonQQ|
160operationExampleJSON = [aesonQQ|
@@ -217,9 +220,8 @@ operationExampleJSON = [aesonQQ|
217
220
218schemaPrimitiveExample :: Schema
221schemaPrimitiveExample :: Schema
219schemaPrimitiveExample = mempty
222schemaPrimitiveExample = mempty
220− { _schemaType = SchemaString
223+ & schemaType .~ SchemaString
221− , _schemaFormat = Just "email"
224+ & schemaFormat ?~ "email"
222− }
223
225
224schemaPrimitiveExampleJSON :: Value
226schemaPrimitiveExampleJSON :: Value
225schemaPrimitiveExampleJSON = [aesonQQ|
227schemaPrimitiveExampleJSON = [aesonQQ|
@@ -231,17 +233,15 @@ schemaPrimitiveExampleJSON = [aesonQQ|
231
233
232schemaSimpleModelExample :: Schema
234schemaSimpleModelExample :: Schema
233schemaSimpleModelExample = mempty
235schemaSimpleModelExample = mempty
234− { _schemaType = SchemaObject
236+ & schemaType .~ SchemaObject
235− , _schemaRequired = [ "name" ]
237+ & schemaRequired .~ [ "name" ]
236− , _schemaProperties =
238+ & schemaProperties .~
237− [ ("name", Inline mempty
239+ [ ("name", Inline (mempty & schemaType .~ SchemaString))
238− { _schemaType = SchemaString } )
239 , ("address", Ref (Reference "#/definitions/Address"))
240 , ("address", Ref (Reference "#/definitions/Address"))
240− , ("age", Inline mempty
241+ , ("age", Inline $ mempty
242+ & schemaMinimum ?~ 0
241− { _schemaType = SchemaInteger
243+ & schemaType .~ SchemaInteger
242− , _schemaFormat = Just "int32"
244+ & schemaFormat ?~ "int32" ) ]
243− , _schemaSchemaCommon = mempty
244− { _schemaCommonMinimum = Just 0 } } ) ] }
245
245
246schemaSimpleModelExampleJSON :: Value
246schemaSimpleModelExampleJSON :: Value
247schemaSimpleModelExampleJSON = [aesonQQ|
247schemaSimpleModelExampleJSON = [aesonQQ|
@@ -268,9 +268,8 @@ schemaSimpleModelExampleJSON = [aesonQQ|
268
268
269schemaModelDictExample :: Schema
269schemaModelDictExample :: Schema
270schemaModelDictExample = mempty
270schemaModelDictExample = mempty
271− { _schemaType = SchemaObject
271+ & schemaType .~ SchemaObject
272− , _schemaAdditionalProperties = Just mempty
272+ & schemaAdditionalProperties ?~ (mempty & schemaType .~ SchemaString)
273− { _schemaType = SchemaString } }
274
273
275schemaModelDictExampleJSON :: Value
274schemaModelDictExampleJSON :: Value
276schemaModelDictExampleJSON = [aesonQQ|
275schemaModelDictExampleJSON = [aesonQQ|
@@ -283,14 +282,12 @@ schemaModelDictExampleJSON = [aesonQQ|
283|]
282|]
284
283
285schemaWithExampleExample :: Schema
284schemaWithExampleExample :: Schema
286−schemaWithExampleExample = mempty
285+schemaWithExampleExample = (mempty & schemaType .~ SchemaObject)
287− { _schemaType = SchemaObject
288− , _schemaProperties =
286+ { _schemaProperties =
289− [ ("id", Inline mempty
287+ [ ("id", Inline $ mempty
290− { _schemaType = SchemaInteger
288+ & schemaType .~ SchemaInteger
291− , _schemaFormat = Just "int64" })
289+ & schemaFormat ?~ "int64" )
292− , ("name", Inline mempty
290+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ]
293− { _schemaType = SchemaString }) ]
294 , _schemaRequired = [ "name" ]
291 , _schemaRequired = [ "name" ]
295 , _schemaExample = Just [aesonQQ|
292 , _schemaExample = Just [aesonQQ|
296 {
293 {
@@ -329,21 +326,19 @@ schemaWithExampleExampleJSON = [aesonQQ|
329definitionsExample :: HashMap Text Schema
326definitionsExample :: HashMap Text Schema
330definitionsExample =
327definitionsExample =
331 [ ("Category", mempty
328 [ ("Category", mempty
332− { _schemaType = SchemaObject
329+ & schemaType .~ SchemaObject
333− , _schemaProperties =
330+ & schemaProperties .~
334− [ ("id", Inline mempty
331+ [ ("id", Inline $ mempty
335− { _schemaType = SchemaInteger
332+ & schemaType .~ SchemaInteger
336− , _schemaFormat = Just "int64" })
333+ & schemaFormat ?~ "int64")
337− , ("name", Inline mempty
334+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ] )
338− { _schemaType = SchemaString }) ] })
339 , ("Tag", mempty
335 , ("Tag", mempty
340− { _schemaType = SchemaObject
336+ & schemaType .~ SchemaObject
341− , _schemaProperties =
337+ & schemaProperties .~
342− [ ("id", Inline mempty
338+ [ ("id", Inline $ mempty
343− { _schemaType = SchemaInteger
339+ & schemaType .~ SchemaInteger
344− , _schemaFormat = Just "int64" })
340+ & schemaFormat ?~ "int64")
345− , ("name", Inline mempty
341+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ] ) ]
346− { _schemaType = SchemaString }) ] }) ]
347
342
348definitionsExampleJSON :: Value
343definitionsExampleJSON :: Value
349definitionsExampleJSON = [aesonQQ|
344definitionsExampleJSON = [aesonQQ|
@@ -385,18 +380,18 @@ paramsDefinitionExample =
385 { _paramName = "skip"
380 { _paramName = "skip"
386 , _paramDescription = Just "number of items to skip"
381 , _paramDescription = Just "number of items to skip"
387 , _paramRequired = Just True
382 , _paramRequired = Just True
388− , _paramSchema = ParamOther mempty
383+ , _paramSchema = ParamOther $ mempty
389− { _paramOtherSchemaIn = ParamQuery
384+ & paramOtherSchemaIn .~ ParamQuery
390− , _paramOtherSchemaType = ParamInteger
385+ & schemaType .~ ParamInteger
391− , _paramOtherSchemaFormat = Just "int32" } })
386+ & schemaFormat ?~ "int32" })
392 , ("limitParam", mempty
387 , ("limitParam", mempty
393 { _paramName = "limit"
388 { _paramName = "limit"
394 , _paramDescription = Just "max records to return"
389 , _paramDescription = Just "max records to return"
395 , _paramRequired = Just True
390 , _paramRequired = Just True
396− , _paramSchema = ParamOther mempty
391+ , _paramSchema = ParamOther $ mempty
397− { _paramOtherSchemaIn = ParamQuery
392+ & paramOtherSchemaIn .~ ParamQuery
398− , _paramOtherSchemaType = ParamInteger
393+ & schemaType .~ ParamInteger
399− , _paramOtherSchemaFormat = Just "int32" } }) ]
394+ & schemaFormat ?~ "int32" }) ]
400
395
401paramsDefinitionExampleJSON :: Value
396paramsDefinitionExampleJSON :: Value
402paramsDefinitionExampleJSON = [aesonQQ|
397paramsDefinitionExampleJSON = [aesonQQ|
@@ -500,20 +495,18 @@ swaggerExample = mempty
500 { _operationResponses = mempty
495 { _operationResponses = mempty
501 { _responsesResponses =
496 { _responsesResponses =
502 [ (200, Inline mempty
497 [ (200, Inline mempty
503− { _responseSchema = Just $ Inline mempty
498+ { _responseSchema = Just $ Inline (mempty & schemaType .~ SchemaObject)
504 { _schemaExample = Just [aesonQQ|
499 { _schemaExample = Just [aesonQQ|
505 {
500 {
506 "created": 100,
501 "created": 100,
507 "description": "get milk"
502 "description": "get milk"
508 } |]
503 } |]
509− , _schemaType = SchemaObject
510 , _schemaDescription = Just "This is some real Todo right here"
504 , _schemaDescription = Just "This is some real Todo right here"
511 , _schemaProperties =
505 , _schemaProperties =
512− [ ("created", Inline mempty
506+ [ ("created", Inline $ mempty
513− { _schemaType = SchemaInteger
507+ & schemaType .~ SchemaInteger
514− , _schemaFormat = Just "int32" })
508+ & schemaFormat ?~ "int32")
515− , ("description", Inline mempty
509+ , ("description", Inline (mempty & schemaType .~ SchemaString)) ] }
516− { _schemaType = SchemaString }) ] }
517 , _responseDescription = "OK" }) ] }
510 , _responseDescription = "OK" }) ] }
518 , _operationProduces = Just (MimeList [ "application/json" ])
511 , _operationProduces = Just (MimeList [ "application/json" ])
519 , _operationParameters =
512 , _operationParameters =
@@ -521,9 +514,9 @@ swaggerExample = mempty
521 { _paramRequired = Just True
514 { _paramRequired = Just True
522 , _paramName = "id"
515 , _paramName = "id"
523 , _paramDescription = Just "TodoId param"
516 , _paramDescription = Just "TodoId param"
524− , _paramSchema = ParamOther mempty
517+ , _paramSchema = ParamOther $ mempty
525− { _paramOtherSchemaIn = ParamPath
518+ & paramOtherSchemaIn .~ ParamPath
526− , _paramOtherSchemaType = ParamString } } ]
519+ & schemaType .~ ParamString } ]
527 , _operationTags = [ "todo" ] } }) ] } }
520 , _operationTags = [ "todo" ] } }) ] } }
528
521
529swaggerExampleJSON :: Value
522swaggerExampleJSON :: Value