@@ -1,6 +1,6 @@
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveDataTypeable #-}
3−{-# LANGUAGE DeriveFunctor #-}
4{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE DeriveGeneric #-}
5{-# LANGUAGE DeriveTraversable #-}
5{-# LANGUAGE DeriveTraversable #-}
6{-# LANGUAGE FlexibleContexts #-}
6{-# LANGUAGE FlexibleContexts #-}
@@ -14,7 +14,7 @@
14{-# LANGUAGE TemplateHaskell #-}
14{-# LANGUAGE TemplateHaskell #-}
15{-# LANGUAGE TypeFamilies #-}
15{-# LANGUAGE TypeFamilies #-}
16{-# LANGUAGE UndecidableInstances #-}
16{-# LANGUAGE UndecidableInstances #-}
17−module Data.Swagger.Internal where
17+module Data.OpenApi.Internal where
19import Prelude ()
19import Prelude ()
20import Prelude.Compat
20import Prelude.Compat
@@ -22,6 +22,9 @@ import Prelude.Compat
22import Control.Applicative
22import Control.Applicative
23import Control.Lens ((&), (.~), (?~))
23import Control.Lens ((&), (.~), (?~))
24import Data.Aeson hiding (Encoding)
24import Data.Aeson hiding (Encoding)
25+#if MIN_VERSION_aeson(2,0,0)
26+import qualified Data.Aeson.KeyMap as KeyMap
25import qualified Data.Aeson.Types as JSON
28import qualified Data.Aeson.Types as JSON
26import Data.Data (Constr, Data (..), DataType, Fixity (..), Typeable,
29import Data.Data (Constr, Data (..), DataType, Fixity (..), Typeable,
27 constrIndex, mkConstr, mkDataType)
30 constrIndex, mkConstr, mkDataType)
@@ -46,58 +49,56 @@ import Text.Read (readMaybe)
46import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
49import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
47import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
50import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
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
49import Generics.SOP.TH (deriveGeneric)
58import Generics.SOP.TH (deriveGeneric)
50−import Data.Swagger.Internal.AesonUtils (sopSwaggerGenericToJSON
51− ,sopSwaggerGenericToJSONWithOpts
52− ,sopSwaggerGenericParseJSON
53− ,HasSwaggerAesonOptions(..)
54− ,AesonDefaultValue(..)
55− ,mkSwaggerAesonOptions
58−import Data.Swagger.Internal.Utils
59−import Data.Swagger.Internal.AesonUtils (sopSwaggerGenericToEncoding)
62-- >>> :seti -XDataKinds
61-- >>> :seti -XDataKinds
63-- >>> import Data.Aeson
62-- >>> import Data.Aeson
63+-- >>> import Data.ByteString.Lazy.Char8 as BSL
64+-- >>> import Data.OpenApi.Internal.Utils
65-- | A list of definitions that can be used in references.
66-- | A list of definitions that can be used in references.
66type Definitions = InsOrdHashMap Text
67type Definitions = InsOrdHashMap Text
68-- | This is the root document object for the API specification.
69-- | This is the root document object for the API specification.
69−data Swagger = Swagger
70+data OpenApi = OpenApi
70 { -- | Provides metadata about the API.
71 { -- | Provides metadata about the API.
71 -- The metadata can be used by the clients if needed.
72 -- The metadata can be used by the clients if needed.
72− _swaggerInfo :: Info
73+ _openApiInfo :: Info
74 -- | An array of Server Objects, which provide connectivity information
75 -- | An array of Server Objects, which provide connectivity information
75 -- to a target server. If the servers property is not provided, or is an empty array,
76 -- to a target server. If the servers property is not provided, or is an empty array,
76 -- the default value would be a 'Server' object with a url value of @/@.
77 -- the default value would be a 'Server' object with a url value of @/@.
77− , _swaggerServers :: [Server]
78+ , _openApiServers :: [Server]
79 -- | The available paths and operations for the API.
80 -- | The available paths and operations for the API.
80− , _swaggerPaths :: InsOrdHashMap FilePath PathItem
81+ , _openApiPaths :: InsOrdHashMap FilePath PathItem
82 -- | An element to hold various schemas for the specification.
83 -- | An element to hold various schemas for the specification.
83− , _swaggerComponents :: Components
84+ , _openApiComponents :: Components
85 -- | A declaration of which security mechanisms can be used across the API.
86 -- | A declaration of which security mechanisms can be used across the API.
86 -- The list of values includes alternative security requirement objects that can be used.
87 -- The list of values includes alternative security requirement objects that can be used.
87 -- Only one of the security requirement objects need to be satisfied to authorize a request.
88 -- Only one of the security requirement objects need to be satisfied to authorize a request.
88 -- Individual operations can override this definition.
89 -- Individual operations can override this definition.
89 -- To make security optional, an empty security requirement can be included in the array.
90 -- To make security optional, an empty security requirement can be included in the array.
90− , _swaggerSecurity :: [SecurityRequirement]
91+ , _openApiSecurity :: [SecurityRequirement]
92 -- | A list of tags used by the specification with additional metadata.
93 -- | A list of tags used by the specification with additional metadata.
93 -- The order of the tags can be used to reflect on their order by the parsing tools.
94 -- The order of the tags can be used to reflect on their order by the parsing tools.
94 -- Not all tags that are used by the 'Operation' Object must be declared.
95 -- Not all tags that are used by the 'Operation' Object must be declared.
95 -- The tags that are not declared MAY be organized randomly or based on the tools' logic.
96 -- The tags that are not declared MAY be organized randomly or based on the tools' logic.
96 -- Each tag name in the list MUST be unique.
97 -- Each tag name in the list MUST be unique.
97− , _swaggerTags :: InsOrdHashSet Tag
98+ , _openApiTags :: InsOrdHashSet Tag
99 -- | Additional external documentation.
100 -- | Additional external documentation.
100− , _swaggerExternalDocs :: Maybe ExternalDocs
101+ , _openApiExternalDocs :: Maybe ExternalDocs
101 } deriving (Eq, Show, Generic, Data, Typeable)
102 } deriving (Eq, Show, Generic, Data, Typeable)
103-- | The object provides metadata about the API.
104-- | The object provides metadata about the API.
@@ -194,8 +195,8 @@ data Components = Components
194 , _componentsParameters :: Definitions Param
195 , _componentsParameters :: Definitions Param
195 , _componentsExamples :: Definitions Example
196 , _componentsExamples :: Definitions Example
196 , _componentsRequestBodies :: Definitions RequestBody
197 , _componentsRequestBodies :: Definitions RequestBody
197− , _componentsHeader :: Definitions Header
198+ , _componentsHeaders :: Definitions Header
198− , _componentsSecuritySchemes :: Definitions SecurityScheme
199+ , _componentsSecuritySchemes :: SecurityDefinitions
199 , _componentsLinks :: Definitions Link
200 , _componentsLinks :: Definitions Link
200 , _componentsCallbacks :: Definitions Callback
201 , _componentsCallbacks :: Definitions Callback
201 } deriving (Eq, Show, Generic, Data, Typeable)
202 } deriving (Eq, Show, Generic, Data, Typeable)
@@ -336,9 +337,11 @@ data RequestBody = RequestBody
336 -- | The content of the request body.
337 -- | The content of the request body.
337 -- The key is a media type or media type range and the value describes it.
338 -- The key is a media type or media type range and the value describes it.
338 -- For requests that match multiple keys, only the most specific key is applicable.
339 -- For requests that match multiple keys, only the most specific key is applicable.
339− -- e.g. @text/plain@ overrides @text/*@
340+ -- e.g. @text/plain@ overrides @text/\*@
340 , _requestBodyContent :: InsOrdHashMap MediaType MediaTypeObject
341 , _requestBodyContent :: InsOrdHashMap MediaType MediaTypeObject
343+ -- | Determines if the request body is required in the request.
344+ -- Defaults to 'False'.
342 , _requestBodyRequired :: Maybe Bool
345 , _requestBodyRequired :: Maybe Bool
343 } deriving (Eq, Show, Generic, Data, Typeable)
346 } deriving (Eq, Show, Generic, Data, Typeable)
@@ -391,7 +394,7 @@ data Encoding = Encoding
391 -- for other primitive types – @text/plain@; for object - @application/json@;
394 -- for other primitive types – @text/plain@; for object - @application/json@;
392 -- for array – the default is defined based on the inner type.
395 -- for array – the default is defined based on the inner type.
393 -- The value can be a specific media type (e.g. @application/json@),
396 -- The value can be a specific media type (e.g. @application/json@),
394− -- a wildcard media type (e.g. @image/*@), or a comma-separated list of the two types.
397+ -- a wildcard media type (e.g. @image/\*@), or a comma-separated list of the two types.
395 _encodingContentType :: Maybe MediaType
398 _encodingContentType :: Maybe MediaType
397 -- | A map allowing additional information to be provided as headers,
400 -- | A map allowing additional information to be provided as headers,
@@ -431,11 +434,11 @@ mimeListConstr :: Constr
431mimeListConstr = mkConstr mimeListDataType "MimeList" ["getMimeList"] Prefix
434mimeListConstr = mkConstr mimeListDataType "MimeList" ["getMimeList"] Prefix
433mimeListDataType :: DataType
436mimeListDataType :: DataType
434−mimeListDataType = mkDataType "Data.Swagger.MimeList" [mimeListConstr]
437+mimeListDataType = mkDataType "Data.OpenApi.MimeList" [mimeListConstr]
436instance Data MimeList where
439instance Data MimeList where
437 gunfold k z c = case constrIndex c of
440 gunfold k z c = case constrIndex c of
438− 1 -> k (z (\xs -> MimeList (map fromString xs)))
441+ 1 -> k (z (MimeList . map fromString))
439 _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type MimeList."
442 _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type MimeList."
440 toConstr (MimeList _) = mimeListConstr
443 toConstr (MimeList _) = mimeListConstr
441 dataTypeOf _ = mimeListDataType
444 dataTypeOf _ = mimeListDataType
@@ -449,7 +452,7 @@ data Param = Param
450 -- | A brief description of the parameter.
453 -- | A brief description of the parameter.
451 -- This could contain examples of use.
454 -- This could contain examples of use.
452− -- GFM syntax can be used for rich text representation.
455+ -- CommonMark syntax MAY be used for rich text representation.
453 , _paramDescription :: Maybe Text
456 , _paramDescription :: Maybe Text
455 -- | Determines whether this parameter is mandatory.
458 -- | Determines whether this parameter is mandatory.
@@ -469,6 +472,13 @@ data Param = Param
469 -- a parameter with an empty value. Default value is @false@.
472 -- a parameter with an empty value. Default value is @false@.
470 , _paramAllowEmptyValue :: Maybe Bool
473 , _paramAllowEmptyValue :: Maybe Bool
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
472 -- | Parameter schema.
482 -- | Parameter schema.
473 , _paramSchema :: Maybe (Referenced Schema)
483 , _paramSchema :: Maybe (Referenced Schema)
@@ -499,6 +509,10 @@ data Param = Param
499 -- Furthermore, if referencing a schema that contains an example,
509 -- Furthermore, if referencing a schema that contains an example,
500 -- the examples value SHALL override the example provided by the schema.
510 -- the examples value SHALL override the example provided by the schema.
501 , _paramExamples :: InsOrdHashMap Text (Referenced Example)
511 , _paramExamples :: InsOrdHashMap Text (Referenced Example)
514+ -- _paramContent :: InsOrdHashMap MediaType MediaTypeObject
515+ -- should be singleton. mutually exclusive with _paramSchema.
502 } deriving (Eq, Show, Generic, Data, Typeable)
516 } deriving (Eq, Show, Generic, Data, Typeable)
504data Example = Example
518data Example = Example
@@ -559,27 +573,27 @@ data Link = Link
559 , _linkServer :: Maybe Server
573 , _linkServer :: Maybe Server
560 } deriving (Eq, Show, Generic, Typeable, Data)
574 } deriving (Eq, Show, Generic, Typeable, Data)
562−-- | Items for @'SwaggerArray'@ schemas.
576+-- | Items for @'OpenApiArray'@ schemas.
564-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
578-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
565-- it will incorporate Json Schema mostly verbatim.
579-- it will incorporate Json Schema mostly verbatim.
567−-- @'SwaggerItemsObject'@ should be used to specify homogenous array @'Schema'@s.
581+-- @'OpenApiItemsObject'@ should be used to specify homogenous array @'Schema'@s.
569−-- @'SwaggerItemsArray'@ should be used to specify tuple @'Schema'@s.
583+-- @'OpenApiItemsArray'@ should be used to specify tuple @'Schema'@s.
570−data SwaggerItems where
584+data OpenApiItems where
571− SwaggerItemsObject :: Referenced Schema -> SwaggerItems
585+ OpenApiItemsObject :: Referenced Schema -> OpenApiItems
572− SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems
586+ OpenApiItemsArray :: [Referenced Schema] -> OpenApiItems
573 deriving (Eq, Show, Typeable, Data)
587 deriving (Eq, Show, Typeable, Data)
575−data SwaggerType where
589+data OpenApiType where
576− SwaggerString :: SwaggerType
590+ OpenApiString :: OpenApiType
577− SwaggerNumber :: SwaggerType
591+ OpenApiNumber :: OpenApiType
578− SwaggerInteger :: SwaggerType
592+ OpenApiInteger :: OpenApiType
579− SwaggerBoolean :: SwaggerType
593+ OpenApiBoolean :: OpenApiType
580− SwaggerArray :: SwaggerType
594+ OpenApiArray :: OpenApiType
581− SwaggerNull :: SwaggerType
595+ OpenApiNull :: OpenApiType
582− SwaggerObject :: SwaggerType
596+ OpenApiObject :: OpenApiType
583 deriving (Eq, Show, Typeable, Generic, Data)
597 deriving (Eq, Show, Typeable, Generic, Data)
585data ParamLocation
599data ParamLocation
@@ -624,9 +638,33 @@ data Schema = Schema
624 , _schemaMaxProperties :: Maybe Integer
638 , _schemaMaxProperties :: Maybe Integer
625 , _schemaMinProperties :: Maybe Integer
639 , _schemaMinProperties :: Maybe Integer
627− , _schemaParamSchema :: ParamSchema
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
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
628 } deriving (Eq, Show, Generic, Data, Typeable)
663 } deriving (Eq, Show, Generic, Data, Typeable)
665+-- | Regex pattern for @string@ type.
630data Discriminator = Discriminator
668data Discriminator = Discriminator
631 { -- | The name of the property in the payload that will hold the discriminator value.
669 { -- | The name of the property in the payload that will hold the discriminator value.
632 _discriminatorPropertyName :: Text
670 _discriminatorPropertyName :: Text
@@ -642,37 +680,9 @@ data NamedSchema = NamedSchema
642 , _namedSchemaSchema :: Schema
680 , _namedSchemaSchema :: Schema
643 } deriving (Eq, Show, Generic, Data, Typeable)
681 } deriving (Eq, Show, Generic, Data, Typeable)
645−-- | Regex pattern for @string@ type.
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
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)
673data Xml = Xml
683data Xml = Xml
674 { -- | Replaces the name of the element/attribute used for the described schema property.
684 { -- | Replaces the name of the element/attribute used for the described schema property.
675− -- When defined within the @'SwaggerItems'@ (items), it will affect the name of the individual XML elements within the list.
685+ -- When defined within the @'OpenApiItems'@ (items), it will affect the name of the individual XML elements within the list.
676 -- When defined alongside type being array (outside the items),
686 -- When defined alongside type being array (outside the items),
677 -- it will affect the wrapping element and only if wrapped is true.
687 -- it will affect the wrapping element and only if wrapped is true.
678 -- If wrapped is false, it will be ignored.
688 -- If wrapped is false, it will be ignored.
@@ -724,7 +734,7 @@ data Response = Response
724 -- | A map containing descriptions of potential response payloads.
734 -- | A map containing descriptions of potential response payloads.
725 -- The key is a media type or media type range and the value describes it.
735 -- The key is a media type or media type range and the value describes it.
726 -- For responses that match multiple keys, only the most specific key is applicable.
736 -- For responses that match multiple keys, only the most specific key is applicable.
727− -- e.g. @text/plain@ overrides @text/*@.
737+ -- e.g. @text/plain@ overrides @text/\*@.
728 , _responseContent :: InsOrdHashMap MediaType MediaTypeObject
738 , _responseContent :: InsOrdHashMap MediaType MediaTypeObject
730 -- | Maps a header name to its definition.
740 -- | Maps a header name to its definition.
@@ -749,11 +759,20 @@ newtype Callback = Callback (InsOrdHashMap Text PathItem)
750type HeaderName = Text
760type HeaderName = Text
752−-- TODO this is mostly a copy of 'Param'.
762+-- | Header fields have the same meaning as for 'Param'.
764+-- Style is always treated as 'StyleSimple', as it is the only value allowed for headers.
753data Header = Header
765data Header = Header
754 { -- | A short description of the header.
766 { -- | A short description of the header.
755 _headerDescription :: Maybe HeaderName
767 _headerDescription :: Maybe HeaderName
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)
757 , _headerSchema :: Maybe (Referenced Schema)
776 , _headerSchema :: Maybe (Referenced Schema)
758 } deriving (Eq, Show, Generic, Data, Typeable)
777 } deriving (Eq, Show, Generic, Data, Typeable)
@@ -778,17 +797,17 @@ type AuthorizationURL = Text
778-- | The token URL to be used for OAuth2 flow. This SHOULD be in the form of a URL.
797-- | The token URL to be used for OAuth2 flow. This SHOULD be in the form of a URL.
779type TokenURL = Text
798type TokenURL = Text
781−data OAuth2ImplicitFlow = OAuth2ImplicitFlow
800+newtype OAuth2ImplicitFlow
782− { _oAuth2ImplicitFlowAuthorizationUrl :: AuthorizationURL
801+ = OAuth2ImplicitFlow {_oAuth2ImplicitFlowAuthorizationUrl :: AuthorizationURL}
783− } deriving (Eq, Show, Generic, Data, Typeable)
802+ deriving (Eq, Show, Generic, Data, Typeable)
785−data OAuth2PasswordFlow = OAuth2PasswordFlow
804+newtype OAuth2PasswordFlow
786− { _oAuth2PasswordFlowTokenUrl :: TokenURL
805+ = OAuth2PasswordFlow {_oAuth2PasswordFlowTokenUrl :: TokenURL}
787− } deriving (Eq, Show, Generic, Data, Typeable)
806+ deriving (Eq, Show, Generic, Data, Typeable)
789−data OAuth2ClientCredentialsFlow = OAuth2ClientCredentialsFlow
808+newtype OAuth2ClientCredentialsFlow
790− { _oAuth2ClientCredentialsFlowTokenUrl :: TokenURL
809+ = OAuth2ClientCredentialsFlow {_oAuth2ClientCredentialsFlowTokenUrl :: TokenURL}
791− } deriving (Eq, Show, Generic, Data, Typeable)
810+ deriving (Eq, Show, Generic, Data, Typeable)
793data OAuth2AuthorizationCodeFlow = OAuth2AuthorizationCodeFlow
812data OAuth2AuthorizationCodeFlow = OAuth2AuthorizationCodeFlow
794 { _oAuth2AuthorizationCodeFlowAuthorizationUrl :: AuthorizationURL
813 { _oAuth2AuthorizationCodeFlowAuthorizationUrl :: AuthorizationURL
@@ -821,8 +840,50 @@ data OAuth2Flows = OAuth2Flows
821 , _oAuth2FlowsAuthorizationCode :: Maybe (OAuth2Flow OAuth2AuthorizationCodeFlow)
840 , _oAuth2FlowsAuthorizationCode :: Maybe (OAuth2Flow OAuth2AuthorizationCodeFlow)
822 } deriving (Eq, Show, Generic, Data, Typeable)
841 } deriving (Eq, Show, Generic, Data, Typeable)
843+type BearerFormat = Text
846+ = HttpSchemeBearer (Maybe BearerFormat)
848+ | HttpSchemeCustom Text
849+ deriving (Eq, Show, Generic, Data, Typeable)
853+-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeHttp (HttpSchemeBearer Nothing))
855+-- "scheme": "bearer",
859+-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeHttp (HttpSchemeBearer (Just "jwt")))
861+-- "bearerFormat": "jwt",
862+-- "scheme": "bearer",
866+-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeHttp HttpSchemeBasic)
868+-- "scheme": "basic",
872+-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeHttp (HttpSchemeCustom "CANARY"))
874+-- "scheme": "CANARY",
878+-- >>> BSL.putStrLn $ encodePretty (SecuritySchemeApiKey (ApiKeyParams "id" ApiKeyCookie))
824data SecuritySchemeType
885data SecuritySchemeType
825− = SecuritySchemeHttp
886+ = SecuritySchemeHttp HttpSchemeType
826 | SecuritySchemeApiKey ApiKeyParams
887 | SecuritySchemeApiKey ApiKeyParams
827 | SecuritySchemeOAuth2 OAuth2Flows
888 | SecuritySchemeOAuth2 OAuth2Flows
828 | SecuritySchemeOpenIdConnect URL
889 | SecuritySchemeOpenIdConnect URL
@@ -857,7 +918,7 @@ data Tag = Tag
857 _tagName :: TagName
918 _tagName :: TagName
859 -- | A short description for the tag.
920 -- | A short description for the tag.
860− -- GFM syntax can be used for rich text representation.
921+ -- [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
861 , _tagDescription :: Maybe Text
922 , _tagDescription :: Maybe Text
863 -- | Additional external documentation for this tag.
924 -- | Additional external documentation for this tag.
@@ -872,7 +933,7 @@ instance IsString Tag where
872-- | Allows referencing an external resource for extended documentation.
933-- | Allows referencing an external resource for extended documentation.
873data ExternalDocs = ExternalDocs
934data ExternalDocs = ExternalDocs
874 { -- | A short description of the target documentation.
935 { -- | A short description of the target documentation.
875− -- GFM syntax can be used for rich text representation.
936+ -- [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
876 _externalDocsDescription :: Maybe Text
937 _externalDocsDescription :: Maybe Text
878 -- | The URL for the target documentation.
939 -- | The URL for the target documentation.
@@ -919,8 +980,7 @@ deriveGeneric ''MediaTypeObject
919deriveGeneric ''Responses
980deriveGeneric ''Responses
920deriveGeneric ''SecurityScheme
981deriveGeneric ''SecurityScheme
921deriveGeneric ''Schema
982deriveGeneric ''Schema
922−deriveGeneric ''ParamSchema
983+deriveGeneric ''OpenApi
923−deriveGeneric ''Swagger
924deriveGeneric ''Example
984deriveGeneric ''Example
925deriveGeneric ''Encoding
985deriveGeneric ''Encoding
926deriveGeneric ''Link
986deriveGeneric ''Link
@@ -929,9 +989,9 @@ deriveGeneric ''Link
929-- Monoid instances
989-- Monoid instances
930-- =======================================================================
990-- =======================================================================
932−instance Semigroup Swagger where
992+instance Semigroup OpenApi where
933 (<>) = genericMappend
993 (<>) = genericMappend
934−instance Monoid Swagger where
994+instance Monoid OpenApi where
935 mempty = genericMempty
995 mempty = genericMempty
936 mappend = (<>)
996 mappend = (<>)
@@ -965,12 +1025,6 @@ instance Monoid Schema where
965 mempty = genericMempty
1025 mempty = genericMempty
966 mappend = (<>)
1026 mappend = (<>)
968−instance Semigroup ParamSchema where
969− (<>) = genericMappend
970−instance Monoid ParamSchema where
971− mempty = genericMempty
974instance Semigroup Param where
1028instance Semigroup Param where
975 (<>) = genericMappend
1029 (<>) = genericMappend
976instance Monoid Param where
1030instance Monoid Param where
@@ -1065,19 +1119,19 @@ instance SwaggerMonoid Info
1065instance SwaggerMonoid Components
1119instance SwaggerMonoid Components
1066instance SwaggerMonoid PathItem
1120instance SwaggerMonoid PathItem
1067instance SwaggerMonoid Schema
1121instance SwaggerMonoid Schema
1068−instance SwaggerMonoid ParamSchema
1069instance SwaggerMonoid Param
1122instance SwaggerMonoid Param
1070instance SwaggerMonoid Responses
1123instance SwaggerMonoid Responses
1071instance SwaggerMonoid Response
1124instance SwaggerMonoid Response
1072instance SwaggerMonoid ExternalDocs
1125instance SwaggerMonoid ExternalDocs
1073instance SwaggerMonoid Operation
1126instance SwaggerMonoid Operation
1074instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
1127instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
1128+instance SwaggerMonoid SecurityDefinitions
1076instance SwaggerMonoid MimeList
1130instance SwaggerMonoid MimeList
1077deriving instance SwaggerMonoid URL
1131deriving instance SwaggerMonoid URL
1079−instance SwaggerMonoid SwaggerType where
1133+instance SwaggerMonoid OpenApiType where
1080− swaggerMempty = SwaggerString
1134+ swaggerMempty = OpenApiString
1081 swaggerMappend _ y = y
1135 swaggerMappend _ y = y
1083instance SwaggerMonoid ParamLocation where
1137instance SwaggerMonoid ParamLocation where
@@ -1100,7 +1154,7 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
1100instance ToJSON Style where
1154instance ToJSON Style where
1101 toJSON = genericToJSON (jsonPrefix "Style")
1155 toJSON = genericToJSON (jsonPrefix "Style")
1103−instance ToJSON SwaggerType where
1157+instance ToJSON OpenApiType where
1104 toJSON = genericToJSON (jsonPrefix "Swagger")
1158 toJSON = genericToJSON (jsonPrefix "Swagger")
1106instance ToJSON ParamLocation where
1160instance ToJSON ParamLocation where
@@ -1155,7 +1209,7 @@ instance ToJSON OAuth2AuthorizationCodeFlow where
1155instance FromJSON Style where
1209instance FromJSON Style where
1156 parseJSON = genericParseJSON (jsonPrefix "Style")
1210 parseJSON = genericParseJSON (jsonPrefix "Style")
1158−instance FromJSON SwaggerType where
1212+instance FromJSON OpenApiType where
1159 parseJSON = genericParseJSON (jsonPrefix "Swagger")
1213 parseJSON = genericParseJSON (jsonPrefix "Swagger")
1161instance FromJSON ParamLocation where
1215instance FromJSON ParamLocation where
@@ -1220,8 +1274,19 @@ instance ToJSON OAuth2Flows where
1220 toEncoding = sopSwaggerGenericToEncoding
1274 toEncoding = sopSwaggerGenericToEncoding
1222instance ToJSON SecuritySchemeType where
1276instance ToJSON SecuritySchemeType where
1223− toJSON SecuritySchemeHttp
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
1283+ object [ "type" .= ("http" :: Text)
1284+ , "scheme" .= ("basic" :: Text)
1286+ HttpSchemeCustom t ->
1224− = object [ "type" .= ("http" :: Text) ]
1287+ object [ "type" .= ("http" :: Text)
1225 toJSON (SecuritySchemeApiKey params)
1290 toJSON (SecuritySchemeApiKey params)
1226 = toJSON params
1291 = toJSON params
1227 <+> object [ "type" .= ("apiKey" :: Text) ]
1292 <+> object [ "type" .= ("apiKey" :: Text) ]
@@ -1234,9 +1299,9 @@ instance ToJSON SecuritySchemeType where
1234 , "openIdConnectUrl" .= url
1299 , "openIdConnectUrl" .= url
1237−instance ToJSON Swagger where
1302+instance ToJSON OpenApi where
1238 toJSON a = sopSwaggerGenericToJSON a &
1303 toJSON a = sopSwaggerGenericToJSON a &
1239− if InsOrdHashMap.null (_swaggerPaths a)
1304+ if InsOrdHashMap.null (_openApiPaths a)
1240 then (<+> object ["paths" .= object []])
1305 then (<+> object ["paths" .= object []])
1242 toEncoding = sopSwaggerGenericToEncoding
1307 toEncoding = sopSwaggerGenericToEncoding
@@ -1250,8 +1315,8 @@ instance ToJSON SecurityScheme where
1250 toEncoding = sopSwaggerGenericToEncoding
1315 toEncoding = sopSwaggerGenericToEncoding
1252instance ToJSON Schema where
1317instance ToJSON Schema where
1253− toJSON = sopSwaggerGenericToJSON
1318+ toJSON = sopSwaggerGenericToJSONWithOpts $
1254− toEncoding = sopSwaggerGenericToEncoding
1319+ mkSwaggerAesonOptions "schema" & saoSubObject ?~ "items"
1256instance ToJSON Header where
1321instance ToJSON Header where
1257 toJSON = sopSwaggerGenericToJSON
1322 toJSON = sopSwaggerGenericToJSON
@@ -1260,17 +1325,21 @@ instance ToJSON Header where
1260-- | As for nullary schema for 0-arity type constructors, see
1325-- | As for nullary schema for 0-arity type constructors, see
1261-- <https://github.com/GetShopTV/swagger2/issues/167>.
1326-- <https://github.com/GetShopTV/swagger2/issues/167>.
1263−-- >>> encode (SwaggerItemsArray [])
1328+-- >>> BSL.putStrLn $ encodePretty (OpenApiItemsArray [])
1264−-- "{\"example\":[],\"items\":{},\"maxItems\":0}"
1332+-- "maxItems": 0
1266−instance ToJSON SwaggerItems where
1335+instance ToJSON OpenApiItems where
1267− toJSON (SwaggerItemsObject x) = object [ "items" .= x ]
1336+ toJSON (OpenApiItemsObject x) = object [ "items" .= x ]
1268− toJSON (SwaggerItemsArray []) = object
1337+ toJSON (OpenApiItemsArray []) = object
1269 [ "items" .= object []
1338 [ "items" .= object []
1270 , "maxItems" .= (0 :: Int)
1339 , "maxItems" .= (0 :: Int)
1271 , "example" .= Array mempty
1340 , "example" .= Array mempty
1273− toJSON (SwaggerItemsArray x) = object [ "items" .= x ]
1342+ toJSON (OpenApiItemsArray x) = object [ "items" .= x ]
1275instance ToJSON Components where
1344instance ToJSON Components where
1276 toJSON = sopSwaggerGenericToJSON
1345 toJSON = sopSwaggerGenericToJSON
@@ -1338,11 +1407,6 @@ instance ToJSON (Referenced Header) where toJSON = referencedToJSON "#/compone
1338instance ToJSON (Referenced Link) where toJSON = referencedToJSON "#/components/links/"
1407instance ToJSON (Referenced Link) where toJSON = referencedToJSON "#/components/links/"
1339instance ToJSON (Referenced Callback) where toJSON = referencedToJSON "#/components/callbacks/"
1408instance ToJSON (Referenced Callback) where toJSON = referencedToJSON "#/components/callbacks/"
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"
1346instance ToJSON AdditionalProperties where
1410instance ToJSON AdditionalProperties where
1347 toJSON (AdditionalPropertiesAllowed b) = toJSON b
1411 toJSON (AdditionalPropertiesAllowed b) = toJSON b
1348 toJSON (AdditionalPropertiesSchema s) = toJSON s
1412 toJSON (AdditionalPropertiesSchema s) = toJSON s
@@ -1375,14 +1439,19 @@ instance FromJSON SecuritySchemeType where
1375 parseJSON js@(Object o) = do
1439 parseJSON js@(Object o) = do
1376 (t :: Text) <- o .: "type"
1440 (t :: Text) <- o .: "type"
1377 case t of
1441 case t of
1443+ scheme <- o .: "scheme"
1378− "http" -> pure SecuritySchemeHttp
1444+ SecuritySchemeHttp <$> case scheme of
1445+ "bearer" -> HttpSchemeBearer <$> (o .:! "bearerFormat")
1446+ "basic" -> pure HttpSchemeBasic
1447+ t -> pure $ HttpSchemeCustom t
1379 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
1448 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
1380 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
1449 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
1381 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
1450 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
1382 _ -> empty
1451 _ -> empty
1383 parseJSON _ = empty
1452 parseJSON _ = empty
1385−instance FromJSON Swagger where
1454+instance FromJSON OpenApi where
1386 parseJSON = sopSwaggerGenericParseJSON
1455 parseJSON = sopSwaggerGenericParseJSON
1388instance FromJSON Server where
1457instance FromJSON Server where
@@ -1394,27 +1463,28 @@ instance FromJSON SecurityScheme where
1394instance FromJSON Schema where
1463instance FromJSON Schema where
1395 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
1464 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
1396 where nullaryCleanup :: Schema -> Schema
1465 where nullaryCleanup :: Schema -> Schema
1397− nullaryCleanup s@Schema{_schemaParamSchema=ps} =
1466+ nullaryCleanup s =
1398− if _paramSchemaItems ps == Just (SwaggerItemsArray [])
1467+ if _schemaItems s == Just (OpenApiItemsArray [])
1399 then s { _schemaExample = Nothing
1468 then s { _schemaExample = Nothing
1400− , _schemaParamSchema = ps { _paramSchemaMaxItems = Nothing } }
1469+ , _schemaMaxItems = Nothing
1403instance FromJSON Header where
1473instance FromJSON Header where
1404 parseJSON = sopSwaggerGenericParseJSON
1474 parseJSON = sopSwaggerGenericParseJSON
1406−instance FromJSON SwaggerItems where
1476+instance FromJSON OpenApiItems where
1407 parseJSON js@(Object obj)
1477 parseJSON js@(Object obj)
1408− | null obj = pure $ SwaggerItemsArray [] -- Nullary schema.
1478+ | null obj = pure $ OpenApiItemsArray [] -- Nullary schema.
1409− | otherwise = SwaggerItemsObject <$> parseJSON js
1479+ | otherwise = OpenApiItemsObject <$> parseJSON js
1410− parseJSON js@(Array _) = SwaggerItemsArray <$> parseJSON js
1480+ parseJSON js@(Array _) = OpenApiItemsArray <$> parseJSON js
1411 parseJSON _ = empty
1481 parseJSON _ = empty
1413instance FromJSON Components where
1483instance FromJSON Components where
1414 parseJSON = sopSwaggerGenericParseJSON
1484 parseJSON = sopSwaggerGenericParseJSON
1416instance FromJSON MimeList where
1486instance FromJSON MimeList where
1417− parseJSON js = (MimeList . map fromString) <$> parseJSON js
1487+ parseJSON js = MimeList . map fromString <$> parseJSON js
1419instance FromJSON Param where
1489instance FromJSON Param where
1420 parseJSON = sopSwaggerGenericParseJSON
1490 parseJSON = sopSwaggerGenericParseJSON
@@ -1422,7 +1492,7 @@ instance FromJSON Param where
1422instance FromJSON Responses where
1492instance FromJSON Responses where
1423 parseJSON (Object o) = Responses
1493 parseJSON (Object o) = Responses
1424 <$> o .:? "default"
1494 <$> o .:? "default"
1425− <*> (parseJSON (Object (HashMap.delete "default" o)))
1495+ <*> parseJSON (Object (deleteKey "default" o))
1426 parseJSON _ = empty
1496 parseJSON _ = empty
1428instance FromJSON Example where
1498instance FromJSON Example where
@@ -1481,9 +1551,6 @@ instance FromJSON (Referenced Callback) where parseJSON = referencedParseJSON "#
1481instance FromJSON Xml where
1551instance FromJSON Xml where
1482 parseJSON = genericParseJSON (jsonPrefix "xml")
1552 parseJSON = genericParseJSON (jsonPrefix "xml")
1484−instance FromJSON ParamSchema where
1485− parseJSON = sopSwaggerGenericParseJSON
1487instance FromJSON AdditionalProperties where
1554instance FromJSON AdditionalProperties where
1488 parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
1555 parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
1489 parseJSON js = AdditionalPropertiesSchema <$> parseJSON js
1556 parseJSON js = AdditionalPropertiesSchema <$> parseJSON js
@@ -1524,7 +1591,7 @@ instance HasSwaggerAesonOptions SecurityScheme where
1524 swaggerAesonOptions _ = mkSwaggerAesonOptions "securityScheme" & saoSubObject ?~ "type"
1591 swaggerAesonOptions _ = mkSwaggerAesonOptions "securityScheme" & saoSubObject ?~ "type"
1525instance HasSwaggerAesonOptions Schema where
1592instance HasSwaggerAesonOptions Schema where
1526 swaggerAesonOptions _ = mkSwaggerAesonOptions "schema" & saoSubObject ?~ "paramSchema"
1593 swaggerAesonOptions _ = mkSwaggerAesonOptions "schema" & saoSubObject ?~ "paramSchema"
1527−instance HasSwaggerAesonOptions Swagger where
1594+instance HasSwaggerAesonOptions OpenApi where
1528 swaggerAesonOptions _ = mkSwaggerAesonOptions "swagger" & saoAdditionalPairs .~ [("openapi", "3.0.0")]
1595 swaggerAesonOptions _ = mkSwaggerAesonOptions "swagger" & saoAdditionalPairs .~ [("openapi", "3.0.0")]
1529instance HasSwaggerAesonOptions Example where
1596instance HasSwaggerAesonOptions Example where
1530 swaggerAesonOptions _ = mkSwaggerAesonOptions "example"
1597 swaggerAesonOptions _ = mkSwaggerAesonOptions "example"
@@ -1534,12 +1601,8 @@ instance HasSwaggerAesonOptions Encoding where
1534instance HasSwaggerAesonOptions Link where
1601instance HasSwaggerAesonOptions Link where
1535 swaggerAesonOptions _ = mkSwaggerAesonOptions "link"
1602 swaggerAesonOptions _ = mkSwaggerAesonOptions "link"
1537−instance HasSwaggerAesonOptions ParamSchema where
1538− swaggerAesonOptions _ = mkSwaggerAesonOptions "paramSchema"
1540instance AesonDefaultValue Server
1604instance AesonDefaultValue Server
1541instance AesonDefaultValue Components
1605instance AesonDefaultValue Components
1542−instance AesonDefaultValue ParamSchema
1543instance AesonDefaultValue OAuth2ImplicitFlow
1606instance AesonDefaultValue OAuth2ImplicitFlow
1544instance AesonDefaultValue OAuth2PasswordFlow
1607instance AesonDefaultValue OAuth2PasswordFlow
1545instance AesonDefaultValue OAuth2ClientCredentialsFlow
1608instance AesonDefaultValue OAuth2ClientCredentialsFlow
@@ -1547,8 +1610,10 @@ instance AesonDefaultValue OAuth2AuthorizationCodeFlow
1547instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
1610instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
1548instance AesonDefaultValue Responses
1611instance AesonDefaultValue Responses
1549instance AesonDefaultValue SecuritySchemeType
1612instance AesonDefaultValue SecuritySchemeType
1550−instance AesonDefaultValue SwaggerType
1613+instance AesonDefaultValue OpenApiType
1551instance AesonDefaultValue MimeList where defaultValue = Just mempty
1614instance AesonDefaultValue MimeList where defaultValue = Just mempty
1552instance AesonDefaultValue Info
1615instance AesonDefaultValue Info
1553instance AesonDefaultValue ParamLocation
1616instance AesonDefaultValue ParamLocation
1554instance AesonDefaultValue Link
1617instance AesonDefaultValue Link
1618+instance AesonDefaultValue SecurityDefinitions where
1619+ defaultValue = Just mempty