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