@@ -1,6 +1,6 @@
1−{-# LANGUAGE CPP #-}
21{-# LANGUAGE DataKinds #-}
32{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE DeriveFunctor #-}
44{-# LANGUAGE DeriveGeneric #-}
55{-# LANGUAGE DeriveTraversable #-}
66{-# LANGUAGE FlexibleContexts #-}
@@ -14,7 +14,7 @@
1414{-# LANGUAGE TemplateHaskell #-}
1515{-# LANGUAGE TypeFamilies #-}
1616{-# LANGUAGE UndecidableInstances #-}
17−module Data.OpenApi.Internal where
17+module Data.Swagger.Internal where
1818
1919import Prelude ()
2020import Prelude.Compat
@@ -22,9 +22,6 @@ import Prelude.Compat
2222import Control.Applicative
2323import Control.Lens ((&), (.~), (?~))
2424import Data.Aeson hiding (Encoding)
25−#if MIN_VERSION_aeson(2,0,0)
26−import qualified Data.Aeson.KeyMap as KeyMap
27−#endif
2825import qualified Data.Aeson.Types as JSON
2926import Data.Data (Constr, Data (..), DataType, Fixity (..), Typeable,
3027 constrIndex, mkConstr, mkDataType)
@@ -49,56 +46,58 @@ import Text.Read (readMaybe)
4946import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
5047import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
5148
52−import Data.OpenApi.Aeson.Compat (deleteKey)
53−import Data.OpenApi.Internal.AesonUtils (AesonDefaultValue (..), HasSwaggerAesonOptions (..),
54− mkSwaggerAesonOptions, saoAdditionalPairs, saoSubObject,
55− sopSwaggerGenericParseJSON, sopSwaggerGenericToEncoding,
56− sopSwaggerGenericToJSON, sopSwaggerGenericToJSONWithOpts)
57−import Data.OpenApi.Internal.Utils
5849import Generics.SOP.TH (deriveGeneric)
50+import Data.Swagger.Internal.AesonUtils (sopSwaggerGenericToJSON
51+ ,sopSwaggerGenericToJSONWithOpts
52+ ,sopSwaggerGenericParseJSON
53+ ,HasSwaggerAesonOptions(..)
54+ ,AesonDefaultValue(..)
55+ ,mkSwaggerAesonOptions
56+ ,saoAdditionalPairs
57+ ,saoSubObject)
58+import Data.Swagger.Internal.Utils
59+import Data.Swagger.Internal.AesonUtils (sopSwaggerGenericToEncoding)
5960
6061-- $setup
6162-- >>> :seti -XDataKinds
6263-- >>> import Data.Aeson
63−-- >>> import Data.ByteString.Lazy.Char8 as BSL
64−-- >>> import Data.OpenApi.Internal.Utils
6564
6665-- | A list of definitions that can be used in references.
6766type Definitions = InsOrdHashMap Text
6867
6968-- | This is the root document object for the API specification.
70−data OpenApi = OpenApi
69+data Swagger = Swagger
7170 { -- | Provides metadata about the API.
7271 -- The metadata can be used by the clients if needed.
73− _openApiInfo :: Info
72+ _swaggerInfo :: Info
7473
7574 -- | An array of Server Objects, which provide connectivity information
7675 -- to a target server. If the servers property is not provided, or is an empty array,
7776 -- the default value would be a 'Server' object with a url value of @/@.
78− , _openApiServers :: [Server]
77+ , _swaggerServers :: [Server]
7978
8079 -- | The available paths and operations for the API.
81− , _openApiPaths :: InsOrdHashMap FilePath PathItem
80+ , _swaggerPaths :: InsOrdHashMap FilePath PathItem
8281
8382 -- | An element to hold various schemas for the specification.
84− , _openApiComponents :: Components
83+ , _swaggerComponents :: Components
8584
8685 -- | A declaration of which security mechanisms can be used across the API.
8786 -- The list of values includes alternative security requirement objects that can be used.
8887 -- Only one of the security requirement objects need to be satisfied to authorize a request.
8988 -- Individual operations can override this definition.
9089 -- To make security optional, an empty security requirement can be included in the array.
91− , _openApiSecurity :: [SecurityRequirement]
90+ , _swaggerSecurity :: [SecurityRequirement]
9291
9392 -- | A list of tags used by the specification with additional metadata.
9493 -- The order of the tags can be used to reflect on their order by the parsing tools.
9594 -- Not all tags that are used by the 'Operation' Object must be declared.
9695 -- The tags that are not declared MAY be organized randomly or based on the tools' logic.
9796 -- Each tag name in the list MUST be unique.
98− , _openApiTags :: InsOrdHashSet Tag
97+ , _swaggerTags :: InsOrdHashSet Tag
9998
10099 -- | Additional external documentation.
101− , _openApiExternalDocs :: Maybe ExternalDocs
100+ , _swaggerExternalDocs :: Maybe ExternalDocs
102101 } deriving (Eq, Show, Generic, Data, Typeable)
103102
104103-- | The object provides metadata about the API.
@@ -195,8 +194,8 @@ data Components = Components
195194 , _componentsParameters :: Definitions Param
196195 , _componentsExamples :: Definitions Example
197196 , _componentsRequestBodies :: Definitions RequestBody
198− , _componentsHeaders :: Definitions Header
199− , _componentsSecuritySchemes :: SecurityDefinitions
197+ , _componentsHeader :: Definitions Header
198+ , _componentsSecuritySchemes :: Definitions SecurityScheme
200199 , _componentsLinks :: Definitions Link
201200 , _componentsCallbacks :: Definitions Callback
202201 } deriving (Eq, Show, Generic, Data, Typeable)
@@ -337,11 +336,9 @@ data RequestBody = RequestBody
337336 -- | The content of the request body.
338337 -- The key is a media type or media type range and the value describes it.
339338 -- For requests that match multiple keys, only the most specific key is applicable.
340− -- e.g. @text/plain@ overrides @text/\*@
339+ -- e.g. @text/plain@ overrides @text/*@
341340 , _requestBodyContent :: InsOrdHashMap MediaType MediaTypeObject
342341
343− -- | Determines if the request body is required in the request.
344− -- Defaults to 'False'.
345342 , _requestBodyRequired :: Maybe Bool
346343 } deriving (Eq, Show, Generic, Data, Typeable)
347344
@@ -394,7 +391,7 @@ data Encoding = Encoding
394391 -- for other primitive types – @text/plain@; for object - @application/json@;
395392 -- for array – the default is defined based on the inner type.
396393 -- The value can be a specific media type (e.g. @application/json@),
397− -- a wildcard media type (e.g. @image/\*@), or a comma-separated list of the two types.
394+ -- a wildcard media type (e.g. @image/*@), or a comma-separated list of the two types.
398395 _encodingContentType :: Maybe MediaType
399396
400397 -- | A map allowing additional information to be provided as headers,
@@ -434,11 +431,11 @@ mimeListConstr :: Constr
434431mimeListConstr = mkConstr mimeListDataType "MimeList" ["getMimeList"] Prefix
435432
436433mimeListDataType :: DataType
437−mimeListDataType = mkDataType "Data.OpenApi.MimeList" [mimeListConstr]
434+mimeListDataType = mkDataType "Data.Swagger.MimeList" [mimeListConstr]
438435
439436instance Data MimeList where
440437 gunfold k z c = case constrIndex c of
441− 1 -> k (z (MimeList . map fromString))
438+ 1 -> k (z (\xs -> MimeList (map fromString xs)))
442439 _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type MimeList."
443440 toConstr (MimeList _) = mimeListConstr
444441 dataTypeOf _ = mimeListDataType
@@ -452,7 +449,7 @@ data Param = Param
452449
453450 -- | A brief description of the parameter.
454451 -- This could contain examples of use.
455− -- CommonMark syntax MAY be used for rich text representation.
452+ -- GFM syntax can be used for rich text representation.
456453 , _paramDescription :: Maybe Text
457454
458455 -- | Determines whether this parameter is mandatory.
@@ -472,13 +469,6 @@ data Param = Param
472469 -- a parameter with an empty value. Default value is @false@.
473470 , _paramAllowEmptyValue :: Maybe Bool
474471
475− -- | Determines whether the parameter value SHOULD allow reserved characters,
476− -- as defined by [RFC3986](https://tools.ietf.org/html/rfc3986#section-2.2)
477− -- @:/?#[]@!$&'()*+,;=@ to be included without percent-encoding.
478− -- This property only applies to parameters with an '_paramIn' value of 'ParamQuery'.
479− -- The default value is 'False'.
480− , _paramAllowReserved :: Maybe Bool
481−
482472 -- | Parameter schema.
483473 , _paramSchema :: Maybe (Referenced Schema)
484474
@@ -509,10 +499,6 @@ data Param = Param
509499 -- Furthermore, if referencing a schema that contains an example,
510500 -- the examples value SHALL override the example provided by the schema.
511501 , _paramExamples :: InsOrdHashMap Text (Referenced Example)
512−
513− -- TODO
514− -- _paramContent :: InsOrdHashMap MediaType MediaTypeObject
515− -- should be singleton. mutually exclusive with _paramSchema.
516502 } deriving (Eq, Show, Generic, Data, Typeable)
517503
518504data Example = Example
@@ -573,27 +559,27 @@ data Link = Link
573559 , _linkServer :: Maybe Server
574560 } deriving (Eq, Show, Generic, Typeable, Data)
575561
576−-- | Items for @'OpenApiArray'@ schemas.
562+-- | Items for @'SwaggerArray'@ schemas.
577563--
578564-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
579565-- it will incorporate Json Schema mostly verbatim.
580566--
581−-- @'OpenApiItemsObject'@ should be used to specify homogenous array @'Schema'@s.
567+-- @'SwaggerItemsObject'@ should be used to specify homogenous array @'Schema'@s.
582568--
583−-- @'OpenApiItemsArray'@ should be used to specify tuple @'Schema'@s.
584−data OpenApiItems where
585− OpenApiItemsObject :: Referenced Schema -> OpenApiItems
586− OpenApiItemsArray :: [Referenced Schema] -> OpenApiItems
569+-- @'SwaggerItemsArray'@ should be used to specify tuple @'Schema'@s.
570+data SwaggerItems where
571+ SwaggerItemsObject :: Referenced Schema -> SwaggerItems
572+ SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems
587573 deriving (Eq, Show, Typeable, Data)
588574
589−data OpenApiType where
590− OpenApiString :: OpenApiType
591− OpenApiNumber :: OpenApiType
592− OpenApiInteger :: OpenApiType
593− OpenApiBoolean :: OpenApiType
594− OpenApiArray :: OpenApiType
595− OpenApiNull :: OpenApiType
596− OpenApiObject :: OpenApiType
575+data SwaggerType where
576+ SwaggerString :: SwaggerType
577+ SwaggerNumber :: SwaggerType
578+ SwaggerInteger :: SwaggerType
579+ SwaggerBoolean :: SwaggerType
580+ SwaggerArray :: SwaggerType
581+ SwaggerNull :: SwaggerType
582+ SwaggerObject :: SwaggerType
597583 deriving (Eq, Show, Typeable, Generic, Data)
598584
599585data ParamLocation
@@ -638,33 +624,9 @@ data Schema = Schema
638624 , _schemaMaxProperties :: Maybe Integer
639625 , _schemaMinProperties :: Maybe Integer
640626
641− , -- | Declares the value of the parameter that the server will use if none is provided,
642− -- for example a @"count"@ to control the number of results per page might default to @100@
643− -- if not supplied by the client in the request.
644− -- (Note: "default" has no meaning for required parameters.)
645− -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
646− _schemaDefault :: Maybe Value
647−
648− , _schemaType :: Maybe OpenApiType
649− , _schemaFormat :: Maybe Format
650− , _schemaItems :: Maybe OpenApiItems
651− , _schemaMaximum :: Maybe Scientific
652− , _schemaExclusiveMaximum :: Maybe Bool
653− , _schemaMinimum :: Maybe Scientific
654− , _schemaExclusiveMinimum :: Maybe Bool
655− , _schemaMaxLength :: Maybe Integer
656− , _schemaMinLength :: Maybe Integer
657− , _schemaPattern :: Maybe Pattern
658− , _schemaMaxItems :: Maybe Integer
659− , _schemaMinItems :: Maybe Integer
660− , _schemaUniqueItems :: Maybe Bool
661− , _schemaEnum :: Maybe [Value]
662− , _schemaMultipleOf :: Maybe Scientific
627+ , _schemaParamSchema :: ParamSchema
663628 } deriving (Eq, Show, Generic, Data, Typeable)
664629
665−-- | Regex pattern for @string@ type.
666−type Pattern = Text
667−
668630data Discriminator = Discriminator
669631 { -- | The name of the property in the payload that will hold the discriminator value.
670632 _discriminatorPropertyName :: Text
@@ -680,9 +642,37 @@ data NamedSchema = NamedSchema
680642 , _namedSchemaSchema :: Schema
681643 } deriving (Eq, Show, Generic, Data, Typeable)
682644
645+-- | Regex pattern for @string@ type.
646+type Pattern = Text
647+
648+data ParamSchema = ParamSchema
649+ { -- | Declares the value of the parameter that the server will use if none is provided,
650+ -- for example a @"count"@ to control the number of results per page might default to @100@
651+ -- if not supplied by the client in the request.
652+ -- (Note: "default" has no meaning for required parameters.)
653+ -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
654+ _paramSchemaDefault :: Maybe Value
655+
656+ , _paramSchemaType :: Maybe SwaggerType
657+ , _paramSchemaFormat :: Maybe Format
658+ , _paramSchemaItems :: Maybe SwaggerItems
659+ , _paramSchemaMaximum :: Maybe Scientific
660+ , _paramSchemaExclusiveMaximum :: Maybe Bool
661+ , _paramSchemaMinimum :: Maybe Scientific
662+ , _paramSchemaExclusiveMinimum :: Maybe Bool
663+ , _paramSchemaMaxLength :: Maybe Integer
664+ , _paramSchemaMinLength :: Maybe Integer
665+ , _paramSchemaPattern :: Maybe Pattern
666+ , _paramSchemaMaxItems :: Maybe Integer
667+ , _paramSchemaMinItems :: Maybe Integer
668+ , _paramSchemaUniqueItems :: Maybe Bool
669+ , _paramSchemaEnum :: Maybe [Value]
670+ , _paramSchemaMultipleOf :: Maybe Scientific
671+ } deriving (Eq, Show, Generic, Typeable, Data)
672+
683673data Xml = Xml
684674 { -- | Replaces the name of the element/attribute used for the described schema property.
685− -- When defined within the @'OpenApiItems'@ (items), it will affect the name of the individual XML elements within the list.
675+ -- When defined within the @'SwaggerItems'@ (items), it will affect the name of the individual XML elements within the list.
686676 -- When defined alongside type being array (outside the items),
687677 -- it will affect the wrapping element and only if wrapped is true.
688678 -- If wrapped is false, it will be ignored.
@@ -734,7 +724,7 @@ data Response = Response
734724 -- | A map containing descriptions of potential response payloads.
735725 -- The key is a media type or media type range and the value describes it.
736726 -- For responses that match multiple keys, only the most specific key is applicable.
737− -- e.g. @text/plain@ overrides @text/\*@.
727+ -- e.g. @text/plain@ overrides @text/*@.
738728 , _responseContent :: InsOrdHashMap MediaType MediaTypeObject
739729
740730 -- | Maps a header name to its definition.
@@ -759,20 +749,11 @@ newtype Callback = Callback (InsOrdHashMap Text PathItem)
759749
760750type HeaderName = Text
761751
762−-- | Header fields have the same meaning as for 'Param'.
763−--
764−-- Style is always treated as 'StyleSimple', as it is the only value allowed for headers.
752+-- TODO this is mostly a copy of 'Param'.
765753data Header = Header
766754 { -- | A short description of the header.
767755 _headerDescription :: Maybe HeaderName
768756
769− , _headerRequired :: Maybe Bool
770− , _headerDeprecated :: Maybe Bool
771− , _headerAllowEmptyValue :: Maybe Bool
772− , _headerExplode :: Maybe Bool
773− , _headerExample :: Maybe Value
774− , _headerExamples :: InsOrdHashMap Text (Referenced Example)
775−
776757 , _headerSchema :: Maybe (Referenced Schema)
777758 } deriving (Eq, Show, Generic, Data, Typeable)
778759
@@ -797,17 +778,17 @@ type AuthorizationURL = Text
797778-- | The token URL to be used for OAuth2 flow. This SHOULD be in the form of a URL.
798779type TokenURL = Text
799780
800−newtype OAuth2ImplicitFlow
801− = OAuth2ImplicitFlow {_oAuth2ImplicitFlowAuthorizationUrl :: AuthorizationURL}
802− deriving (Eq, Show, Generic, Data, Typeable)
781+data OAuth2ImplicitFlow = OAuth2ImplicitFlow
782+ { _oAuth2ImplicitFlowAuthorizationUrl :: AuthorizationURL
783+ } deriving (Eq, Show, Generic, Data, Typeable)
803784
804−newtype OAuth2PasswordFlow
805− = OAuth2PasswordFlow {_oAuth2PasswordFlowTokenUrl :: TokenURL}
806− deriving (Eq, Show, Generic, Data, Typeable)
785+data OAuth2PasswordFlow = OAuth2PasswordFlow
786+ { _oAuth2PasswordFlowTokenUrl :: TokenURL
787+ } deriving (Eq, Show, Generic, Data, Typeable)
807788
808−newtype OAuth2ClientCredentialsFlow
809− = OAuth2ClientCredentialsFlow {_oAuth2ClientCredentialsFlowTokenUrl :: TokenURL}
810− deriving (Eq, Show, Generic, Data, Typeable)
789+data OAuth2ClientCredentialsFlow = OAuth2ClientCredentialsFlow
790+ { _oAuth2ClientCredentialsFlowTokenUrl :: TokenURL
791+ } deriving (Eq, Show, Generic, Data, Typeable)
811792
812793data OAuth2AuthorizationCodeFlow = OAuth2AuthorizationCodeFlow
813794 { _oAuth2AuthorizationCodeFlowAuthorizationUrl :: AuthorizationURL
@@ -840,50 +821,8 @@ data OAuth2Flows = OAuth2Flows
840821 , _oAuth2FlowsAuthorizationCode :: Maybe (OAuth2Flow OAuth2AuthorizationCodeFlow)
841822 } deriving (Eq, Show, Generic, Data, Typeable)
842823
843−type BearerFormat = Text
844−
845−data HttpSchemeType
846− = HttpSchemeBearer (Maybe BearerFormat)
847− | HttpSchemeBasic
848− | HttpSchemeCustom Text
849− deriving (Eq, Show, Generic, Data, Typeable)
850−
851−-- |
852−--
853−-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeHttp (HttpSchemeBearer Nothing))
854−-- {
855−-- "scheme": "bearer",
856−-- "type": "http"
857−-- }
858−--
859−-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeHttp (HttpSchemeBearer (Just "jwt")))
860−-- {
861−-- "bearerFormat": "jwt",
862−-- "scheme": "bearer",
863−-- "type": "http"
864−-- }
865−--
866−-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeHttp HttpSchemeBasic)
867−-- {
868−-- "scheme": "basic",
869−-- "type": "http"
870−-- }
871−--
872−-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeHttp (HttpSchemeCustom "CANARY"))
873−-- {
874−-- "scheme": "CANARY",
875−-- "type": "http"
876−-- }
877−--
878−-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeApiKey (ApiKeyParams "id" ApiKeyCookie))
879−-- {
880−-- "in": "cookie",
881−-- "name": "id",
882−-- "type": "apiKey"
883−-- }
884−--
885824data SecuritySchemeType
886− = SecuritySchemeHttp HttpSchemeType
825+ = SecuritySchemeHttp
887826 | SecuritySchemeApiKey ApiKeyParams
888827 | SecuritySchemeOAuth2 OAuth2Flows
889828 | SecuritySchemeOpenIdConnect URL
@@ -918,7 +857,7 @@ data Tag = Tag
918857 _tagName :: TagName
919858
920859 -- | A short description for the tag.
921− -- [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
860+ -- GFM syntax can be used for rich text representation.
922861 , _tagDescription :: Maybe Text
923862
924863 -- | Additional external documentation for this tag.
@@ -933,7 +872,7 @@ instance IsString Tag where
933872-- | Allows referencing an external resource for extended documentation.
934873data ExternalDocs = ExternalDocs
935874 { -- | A short description of the target documentation.
936− -- [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
875+ -- GFM syntax can be used for rich text representation.
937876 _externalDocsDescription :: Maybe Text
938877
939878 -- | The URL for the target documentation.
@@ -980,7 +919,8 @@ deriveGeneric ''MediaTypeObject
980919deriveGeneric ''Responses
981920deriveGeneric ''SecurityScheme
982921deriveGeneric ''Schema
983−deriveGeneric ''OpenApi
922+deriveGeneric ''ParamSchema
923+deriveGeneric ''Swagger
984924deriveGeneric ''Example
985925deriveGeneric ''Encoding
986926deriveGeneric ''Link
@@ -989,9 +929,9 @@ deriveGeneric ''Link
989929-- Monoid instances
990930-- =======================================================================
991931
992−instance Semigroup OpenApi where
932+instance Semigroup Swagger where
993933 (<>) = genericMappend
994−instance Monoid OpenApi where
934+instance Monoid Swagger where
995935 mempty = genericMempty
996936 mappend = (<>)
997937
@@ -1025,6 +965,12 @@ instance Monoid Schema where
1025965 mempty = genericMempty
1026966 mappend = (<>)
1027967
968+instance Semigroup ParamSchema where
969+ (<>) = genericMappend
970+instance Monoid ParamSchema where
971+ mempty = genericMempty
972+ mappend = (<>)
973+
1028974instance Semigroup Param where
1029975 (<>) = genericMappend
1030976instance Monoid Param where
@@ -1119,19 +1065,19 @@ instance SwaggerMonoid Info
11191065instance SwaggerMonoid Components
11201066instance SwaggerMonoid PathItem
11211067instance SwaggerMonoid Schema
1068+instance SwaggerMonoid ParamSchema
11221069instance SwaggerMonoid Param
11231070instance SwaggerMonoid Responses
11241071instance SwaggerMonoid Response
11251072instance SwaggerMonoid ExternalDocs
11261073instance SwaggerMonoid Operation
11271074instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
1128−instance SwaggerMonoid SecurityDefinitions
11291075
11301076instance SwaggerMonoid MimeList
11311077deriving instance SwaggerMonoid URL
11321078
1133−instance SwaggerMonoid OpenApiType where
1134− swaggerMempty = OpenApiString
1079+instance SwaggerMonoid SwaggerType where
1080+ swaggerMempty = SwaggerString
11351081 swaggerMappend _ y = y
11361082
11371083instance SwaggerMonoid ParamLocation where
@@ -1154,7 +1100,7 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
11541100instance ToJSON Style where
11551101 toJSON = genericToJSON (jsonPrefix "Style")
11561102
1157−instance ToJSON OpenApiType where
1103+instance ToJSON SwaggerType where
11581104 toJSON = genericToJSON (jsonPrefix "Swagger")
11591105
11601106instance ToJSON ParamLocation where
@@ -1209,7 +1155,7 @@ instance ToJSON OAuth2AuthorizationCodeFlow where
12091155instance FromJSON Style where
12101156 parseJSON = genericParseJSON (jsonPrefix "Style")
12111157
1212−instance FromJSON OpenApiType where
1158+instance FromJSON SwaggerType where
12131159 parseJSON = genericParseJSON (jsonPrefix "Swagger")
12141160
12151161instance FromJSON ParamLocation where
@@ -1274,19 +1220,8 @@ instance ToJSON OAuth2Flows where
12741220 toEncoding = sopSwaggerGenericToEncoding
12751221
12761222instance ToJSON SecuritySchemeType where
1277− toJSON (SecuritySchemeHttp ty) = case ty of
1278− HttpSchemeBearer mFmt ->
1279− object $ [ "type" .= ("http" :: Text)
1280− , "scheme" .= ("bearer" :: Text)
1281− ] <> maybe [] (\t -> ["bearerFormat" .= t]) mFmt
1282− HttpSchemeBasic ->
1283− object [ "type" .= ("http" :: Text)
1284− , "scheme" .= ("basic" :: Text)
1285− ]
1286− HttpSchemeCustom t ->
1287− object [ "type" .= ("http" :: Text)
1288− , "scheme" .= t
1289− ]
1223+ toJSON SecuritySchemeHttp
1224+ = object [ "type" .= ("http" :: Text) ]
12901225 toJSON (SecuritySchemeApiKey params)
12911226 = toJSON params
12921227 <+> object [ "type" .= ("apiKey" :: Text) ]
@@ -1299,9 +1234,9 @@ instance ToJSON SecuritySchemeType where
12991234 , "openIdConnectUrl" .= url
13001235 ]
13011236
1302−instance ToJSON OpenApi where
1237+instance ToJSON Swagger where
13031238 toJSON a = sopSwaggerGenericToJSON a &
1304− if InsOrdHashMap.null (_openApiPaths a)
1239+ if InsOrdHashMap.null (_swaggerPaths a)
13051240 then (<+> object ["paths" .= object []])
13061241 else id
13071242 toEncoding = sopSwaggerGenericToEncoding
@@ -1315,8 +1250,8 @@ instance ToJSON SecurityScheme where
13151250 toEncoding = sopSwaggerGenericToEncoding
13161251
13171252instance ToJSON Schema where
1318− toJSON = sopSwaggerGenericToJSONWithOpts $
1319− mkSwaggerAesonOptions "schema" & saoSubObject ?~ "items"
1253+ toJSON = sopSwaggerGenericToJSON
1254+ toEncoding = sopSwaggerGenericToEncoding
13201255
13211256instance ToJSON Header where
13221257 toJSON = sopSwaggerGenericToJSON
@@ -1325,21 +1260,17 @@ instance ToJSON Header where
13251260-- | As for nullary schema for 0-arity type constructors, see
13261261-- <https://github.com/GetShopTV/swagger2/issues/167>.
13271262--
1328−-- >>> BSL.putStrLn $ encodePretty (OpenApiItemsArray [])
1329−-- {
1330−-- "example": [],
1331−-- "items": {},
1332−-- "maxItems": 0
1333−-- }
1263+-- >>> encode (SwaggerItemsArray [])
1264+-- "{\"example\":[],\"items\":{},\"maxItems\":0}"
13341265--
1335−instance ToJSON OpenApiItems where
1336− toJSON (OpenApiItemsObject x) = object [ "items" .= x ]
1337− toJSON (OpenApiItemsArray []) = object
1266+instance ToJSON SwaggerItems where
1267+ toJSON (SwaggerItemsObject x) = object [ "items" .= x ]
1268+ toJSON (SwaggerItemsArray []) = object
13381269 [ "items" .= object []
13391270 , "maxItems" .= (0 :: Int)
13401271 , "example" .= Array mempty
13411272 ]
1342− toJSON (OpenApiItemsArray x) = object [ "items" .= x ]
1273+ toJSON (SwaggerItemsArray x) = object [ "items" .= x ]
13431274
13441275instance ToJSON Components where
13451276 toJSON = sopSwaggerGenericToJSON
@@ -1407,6 +1338,11 @@ instance ToJSON (Referenced Header) where toJSON = referencedToJSON "#/compone
14071338instance ToJSON (Referenced Link) where toJSON = referencedToJSON "#/components/links/"
14081339instance ToJSON (Referenced Callback) where toJSON = referencedToJSON "#/components/callbacks/"
14091340
1341+instance ToJSON ParamSchema where
1342+ -- TODO: this is a bit fishy, why we need sub object only in `ToJSON`?
1343+ toJSON = sopSwaggerGenericToJSONWithOpts $
1344+ mkSwaggerAesonOptions "paramSchema" & saoSubObject ?~ "items"
1345+
14101346instance ToJSON AdditionalProperties where
14111347 toJSON (AdditionalPropertiesAllowed b) = toJSON b
14121348 toJSON (AdditionalPropertiesSchema s) = toJSON s
@@ -1439,19 +1375,14 @@ instance FromJSON SecuritySchemeType where
14391375 parseJSON js@(Object o) = do
14401376 (t :: Text) <- o .: "type"
14411377 case t of
1442− "http" -> do
1443− scheme <- o .: "scheme"
1444− SecuritySchemeHttp <$> case scheme of
1445− "bearer" -> HttpSchemeBearer <$> (o .:! "bearerFormat")
1446− "basic" -> pure HttpSchemeBasic
1447− t -> pure $ HttpSchemeCustom t
1378+ "http" -> pure SecuritySchemeHttp
14481379 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
14491380 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
14501381 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
14511382 _ -> empty
14521383 parseJSON _ = empty
14531384
1454−instance FromJSON OpenApi where
1385+instance FromJSON Swagger where
14551386 parseJSON = sopSwaggerGenericParseJSON
14561387
14571388instance FromJSON Server where
@@ -1463,28 +1394,27 @@ instance FromJSON SecurityScheme where
14631394instance FromJSON Schema where
14641395 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
14651396 where nullaryCleanup :: Schema -> Schema
1466− nullaryCleanup s =
1467− if _schemaItems s == Just (OpenApiItemsArray [])
1397+ nullaryCleanup s@Schema{_schemaParamSchema=ps} =
1398+ if _paramSchemaItems ps == Just (SwaggerItemsArray [])
14681399 then s { _schemaExample = Nothing
1469− , _schemaMaxItems = Nothing
1470− }
1400+ , _schemaParamSchema = ps { _paramSchemaMaxItems = Nothing } }
14711401 else s
14721402
14731403instance FromJSON Header where
14741404 parseJSON = sopSwaggerGenericParseJSON
14751405
1476−instance FromJSON OpenApiItems where
1406+instance FromJSON SwaggerItems where
14771407 parseJSON js@(Object obj)
1478− | null obj = pure $ OpenApiItemsArray [] -- Nullary schema.
1479− | otherwise = OpenApiItemsObject <$> parseJSON js
1480− parseJSON js@(Array _) = OpenApiItemsArray <$> parseJSON js
1408+ | null obj = pure $ SwaggerItemsArray [] -- Nullary schema.
1409+ | otherwise = SwaggerItemsObject <$> parseJSON js
1410+ parseJSON js@(Array _) = SwaggerItemsArray <$> parseJSON js
14811411 parseJSON _ = empty
14821412
14831413instance FromJSON Components where
14841414 parseJSON = sopSwaggerGenericParseJSON
14851415
14861416instance FromJSON MimeList where
1487− parseJSON js = MimeList . map fromString <$> parseJSON js
1417+ parseJSON js = (MimeList . map fromString) <$> parseJSON js
14881418
14891419instance FromJSON Param where
14901420 parseJSON = sopSwaggerGenericParseJSON
@@ -1492,7 +1422,7 @@ instance FromJSON Param where
14921422instance FromJSON Responses where
14931423 parseJSON (Object o) = Responses
14941424 <$> o .:? "default"
1495− <*> parseJSON (Object (deleteKey "default" o))
1425+ <*> (parseJSON (Object (HashMap.delete "default" o)))
14961426 parseJSON _ = empty
14971427
14981428instance FromJSON Example where
@@ -1551,6 +1481,9 @@ instance FromJSON (Referenced Callback) where parseJSON = referencedParseJSON "#
15511481instance FromJSON Xml where
15521482 parseJSON = genericParseJSON (jsonPrefix "xml")
15531483
1484+instance FromJSON ParamSchema where
1485+ parseJSON = sopSwaggerGenericParseJSON
1486+
15541487instance FromJSON AdditionalProperties where
15551488 parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
15561489 parseJSON js = AdditionalPropertiesSchema <$> parseJSON js
@@ -1591,7 +1524,7 @@ instance HasSwaggerAesonOptions SecurityScheme where
15911524 swaggerAesonOptions _ = mkSwaggerAesonOptions "securityScheme" & saoSubObject ?~ "type"
15921525instance HasSwaggerAesonOptions Schema where
15931526 swaggerAesonOptions _ = mkSwaggerAesonOptions "schema" & saoSubObject ?~ "paramSchema"
1594−instance HasSwaggerAesonOptions OpenApi where
1527+instance HasSwaggerAesonOptions Swagger where
15951528 swaggerAesonOptions _ = mkSwaggerAesonOptions "swagger" & saoAdditionalPairs .~ [("openapi", "3.0.0")]
15961529instance HasSwaggerAesonOptions Example where
15971530 swaggerAesonOptions _ = mkSwaggerAesonOptions "example"
@@ -1601,8 +1534,12 @@ instance HasSwaggerAesonOptions Encoding where
16011534instance HasSwaggerAesonOptions Link where
16021535 swaggerAesonOptions _ = mkSwaggerAesonOptions "link"
16031536
1537+instance HasSwaggerAesonOptions ParamSchema where
1538+ swaggerAesonOptions _ = mkSwaggerAesonOptions "paramSchema"
1539+
16041540instance AesonDefaultValue Server
16051541instance AesonDefaultValue Components
1542+instance AesonDefaultValue ParamSchema
16061543instance AesonDefaultValue OAuth2ImplicitFlow
16071544instance AesonDefaultValue OAuth2PasswordFlow
16081545instance AesonDefaultValue OAuth2ClientCredentialsFlow
@@ -1610,10 +1547,8 @@ instance AesonDefaultValue OAuth2AuthorizationCodeFlow
16101547instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
16111548instance AesonDefaultValue Responses
16121549instance AesonDefaultValue SecuritySchemeType
1613−instance AesonDefaultValue OpenApiType
1550+instance AesonDefaultValue SwaggerType
16141551instance AesonDefaultValue MimeList where defaultValue = Just mempty
16151552instance AesonDefaultValue Info
16161553instance AesonDefaultValue ParamLocation
16171554instance AesonDefaultValue Link
1618−instance AesonDefaultValue SecurityDefinitions where
1619− defaultValue = Just mempty