@@ -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,10 +194,10 @@ data Components = Components
195194 , _componentsParameters :: Definitions Param
196195 , _componentsExamples :: Definitions Example
197196 , _componentsRequestBodies :: Definitions RequestBody
198− , _componentsHeaders :: Definitions Header
199− , _componentsSecuritySchemes :: SecurityDefinitions
200− , _componentsLinks :: Definitions Link
201− , _componentsCallbacks :: Definitions Callback
197+ , _componentsHeader :: Definitions Header
198+ , _componentsSecuritySchemes :: Definitions SecurityScheme
199+-- , _componentsLinks
200+-- , _componentsCallbacks
202201 } deriving (Eq, Show, Generic, Data, Typeable)
203202
204203-- | Describes the operations available on a single path.
@@ -288,11 +287,7 @@ data Operation = Operation
288287 -- | The list of possible responses as they are returned from executing this operation.
289288 , _operationResponses :: Responses
290289
291− -- | A map of possible out-of band callbacks related to the parent operation.
292− -- The key is a unique identifier for the 'Callback' Object.
293− -- Each value in the map is a 'Callback' Object that describes a request
294− -- that may be initiated by the API provider and the expected responses.
295− , _operationCallbacks :: InsOrdHashMap Text (Referenced Callback)
290+ -- TODO callbacks
296291
297292 -- | Declares this operation to be deprecated.
298293 -- Usage of the declared operation should be refrained.
@@ -337,11 +332,9 @@ data RequestBody = RequestBody
337332 -- | The content of the request body.
338333 -- The key is a media type or media type range and the value describes it.
339334 -- For requests that match multiple keys, only the most specific key is applicable.
340− -- e.g. @text/plain@ overrides @text/\*@
335+ -- e.g. @text/plain@ overrides @text/*@
341336 , _requestBodyContent :: InsOrdHashMap MediaType MediaTypeObject
342337
343− -- | Determines if the request body is required in the request.
344− -- Defaults to 'False'.
345338 , _requestBodyRequired :: Maybe Bool
346339 } deriving (Eq, Show, Generic, Data, Typeable)
347340
@@ -394,7 +387,7 @@ data Encoding = Encoding
394387 -- for other primitive types – @text/plain@; for object - @application/json@;
395388 -- for array – the default is defined based on the inner type.
396389 -- 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.
390+ -- a wildcard media type (e.g. @image/*@), or a comma-separated list of the two types.
398391 _encodingContentType :: Maybe MediaType
399392
400393 -- | A map allowing additional information to be provided as headers,
@@ -434,11 +427,11 @@ mimeListConstr :: Constr
434427mimeListConstr = mkConstr mimeListDataType "MimeList" ["getMimeList"] Prefix
435428
436429mimeListDataType :: DataType
437−mimeListDataType = mkDataType "Data.OpenApi.MimeList" [mimeListConstr]
430+mimeListDataType = mkDataType "Data.Swagger.MimeList" [mimeListConstr]
438431
439432instance Data MimeList where
440433 gunfold k z c = case constrIndex c of
441− 1 -> k (z (MimeList . map fromString))
434+ 1 -> k (z (\xs -> MimeList (map fromString xs)))
442435 _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type MimeList."
443436 toConstr (MimeList _) = mimeListConstr
444437 dataTypeOf _ = mimeListDataType
@@ -452,7 +445,7 @@ data Param = Param
452445
453446 -- | A brief description of the parameter.
454447 -- This could contain examples of use.
455− -- CommonMark syntax MAY be used for rich text representation.
448+ -- GFM syntax can be used for rich text representation.
456449 , _paramDescription :: Maybe Text
457450
458451 -- | Determines whether this parameter is mandatory.
@@ -472,13 +465,6 @@ data Param = Param
472465 -- a parameter with an empty value. Default value is @false@.
473466 , _paramAllowEmptyValue :: Maybe Bool
474467
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−
482468 -- | Parameter schema.
483469 , _paramSchema :: Maybe (Referenced Schema)
484470
@@ -509,10 +495,6 @@ data Param = Param
509495 -- Furthermore, if referencing a schema that contains an example,
510496 -- the examples value SHALL override the example provided by the schema.
511497 , _paramExamples :: InsOrdHashMap Text (Referenced Example)
512−
513− -- TODO
514− -- _paramContent :: InsOrdHashMap MediaType MediaTypeObject
515− -- should be singleton. mutually exclusive with _paramSchema.
516498 } deriving (Eq, Show, Generic, Data, Typeable)
517499
518500data Example = Example
@@ -537,63 +519,27 @@ data Example = Example
537519 , _exampleExternalValue :: Maybe URL
538520 } deriving (Eq, Show, Generic, Typeable, Data)
539521
540−data ExpressionOrValue
541− = Expression Text
542− | Value Value
543− deriving (Eq, Show, Generic, Typeable, Data)
544−
545−-- | The Link object represents a possible design-time link for a response.
546−-- The presence of a link does not guarantee the caller's ability to successfully invoke it,
547−-- rather it provides a known relationship and traversal mechanism between responses and other operations.
548−data Link = Link
549− { -- | A relative or absolute URI reference to an OAS operation.
550− -- This field is mutually exclusive of the '_linkOperationId' field,
551− -- and MUST point to an 'Operation' Object. Relative '_linkOperationRef'
552− -- values MAY be used to locate an existing 'Operation' Object in the OpenAPI definition.
553− _linkOperationRef :: Maybe Text
554−
555− -- | The name of an /existing/, resolvable OAS operation, as defined with a unique
556− -- '_operationOperationId'. This field is mutually exclusive of the '_linkOperationRef' field.
557− , _linkOperationId :: Maybe Text
558−
559− -- | A map representing parameters to pass to an operation as specified with '_linkOperationId'
560− -- or identified via '_linkOperationRef'. The key is the parameter name to be used, whereas
561− -- the value can be a constant or an expression to be evaluated and passed to the linked operation.
562− -- The parameter name can be qualified using the parameter location @[{in}.]{name}@
563− -- for operations that use the same parameter name in different locations (e.g. path.id).
564− , _linkParameters :: InsOrdHashMap Text ExpressionOrValue
565−
566− -- | A literal value or @{expression}@ to use as a request body when calling the target operation.
567− , _linkRequestBody :: Maybe ExpressionOrValue
568−
569− -- | A description of the link.
570− , _linkDescription :: Maybe Text
571−
572− -- | A server object to be used by the target operation.
573− , _linkServer :: Maybe Server
574− } deriving (Eq, Show, Generic, Typeable, Data)
575−
576−-- | Items for @'OpenApiArray'@ schemas.
522+-- | Items for @'SwaggerArray'@ schemas.
577523--
578524-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
579525-- it will incorporate Json Schema mostly verbatim.
580526--
581−-- @'OpenApiItemsObject'@ should be used to specify homogenous array @'Schema'@s.
527+-- @'SwaggerItemsObject'@ should be used to specify homogenous array @'Schema'@s.
582528--
583−-- @'OpenApiItemsArray'@ should be used to specify tuple @'Schema'@s.
584−data OpenApiItems where
585− OpenApiItemsObject :: Referenced Schema -> OpenApiItems
586− OpenApiItemsArray :: [Referenced Schema] -> OpenApiItems
529+-- @'SwaggerItemsArray'@ should be used to specify tuple @'Schema'@s.
530+data SwaggerItems where
531+ SwaggerItemsObject :: Referenced Schema -> SwaggerItems
532+ SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems
587533 deriving (Eq, Show, Typeable, Data)
588534
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
535+data SwaggerType where
536+ SwaggerString :: SwaggerType
537+ SwaggerNumber :: SwaggerType
538+ SwaggerInteger :: SwaggerType
539+ SwaggerBoolean :: SwaggerType
540+ SwaggerArray :: SwaggerType
541+ SwaggerNull :: SwaggerType
542+ SwaggerObject :: SwaggerType
597543 deriving (Eq, Show, Typeable, Generic, Data)
598544
599545data ParamLocation
@@ -638,33 +584,9 @@ data Schema = Schema
638584 , _schemaMaxProperties :: Maybe Integer
639585 , _schemaMinProperties :: Maybe Integer
640586
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
587+ , _schemaParamSchema :: ParamSchema
663588 } deriving (Eq, Show, Generic, Data, Typeable)
664589
665−-- | Regex pattern for @string@ type.
666−type Pattern = Text
667−
668590data Discriminator = Discriminator
669591 { -- | The name of the property in the payload that will hold the discriminator value.
670592 _discriminatorPropertyName :: Text
@@ -680,9 +602,37 @@ data NamedSchema = NamedSchema
680602 , _namedSchemaSchema :: Schema
681603 } deriving (Eq, Show, Generic, Data, Typeable)
682604
605+-- | Regex pattern for @string@ type.
606+type Pattern = Text
607+
608+data ParamSchema = ParamSchema
609+ { -- | Declares the value of the parameter that the server will use if none is provided,
610+ -- for example a @"count"@ to control the number of results per page might default to @100@
611+ -- if not supplied by the client in the request.
612+ -- (Note: "default" has no meaning for required parameters.)
613+ -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
614+ _paramSchemaDefault :: Maybe Value
615+
616+ , _paramSchemaType :: Maybe SwaggerType
617+ , _paramSchemaFormat :: Maybe Format
618+ , _paramSchemaItems :: Maybe SwaggerItems
619+ , _paramSchemaMaximum :: Maybe Scientific
620+ , _paramSchemaExclusiveMaximum :: Maybe Bool
621+ , _paramSchemaMinimum :: Maybe Scientific
622+ , _paramSchemaExclusiveMinimum :: Maybe Bool
623+ , _paramSchemaMaxLength :: Maybe Integer
624+ , _paramSchemaMinLength :: Maybe Integer
625+ , _paramSchemaPattern :: Maybe Pattern
626+ , _paramSchemaMaxItems :: Maybe Integer
627+ , _paramSchemaMinItems :: Maybe Integer
628+ , _paramSchemaUniqueItems :: Maybe Bool
629+ , _paramSchemaEnum :: Maybe [Value]
630+ , _paramSchemaMultipleOf :: Maybe Scientific
631+ } deriving (Eq, Show, Generic, Typeable, Data)
632+
683633data Xml = Xml
684634 { -- | 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.
635+ -- When defined within the @'SwaggerItems'@ (items), it will affect the name of the individual XML elements within the list.
686636 -- When defined alongside type being array (outside the items),
687637 -- it will affect the wrapping element and only if wrapped is true.
688638 -- If wrapped is false, it will be ignored.
@@ -734,44 +684,25 @@ data Response = Response
734684 -- | A map containing descriptions of potential response payloads.
735685 -- The key is a media type or media type range and the value describes it.
736686 -- For responses that match multiple keys, only the most specific key is applicable.
737− -- e.g. @text/plain@ overrides @text/\*@.
687+ -- e.g. @text/plain@ overrides @text/*@.
738688 , _responseContent :: InsOrdHashMap MediaType MediaTypeObject
739689
740690 -- | Maps a header name to its definition.
741691 , _responseHeaders :: InsOrdHashMap HeaderName (Referenced Header)
742692
743− -- | A map of operations links that can be followed from the response.
744− -- The key of the map is a short name for the link, following the naming
745− -- constraints of the names for 'Component' Objects.
746− , _responseLinks :: InsOrdHashMap Text (Referenced Link)
693+ -- TODO links
747694 } deriving (Eq, Show, Generic, Data, Typeable)
748695
749696instance IsString Response where
750− fromString s = Response (fromString s) mempty mempty mempty
751−
752−-- | A map of possible out-of band callbacks related to the parent operation.
753−-- Each value in the map is a 'PathItem' Object that describes a set of requests that
754−-- may be initiated by the API provider and the expected responses.
755−-- The key value used to identify the path item object is an expression, evaluated at runtime,
756−-- that identifies a URL to use for the callback operation.
757−newtype Callback = Callback (InsOrdHashMap Text PathItem)
758− deriving (Eq, Show, Generic, Data, Typeable)
697+ fromString s = Response (fromString s) mempty mempty
759698
760699type HeaderName = Text
761700
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.
701+
702+-- TODO this is mostly a copy of 'Param'.
765703data Header = Header
766704 { -- | A short description of the header.
767− _headerDescription :: Maybe HeaderName
768−
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)
705+ _headerDescription :: Maybe Text
775706
776707 , _headerSchema :: Maybe (Referenced Schema)
777708 } deriving (Eq, Show, Generic, Data, Typeable)
@@ -797,17 +728,17 @@ type AuthorizationURL = Text
797728-- | The token URL to be used for OAuth2 flow. This SHOULD be in the form of a URL.
798729type TokenURL = Text
799730
800−newtype OAuth2ImplicitFlow
801− = OAuth2ImplicitFlow {_oAuth2ImplicitFlowAuthorizationUrl :: AuthorizationURL}
802− deriving (Eq, Show, Generic, Data, Typeable)
731+data OAuth2ImplicitFlow = OAuth2ImplicitFlow
732+ { _oAuth2ImplicitFlowAuthorizationUrl :: AuthorizationURL
733+ } deriving (Eq, Show, Generic, Data, Typeable)
803734
804−newtype OAuth2PasswordFlow
805− = OAuth2PasswordFlow {_oAuth2PasswordFlowTokenUrl :: TokenURL}
806− deriving (Eq, Show, Generic, Data, Typeable)
735+data OAuth2PasswordFlow = OAuth2PasswordFlow
736+ { _oAuth2PasswordFlowTokenUrl :: TokenURL
737+ } deriving (Eq, Show, Generic, Data, Typeable)
807738
808−newtype OAuth2ClientCredentialsFlow
809− = OAuth2ClientCredentialsFlow {_oAuth2ClientCredentialsFlowTokenUrl :: TokenURL}
810− deriving (Eq, Show, Generic, Data, Typeable)
739+data OAuth2ClientCredentialsFlow = OAuth2ClientCredentialsFlow
740+ { _oAuth2ClientCredentialsFlowTokenUrl :: TokenURL
741+ } deriving (Eq, Show, Generic, Data, Typeable)
811742
812743data OAuth2AuthorizationCodeFlow = OAuth2AuthorizationCodeFlow
813744 { _oAuth2AuthorizationCodeFlowAuthorizationUrl :: AuthorizationURL
@@ -840,50 +771,8 @@ data OAuth2Flows = OAuth2Flows
840771 , _oAuth2FlowsAuthorizationCode :: Maybe (OAuth2Flow OAuth2AuthorizationCodeFlow)
841772 } deriving (Eq, Show, Generic, Data, Typeable)
842773
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−--
885774data SecuritySchemeType
886− = SecuritySchemeHttp HttpSchemeType
775+ = SecuritySchemeHttp
887776 | SecuritySchemeApiKey ApiKeyParams
888777 | SecuritySchemeOAuth2 OAuth2Flows
889778 | SecuritySchemeOpenIdConnect URL
@@ -918,7 +807,7 @@ data Tag = Tag
918807 _tagName :: TagName
919808
920809 -- | A short description for the tag.
921− -- [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
810+ -- GFM syntax can be used for rich text representation.
922811 , _tagDescription :: Maybe Text
923812
924813 -- | Additional external documentation for this tag.
@@ -933,7 +822,7 @@ instance IsString Tag where
933822-- | Allows referencing an external resource for extended documentation.
934823data ExternalDocs = ExternalDocs
935824 { -- | A short description of the target documentation.
936− -- [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
825+ -- GFM syntax can be used for rich text representation.
937826 _externalDocsDescription :: Maybe Text
938827
939828 -- | The URL for the target documentation.
@@ -980,18 +869,18 @@ deriveGeneric ''MediaTypeObject
980869deriveGeneric ''Responses
981870deriveGeneric ''SecurityScheme
982871deriveGeneric ''Schema
983−deriveGeneric ''OpenApi
872+deriveGeneric ''ParamSchema
873+deriveGeneric ''Swagger
984874deriveGeneric ''Example
985875deriveGeneric ''Encoding
986−deriveGeneric ''Link
987876
988877-- =======================================================================
989878-- Monoid instances
990879-- =======================================================================
991880
992−instance Semigroup OpenApi where
881+instance Semigroup Swagger where
993882 (<>) = genericMappend
994−instance Monoid OpenApi where
883+instance Monoid Swagger where
995884 mempty = genericMempty
996885 mappend = (<>)
997886
@@ -1025,6 +914,12 @@ instance Monoid Schema where
1025914 mempty = genericMempty
1026915 mappend = (<>)
1027916
917+instance Semigroup ParamSchema where
918+ (<>) = genericMappend
919+instance Monoid ParamSchema where
920+ mempty = genericMempty
921+ mappend = (<>)
922+
1028923instance Semigroup Param where
1029924 (<>) = genericMappend
1030925instance Monoid Param where
@@ -1119,19 +1014,19 @@ instance SwaggerMonoid Info
11191014instance SwaggerMonoid Components
11201015instance SwaggerMonoid PathItem
11211016instance SwaggerMonoid Schema
1017+instance SwaggerMonoid ParamSchema
11221018instance SwaggerMonoid Param
11231019instance SwaggerMonoid Responses
11241020instance SwaggerMonoid Response
11251021instance SwaggerMonoid ExternalDocs
11261022instance SwaggerMonoid Operation
11271023instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
1128−instance SwaggerMonoid SecurityDefinitions
11291024
11301025instance SwaggerMonoid MimeList
11311026deriving instance SwaggerMonoid URL
11321027
1133−instance SwaggerMonoid OpenApiType where
1134− swaggerMempty = OpenApiString
1028+instance SwaggerMonoid SwaggerType where
1029+ swaggerMempty = SwaggerString
11351030 swaggerMappend _ y = y
11361031
11371032instance SwaggerMonoid ParamLocation where
@@ -1154,7 +1049,7 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
11541049instance ToJSON Style where
11551050 toJSON = genericToJSON (jsonPrefix "Style")
11561051
1157−instance ToJSON OpenApiType where
1052+instance ToJSON SwaggerType where
11581053 toJSON = genericToJSON (jsonPrefix "Swagger")
11591054
11601055instance ToJSON ParamLocation where
@@ -1209,7 +1104,7 @@ instance ToJSON OAuth2AuthorizationCodeFlow where
12091104instance FromJSON Style where
12101105 parseJSON = genericParseJSON (jsonPrefix "Style")
12111106
1212−instance FromJSON OpenApiType where
1107+instance FromJSON SwaggerType where
12131108 parseJSON = genericParseJSON (jsonPrefix "Swagger")
12141109
12151110instance FromJSON ParamLocation where
@@ -1274,19 +1169,8 @@ instance ToJSON OAuth2Flows where
12741169 toEncoding = sopSwaggerGenericToEncoding
12751170
12761171instance 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− ]
1172+ toJSON SecuritySchemeHttp
1173+ = object [ "type" .= ("http" :: Text) ]
12901174 toJSON (SecuritySchemeApiKey params)
12911175 = toJSON params
12921176 <+> object [ "type" .= ("apiKey" :: Text) ]
@@ -1299,9 +1183,9 @@ instance ToJSON SecuritySchemeType where
12991183 , "openIdConnectUrl" .= url
13001184 ]
13011185
1302−instance ToJSON OpenApi where
1186+instance ToJSON Swagger where
13031187 toJSON a = sopSwaggerGenericToJSON a &
1304− if InsOrdHashMap.null (_openApiPaths a)
1188+ if InsOrdHashMap.null (_swaggerPaths a)
13051189 then (<+> object ["paths" .= object []])
13061190 else id
13071191 toEncoding = sopSwaggerGenericToEncoding
@@ -1315,8 +1199,8 @@ instance ToJSON SecurityScheme where
13151199 toEncoding = sopSwaggerGenericToEncoding
13161200
13171201instance ToJSON Schema where
1318− toJSON = sopSwaggerGenericToJSONWithOpts $
1319− mkSwaggerAesonOptions "schema" & saoSubObject ?~ "items"
1202+ toJSON = sopSwaggerGenericToJSON
1203+ toEncoding = sopSwaggerGenericToEncoding
13201204
13211205instance ToJSON Header where
13221206 toJSON = sopSwaggerGenericToJSON
@@ -1325,21 +1209,17 @@ instance ToJSON Header where
13251209-- | As for nullary schema for 0-arity type constructors, see
13261210-- <https://github.com/GetShopTV/swagger2/issues/167>.
13271211--
1328−-- >>> BSL.putStrLn $ encodePretty (OpenApiItemsArray [])
1329−-- {
1330−-- "example": [],
1331−-- "items": {},
1332−-- "maxItems": 0
1333−-- }
1212+-- >>> encode (SwaggerItemsArray [])
1213+-- "{\"example\":[],\"items\":{},\"maxItems\":0}"
13341214--
1335−instance ToJSON OpenApiItems where
1336− toJSON (OpenApiItemsObject x) = object [ "items" .= x ]
1337− toJSON (OpenApiItemsArray []) = object
1215+instance ToJSON SwaggerItems where
1216+ toJSON (SwaggerItemsObject x) = object [ "items" .= x ]
1217+ toJSON (SwaggerItemsArray []) = object
13381218 [ "items" .= object []
13391219 , "maxItems" .= (0 :: Int)
13401220 , "example" .= Array mempty
13411221 ]
1342− toJSON (OpenApiItemsArray x) = object [ "items" .= x ]
1222+ toJSON (SwaggerItemsArray x) = object [ "items" .= x ]
13431223
13441224instance ToJSON Components where
13451225 toJSON = sopSwaggerGenericToJSON
@@ -1384,10 +1264,6 @@ instance ToJSON Encoding where
13841264 toJSON = sopSwaggerGenericToJSON
13851265 toEncoding = sopSwaggerGenericToEncoding
13861266
1387−instance ToJSON Link where
1388− toJSON = sopSwaggerGenericToJSON
1389− toEncoding = sopSwaggerGenericToEncoding
1390−
13911267instance ToJSON SecurityDefinitions where
13921268 toJSON (SecurityDefinitions sd) = toJSON sd
13931269
@@ -1404,20 +1280,16 @@ instance ToJSON (Referenced Response) where toJSON = referencedToJSON "#/compone
14041280instance ToJSON (Referenced RequestBody) where toJSON = referencedToJSON "#/components/requestBodies/"
14051281instance ToJSON (Referenced Example) where toJSON = referencedToJSON "#/components/examples/"
14061282instance ToJSON (Referenced Header) where toJSON = referencedToJSON "#/components/headers/"
1407−instance ToJSON (Referenced Link) where toJSON = referencedToJSON "#/components/links/"
1408−instance ToJSON (Referenced Callback) where toJSON = referencedToJSON "#/components/callbacks/"
1283+
1284+instance ToJSON ParamSchema where
1285+ -- TODO: this is a bit fishy, why we need sub object only in `ToJSON`?
1286+ toJSON = sopSwaggerGenericToJSONWithOpts $
1287+ mkSwaggerAesonOptions "paramSchema" & saoSubObject ?~ "items"
14091288
14101289instance ToJSON AdditionalProperties where
14111290 toJSON (AdditionalPropertiesAllowed b) = toJSON b
14121291 toJSON (AdditionalPropertiesSchema s) = toJSON s
14131292
1414−instance ToJSON ExpressionOrValue where
1415− toJSON (Expression expr) = toJSON expr
1416− toJSON (Value val) = toJSON val
1417−
1418−instance ToJSON Callback where
1419− toJSON (Callback ps) = toJSON ps
1420−
14211293-- =======================================================================
14221294-- Manual FromJSON instances
14231295-- =======================================================================
@@ -1439,19 +1311,14 @@ instance FromJSON SecuritySchemeType where
14391311 parseJSON js@(Object o) = do
14401312 (t :: Text) <- o .: "type"
14411313 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
1314+ "http" -> pure SecuritySchemeHttp
14481315 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
14491316 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
14501317 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
14511318 _ -> empty
14521319 parseJSON _ = empty
14531320
1454−instance FromJSON OpenApi where
1321+instance FromJSON Swagger where
14551322 parseJSON = sopSwaggerGenericParseJSON
14561323
14571324instance FromJSON Server where
@@ -1463,28 +1330,27 @@ instance FromJSON SecurityScheme where
14631330instance FromJSON Schema where
14641331 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
14651332 where nullaryCleanup :: Schema -> Schema
1466− nullaryCleanup s =
1467− if _schemaItems s == Just (OpenApiItemsArray [])
1333+ nullaryCleanup s@Schema{_schemaParamSchema=ps} =
1334+ if _paramSchemaItems ps == Just (SwaggerItemsArray [])
14681335 then s { _schemaExample = Nothing
1469− , _schemaMaxItems = Nothing
1470− }
1336+ , _schemaParamSchema = ps { _paramSchemaMaxItems = Nothing } }
14711337 else s
14721338
14731339instance FromJSON Header where
14741340 parseJSON = sopSwaggerGenericParseJSON
14751341
1476−instance FromJSON OpenApiItems where
1342+instance FromJSON SwaggerItems where
14771343 parseJSON js@(Object obj)
1478− | null obj = pure $ OpenApiItemsArray [] -- Nullary schema.
1479− | otherwise = OpenApiItemsObject <$> parseJSON js
1480− parseJSON js@(Array _) = OpenApiItemsArray <$> parseJSON js
1344+ | null obj = pure $ SwaggerItemsArray [] -- Nullary schema.
1345+ | otherwise = SwaggerItemsObject <$> parseJSON js
1346+ parseJSON js@(Array _) = SwaggerItemsArray <$> parseJSON js
14811347 parseJSON _ = empty
14821348
14831349instance FromJSON Components where
14841350 parseJSON = sopSwaggerGenericParseJSON
14851351
14861352instance FromJSON MimeList where
1487− parseJSON js = MimeList . map fromString <$> parseJSON js
1353+ parseJSON js = (MimeList . map fromString) <$> parseJSON js
14881354
14891355instance FromJSON Param where
14901356 parseJSON = sopSwaggerGenericParseJSON
@@ -1492,7 +1358,7 @@ instance FromJSON Param where
14921358instance FromJSON Responses where
14931359 parseJSON (Object o) = Responses
14941360 <$> o .:? "default"
1495− <*> parseJSON (Object (deleteKey "default" o))
1361+ <*> (parseJSON (Object (HashMap.delete "default" o)))
14961362 parseJSON _ = empty
14971363
14981364instance FromJSON Example where
@@ -1519,9 +1385,6 @@ instance FromJSON MediaTypeObject where
15191385instance FromJSON Encoding where
15201386 parseJSON = sopSwaggerGenericParseJSON
15211387
1522−instance FromJSON Link where
1523− parseJSON = sopSwaggerGenericParseJSON
1524−
15251388instance FromJSON Reference where
15261389 parseJSON (Object o) = Reference <$> o .: "$ref"
15271390 parseJSON _ = empty
@@ -1545,24 +1408,17 @@ instance FromJSON (Referenced Response) where parseJSON = referencedParseJSON "#
15451408instance FromJSON (Referenced RequestBody) where parseJSON = referencedParseJSON "#/components/requestBodies/"
15461409instance FromJSON (Referenced Example) where parseJSON = referencedParseJSON "#/components/examples/"
15471410instance FromJSON (Referenced Header) where parseJSON = referencedParseJSON "#/components/headers/"
1548−instance FromJSON (Referenced Link) where parseJSON = referencedParseJSON "#/components/links/"
1549−instance FromJSON (Referenced Callback) where parseJSON = referencedParseJSON "#/components/callbacks/"
15501411
15511412instance FromJSON Xml where
15521413 parseJSON = genericParseJSON (jsonPrefix "xml")
15531414
1415+instance FromJSON ParamSchema where
1416+ parseJSON = sopSwaggerGenericParseJSON
1417+
15541418instance FromJSON AdditionalProperties where
15551419 parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
15561420 parseJSON js = AdditionalPropertiesSchema <$> parseJSON js
15571421
1558−-- | All strings are parsed as expressions
1559−instance FromJSON ExpressionOrValue where
1560− parseJSON (String expr) = pure $ Expression expr
1561− parseJSON v = pure $ Value v
1562−
1563−instance FromJSON Callback where
1564− parseJSON = fmap Callback . parseJSON
1565−
15661422instance HasSwaggerAesonOptions Server where
15671423 swaggerAesonOptions _ = mkSwaggerAesonOptions "server"
15681424instance HasSwaggerAesonOptions Components where
@@ -1591,18 +1447,19 @@ instance HasSwaggerAesonOptions SecurityScheme where
15911447 swaggerAesonOptions _ = mkSwaggerAesonOptions "securityScheme" & saoSubObject ?~ "type"
15921448instance HasSwaggerAesonOptions Schema where
15931449 swaggerAesonOptions _ = mkSwaggerAesonOptions "schema" & saoSubObject ?~ "paramSchema"
1594−instance HasSwaggerAesonOptions OpenApi where
1450+instance HasSwaggerAesonOptions Swagger where
15951451 swaggerAesonOptions _ = mkSwaggerAesonOptions "swagger" & saoAdditionalPairs .~ [("openapi", "3.0.0")]
15961452instance HasSwaggerAesonOptions Example where
15971453 swaggerAesonOptions _ = mkSwaggerAesonOptions "example"
15981454instance HasSwaggerAesonOptions Encoding where
15991455 swaggerAesonOptions _ = mkSwaggerAesonOptions "encoding"
16001456
1601−instance HasSwaggerAesonOptions Link where
1602− swaggerAesonOptions _ = mkSwaggerAesonOptions "link"
1457+instance HasSwaggerAesonOptions ParamSchema where
1458+ swaggerAesonOptions _ = mkSwaggerAesonOptions "paramSchema"
16031459
16041460instance AesonDefaultValue Server
16051461instance AesonDefaultValue Components
1462+instance AesonDefaultValue ParamSchema
16061463instance AesonDefaultValue OAuth2ImplicitFlow
16071464instance AesonDefaultValue OAuth2PasswordFlow
16081465instance AesonDefaultValue OAuth2ClientCredentialsFlow
@@ -1610,10 +1467,7 @@ instance AesonDefaultValue OAuth2AuthorizationCodeFlow
16101467instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
16111468instance AesonDefaultValue Responses
16121469instance AesonDefaultValue SecuritySchemeType
1613−instance AesonDefaultValue OpenApiType
1470+instance AesonDefaultValue SwaggerType
16141471instance AesonDefaultValue MimeList where defaultValue = Just mempty
16151472instance AesonDefaultValue Info
16161473instance AesonDefaultValue ParamLocation
1617−instance AesonDefaultValue Link
1618−instance AesonDefaultValue SecurityDefinitions where
1619− defaultValue = Just mempty