@@ -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,91 +14,87 @@
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+import Control.Lens ((&), (.~), (?~))
22import Control.Applicative
23import Control.Applicative
23−import Control.Lens ((&), (.~), (?~))
24−import Data.Aeson hiding (Encoding)
24+import Data.Aeson hiding (Encoding)
25−#if MIN_VERSION_aeson(2,0,0)
26−import qualified Data.Aeson.KeyMap as KeyMap
28−import qualified Data.Aeson.Types as JSON
25+import qualified Data.Aeson.Types as JSON
29−import Data.Data (Constr, Data (..), DataType, Fixity (..), Typeable,
26+import Data.Data (Data(..), Typeable, mkConstr, mkDataType, Fixity(..), Constr, DataType, constrIndex)
30− constrIndex, mkConstr, mkDataType)
31−import Data.Hashable (Hashable (..))
27+import Data.Hashable (Hashable)
32−import qualified Data.HashMap.Strict as HashMap
28+import qualified Data.HashMap.Strict as HashMap
33−import Data.HashSet.InsOrd (InsOrdHashSet)
29+import Data.HashSet.InsOrd (InsOrdHashSet)
34−import Data.Map (Map)
30+import Data.Map (Map)
35−import qualified Data.Map as Map
31+import qualified Data.Map as Map
36−import Data.Monoid (Monoid (..))
32+import Data.Monoid (Monoid (..))
37−import Data.Scientific (Scientific)
38−import Data.Semigroup.Compat (Semigroup (..))
33+import Data.Semigroup.Compat (Semigroup (..))
34+import Data.Scientific (Scientific)
39−import Data.String (IsString (..))
35+import Data.String (IsString(..))
40−import Data.Text (Text)
36+import Data.Text (Text)
41−import qualified Data.Text as Text
37+import qualified Data.Text as Text
42−import Data.Text.Encoding (encodeUtf8)
43−import GHC.Generics (Generic)
38+import GHC.Generics (Generic)
44−import Network.HTTP.Media (MediaType, mainType, parameters, parseAccept, subType, (//),
39+import Network.Socket (HostName, PortNumber)
45− (/:))
40+import Network.HTTP.Media (MediaType)
46−import Network.Socket (HostName, PortNumber)
47−import Text.Read (readMaybe)
41+import Text.Read (readMaybe)
49import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
43import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
50import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
44import 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)
46import Generics.SOP.TH (deriveGeneric)
47+import Data.Swagger.Internal.AesonUtils (sopSwaggerGenericToJSON
48+ ,sopSwaggerGenericToJSONWithOpts
49+ ,sopSwaggerGenericParseJSON
50+ ,HasSwaggerAesonOptions(..)
51+ ,AesonDefaultValue(..)
52+ ,mkSwaggerAesonOptions
55+import Data.Swagger.Internal.Utils
56+import Data.Swagger.Internal.AesonUtils (sopSwaggerGenericToEncoding)
61-- >>> :seti -XDataKinds
59-- >>> :seti -XDataKinds
62-- >>> import Data.Aeson
60-- >>> 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.
62-- | A list of definitions that can be used in references.
67type Definitions = InsOrdHashMap Text
63type Definitions = InsOrdHashMap Text
69-- | This is the root document object for the API specification.
65-- | This is the root document object for the API specification.
70−data OpenApi = OpenApi
66+data Swagger = Swagger
71 { -- | Provides metadata about the API.
67 { -- | Provides metadata about the API.
72 -- The metadata can be used by the clients if needed.
68 -- The metadata can be used by the clients if needed.
73− _openApiInfo :: Info
69+ _swaggerInfo :: Info
75 -- | An array of Server Objects, which provide connectivity information
71 -- | 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,
72 -- 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 @/@.
73 -- the default value would be a 'Server' object with a url value of @/@.
78− , _openApiServers :: [Server]
74+ , _swaggerServers :: [Server]
80 -- | The available paths and operations for the API.
76 -- | The available paths and operations for the API.
81− , _openApiPaths :: InsOrdHashMap FilePath PathItem
77+ , _swaggerPaths :: InsOrdHashMap FilePath PathItem
83 -- | An element to hold various schemas for the specification.
79 -- | An element to hold various schemas for the specification.
84− , _openApiComponents :: Components
80+ , _swaggerComponents :: Components
86 -- | A declaration of which security mechanisms can be used across the API.
82 -- | 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.
83 -- 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.
84 -- Only one of the security requirement objects need to be satisfied to authorize a request.
89 -- Individual operations can override this definition.
85 -- Individual operations can override this definition.
90 -- To make security optional, an empty security requirement can be included in the array.
86 -- To make security optional, an empty security requirement can be included in the array.
91− , _openApiSecurity :: [SecurityRequirement]
87+ , _swaggerSecurity :: [SecurityRequirement]
93 -- | A list of tags used by the specification with additional metadata.
89 -- | 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.
90 -- 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.
91 -- 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.
92 -- 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.
93 -- Each tag name in the list MUST be unique.
98− , _openApiTags :: InsOrdHashSet Tag
94+ , _swaggerTags :: InsOrdHashSet Tag
100 -- | Additional external documentation.
96 -- | Additional external documentation.
101− , _openApiExternalDocs :: Maybe ExternalDocs
97+ , _swaggerExternalDocs :: Maybe ExternalDocs
102 } deriving (Eq, Show, Generic, Data, Typeable)
98 } deriving (Eq, Show, Generic, Data, Typeable)
104-- | The object provides metadata about the API.
100-- | The object provides metadata about the API.
@@ -183,9 +179,6 @@ data ServerVariable = ServerVariable
183 , _serverVariableDescription :: Maybe Text
179 , _serverVariableDescription :: Maybe Text
184 } deriving (Eq, Show, Generic, Data, Typeable)
180 } deriving (Eq, Show, Generic, Data, Typeable)
186−instance IsString Server where
187− fromString s = Server (fromString s) Nothing mempty
189-- | Holds a set of reusable objects for different aspects of the OAS.
182-- | Holds a set of reusable objects for different aspects of the OAS.
190-- All objects defined within the components object will have no effect on the API
183-- All objects defined within the components object will have no effect on the API
191-- unless they are explicitly referenced from properties outside the components object.
184-- unless they are explicitly referenced from properties outside the components object.
@@ -195,12 +188,42 @@ data Components = Components
195 , _componentsParameters :: Definitions Param
188 , _componentsParameters :: Definitions Param
196 , _componentsExamples :: Definitions Example
189 , _componentsExamples :: Definitions Example
197 , _componentsRequestBodies :: Definitions RequestBody
190 , _componentsRequestBodies :: Definitions RequestBody
198− , _componentsHeaders :: Definitions Header
191+ , _componentsHeader :: Definitions Header
199− , _componentsSecuritySchemes :: SecurityDefinitions
192+ , _componentsSecuritySchemes :: Definitions SecurityScheme
200− , _componentsLinks :: Definitions Link
193+-- , _componentsLinks
201− , _componentsCallbacks :: Definitions Callback
194+-- , _componentsCallbacks
202 } deriving (Eq, Show, Generic, Data, Typeable)
195 } deriving (Eq, Show, Generic, Data, Typeable)
197+-- | The host (name or ip) serving the API. It MAY include a port.
199+ { _hostName :: HostName -- ^ Host name.
200+ , _hostPort :: Maybe PortNumber -- ^ Optional port.
201+ } deriving (Eq, Show, Generic, Typeable)
203+instance IsString Host where
204+ fromString s = Host s Nothing
207+hostConstr = mkConstr hostDataType "Host" [] Prefix
209+hostDataType :: DataType
210+hostDataType = mkDataType "Data.Swagger.Host" [hostConstr]
212+instance Data Host where
213+ gunfold k z c = case constrIndex c of
214+ 1 -> k (k (z (\name mport -> Host name (fromInteger <$> mport))))
215+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type Host."
216+ toConstr (Host _ _) = hostConstr
217+ dataTypeOf _ = hostDataType
219+-- | The transfer protocol of the API.
225+ deriving (Eq, Show, Generic, Data, Typeable)
204-- | Describes the operations available on a single path.
227-- | Describes the operations available on a single path.
205-- A @'PathItem'@ may be empty, due to ACL constraints.
228-- A @'PathItem'@ may be empty, due to ACL constraints.
206-- The path itself is still exposed to the documentation viewer
229-- The path itself is still exposed to the documentation viewer
@@ -288,11 +311,7 @@ data Operation = Operation
288 -- | The list of possible responses as they are returned from executing this operation.
311 -- | The list of possible responses as they are returned from executing this operation.
289 , _operationResponses :: Responses
312 , _operationResponses :: Responses
291− -- | A map of possible out-of band callbacks related to the parent operation.
314+ -- TODO callbacks
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)
297 -- | Declares this operation to be deprecated.
316 -- | Declares this operation to be deprecated.
298 -- Usage of the declared operation should be refrained.
317 -- Usage of the declared operation should be refrained.
@@ -312,22 +331,6 @@ data Operation = Operation
312 , _operationServers :: [Server]
331 , _operationServers :: [Server]
313 } deriving (Eq, Show, Generic, Data, Typeable)
332 } deriving (Eq, Show, Generic, Data, Typeable)
315−-- This instance should be in @http-media@.
316−instance Data MediaType where
317− gunfold k z c = case constrIndex c of
318− 1 -> k (k (k (z (\main sub params -> foldl (/:) (main // sub) (Map.toList params)))))
319− _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type MediaType."
321− toConstr _ = mediaTypeConstr
323− dataTypeOf _ = mediaTypeData
325−mediaTypeConstr = mkConstr mediaTypeData "MediaType" [] Prefix
326−mediaTypeData = mkDataType "MediaType" [mediaTypeConstr]
328−instance Hashable MediaType where
329− hashWithSalt salt mt = salt `hashWithSalt` show mt
331-- | Describes a single request body.
334-- | Describes a single request body.
332data RequestBody = RequestBody
335data RequestBody = RequestBody
333 { -- | A brief description of the request body. This could contain examples of use.
336 { -- | A brief description of the request body. This could contain examples of use.
@@ -337,11 +340,9 @@ data RequestBody = RequestBody
337 -- | The content of the request body.
340 -- | The content of the request body.
338 -- The key is a media type or media type range and the value describes it.
341 -- 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.
342 -- For requests that match multiple keys, only the most specific key is applicable.
340− -- e.g. @text/plain@ overrides @text/\*@
343+ -- e.g. @text/plain@ overrides @text/*@
341− , _requestBodyContent :: InsOrdHashMap MediaType MediaTypeObject
344+ , _requestBodyContent :: InsOrdHashMap {-MediaType-} Text MediaTypeObject -- FIXME Data MediaType
343− -- | Determines if the request body is required in the request.
344− -- Defaults to 'False'.
345 , _requestBodyRequired :: Maybe Bool
346 , _requestBodyRequired :: Maybe Bool
346 } deriving (Eq, Show, Generic, Data, Typeable)
347 } deriving (Eq, Show, Generic, Data, Typeable)
@@ -364,29 +365,6 @@ data MediaTypeObject = MediaTypeObject
364 , _mediaTypeObjectEncoding :: InsOrdHashMap Text Encoding
365 , _mediaTypeObjectEncoding :: InsOrdHashMap Text Encoding
365 } deriving (Eq, Show, Generic, Data, Typeable)
366 } deriving (Eq, Show, Generic, Data, Typeable)
367−-- | In order to support common ways of serializing simple parameters, a set of style values are defined.
370− -- ^ Path-style parameters defined by [RFC6570](https://tools.ietf.org/html/rfc6570#section-3.2.7).
372− -- ^ Label style parameters defined by [RFC6570](https://tools.ietf.org/html/rfc6570#section-3.2.7).
374− -- ^ Form style parameters defined by [RFC6570](https://tools.ietf.org/html/rfc6570#section-3.2.7).
375− -- This option replaces @collectionFormat@ with a @csv@ (when @explode@ is false) or @multi@
376− -- (when explode is true) value from OpenAPI 2.0.
378− -- ^ Simple style parameters defined by [RFC6570](https://tools.ietf.org/html/rfc6570#section-3.2.7).
379− -- This option replaces @collectionFormat@ with a @csv@ value from OpenAPI 2.0.
380− | StyleSpaceDelimited
381− -- ^ Space separated array values.
382− -- This option replaces @collectionFormat@ equal to @ssv@ from OpenAPI 2.0.
383− | StylePipeDelimited
384− -- ^ Pipe separated array values.
385− -- This option replaces @collectionFormat@ equal to @pipes@ from OpenAPI 2.0.
387− -- ^ Provides a simple way of rendering nested objects using form parameters.
388− deriving (Eq, Show, Generic, Data, Typeable)
390data Encoding = Encoding
368data Encoding = Encoding
391 { -- | The Content-Type for encoding a specific property.
369 { -- | The Content-Type for encoding a specific property.
392 -- Default value depends on the property type: for @string@
370 -- Default value depends on the property type: for @string@
@@ -394,8 +372,8 @@ data Encoding = Encoding
394 -- for other primitive types – @text/plain@; for object - @application/json@;
372 -- for other primitive types – @text/plain@; for object - @application/json@;
395 -- for array – the default is defined based on the inner type.
373 -- for array – the default is defined based on the inner type.
396 -- The value can be a specific media type (e.g. @application/json@),
374 -- 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.
375+ -- a wildcard media type (e.g. @image/*@), or a comma-separated list of the two types.
398− _encodingContentType :: Maybe MediaType
376+ _encodingContentType :: Maybe Text
400 -- | A map allowing additional information to be provided as headers,
378 -- | A map allowing additional information to be provided as headers,
401 -- for example @Content-Disposition@. @Content-Type@ is described separately
379 -- for example @Content-Disposition@. @Content-Type@ is described separately
@@ -404,11 +382,11 @@ data Encoding = Encoding
404 , _encodingHeaders :: InsOrdHashMap Text (Referenced Header)
382 , _encodingHeaders :: InsOrdHashMap Text (Referenced Header)
406 -- | Describes how a specific property value will be serialized depending on its type.
384 -- | Describes how a specific property value will be serialized depending on its type.
407− -- See 'Param' Object for details on the style property.
385+ -- See Parameter Object for details on the style property.
408 -- The behavior follows the same values as query parameters, including default values.
386 -- The behavior follows the same values as query parameters, including default values.
409 -- This property SHALL be ignored if the request body media type
387 -- This property SHALL be ignored if the request body media type
410 -- is not @application/x-www-form-urlencoded@.
388 -- is not @application/x-www-form-urlencoded@.
411− , _encodingStyle :: Maybe Style
389+ , _encodingStyle :: Maybe Text -- TODO enum
413 -- | When this is true, property values of type @array@ or @object@ generate
391 -- | When this is true, property values of type @array@ or @object@ generate
414 -- separate parameters for each value of the array,
392 -- separate parameters for each value of the array,
@@ -434,11 +412,11 @@ mimeListConstr :: Constr
434mimeListConstr = mkConstr mimeListDataType "MimeList" ["getMimeList"] Prefix
412mimeListConstr = mkConstr mimeListDataType "MimeList" ["getMimeList"] Prefix
436mimeListDataType :: DataType
414mimeListDataType :: DataType
437−mimeListDataType = mkDataType "Data.OpenApi.MimeList" [mimeListConstr]
415+mimeListDataType = mkDataType "Data.Swagger.MimeList" [mimeListConstr]
439instance Data MimeList where
417instance Data MimeList where
440 gunfold k z c = case constrIndex c of
418 gunfold k z c = case constrIndex c of
441− 1 -> k (z (MimeList . map fromString))
419+ 1 -> k (z (\xs -> MimeList (map fromString xs)))
442 _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type MimeList."
420 _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type MimeList."
443 toConstr (MimeList _) = mimeListConstr
421 toConstr (MimeList _) = mimeListConstr
444 dataTypeOf _ = mimeListDataType
422 dataTypeOf _ = mimeListDataType
@@ -452,7 +430,7 @@ data Param = Param
453 -- | A brief description of the parameter.
431 -- | A brief description of the parameter.
454 -- This could contain examples of use.
432 -- This could contain examples of use.
455− -- CommonMark syntax MAY be used for rich text representation.
433+ -- GFM syntax can be used for rich text representation.
456 , _paramDescription :: Maybe Text
434 , _paramDescription :: Maybe Text
458 -- | Determines whether this parameter is mandatory.
436 -- | Determines whether this parameter is mandatory.
@@ -460,60 +438,27 @@ data Param = Param
460 -- Otherwise, the property MAY be included and its default value is @False@.
438 -- Otherwise, the property MAY be included and its default value is @False@.
461 , _paramRequired :: Maybe Bool
439 , _paramRequired :: Maybe Bool
463− -- | Specifies that a parameter is deprecated and SHOULD be transitioned out of usage.
441+ -- | Parameter schema.
464− -- Default value is @false@.
442+ , _paramSchema :: ParamAnySchema
465− , _paramDeprecated :: Maybe Bool
443+ } deriving (Eq, Show, Generic, Data, Typeable)
467− -- | The location of the parameter.
445+data ParamAnySchema
468− , _paramIn :: ParamLocation
446+ = ParamBody (Referenced Schema)
447+ | ParamOther ParamOtherSchema
448+ deriving (Eq, Show, Generic, Data, Typeable)
470− -- | Sets the ability to pass empty-valued parameters.
450+data ParamOtherSchema = ParamOtherSchema
471− -- This is valid only for 'ParamQuery' parameters and allows sending
451+ { -- | The location of the parameter.
472− -- a parameter with an empty value. Default value is @false@.
452+ _paramOtherSchemaIn :: ParamLocation
473− , _paramAllowEmptyValue :: Maybe Bool
475− -- | Determines whether the parameter value SHOULD allow reserved characters,
454+ -- | Sets the ability to pass empty-valued parameters.
476− -- as defined by [RFC3986](https://tools.ietf.org/html/rfc3986#section-2.2)
455+ -- This is valid only for either @'ParamQuery'@ or @'ParamFormData'@
477− -- @:/?#[]@!$&'()*+,;=@ to be included without percent-encoding.
456+ -- and allows you to send a parameter with a name only or an empty value.
478− -- This property only applies to parameters with an '_paramIn' value of 'ParamQuery'.
479− -- The default value is 'False'.
457+ -- Default value is @False@.
480− , _paramAllowReserved :: Maybe Bool
458+ , _paramOtherSchemaAllowEmptyValue :: Maybe Bool
482− -- | Parameter schema.
460+ , _paramOtherSchemaParamSchema :: ParamSchema 'SwaggerKindParamOtherSchema
483− , _paramSchema :: Maybe (Referenced Schema)
485− -- | Describes how the parameter value will be serialized depending
486− -- on the type of the parameter value. Default values (based on value of '_paramIn'):
487− -- for 'ParamQuery' - 'StyleForm'; for 'ParamPath' - 'StyleSimple'; for 'ParamHeader' - 'StyleSimple';
488− -- for 'ParamCookie' - 'StyleForm'.
489− , _paramStyle :: Maybe Style
491− -- | When this is true, parameter values of type @array@ or @object@
492− -- generate separate parameters for each value of the array or key-value pair of the map.
493− -- For other types of parameters this property has no effect.
494− -- When style is @form@, the default value is true. For all other styles, the default value is false.
495− , _paramExplode :: Maybe Bool
497− -- | Example of the parameter's potential value.
498− -- The example SHOULD match the specified schema and encoding properties if present.
499− -- The '_paramExample' field is mutually exclusive of the '_paramExamples' field.
500− -- Furthermore, if referencing a schema that contains an example, the example value
501− -- SHALL override the example provided by the schema. To represent examples of media types
502− -- that cannot naturally be represented in JSON or YAML, a string value can contain
503− -- the example with escaping where necessary.
504− , _paramExample :: Maybe Value
506− -- | Examples of the parameter's potential value.
507− -- Each example SHOULD contain a value in the correct format as specified
508− -- in the parameter encoding. The '_paramExamples' field is mutually exclusive of the '_paramExample' field.
509− -- Furthermore, if referencing a schema that contains an example,
510− -- the examples value SHALL override the example provided by the schema.
511− , _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)
461+ } deriving (Eq, Show, Generic, Typeable, Data)
518data Example = Example
463data Example = Example
519 { -- | Short description for the example.
464 { -- | Short description for the example.
@@ -537,64 +482,137 @@ data Example = Example
537 , _exampleExternalValue :: Maybe URL
482 , _exampleExternalValue :: Maybe URL
538 } deriving (Eq, Show, Generic, Typeable, Data)
483 } deriving (Eq, Show, Generic, Typeable, Data)
540−data ExpressionOrValue
543− deriving (Eq, Show, Generic, Typeable, Data)
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.
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
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
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
566− -- | A literal value or @{expression}@ to use as a request body when calling the target operation.
567− , _linkRequestBody :: Maybe ExpressionOrValue
569− -- | A description of the link.
570− , _linkDescription :: Maybe Text
572− -- | A server object to be used by the target operation.
573− , _linkServer :: Maybe Server
574− } deriving (Eq, Show, Generic, Typeable, Data)
576−-- | Items for @'OpenApiArray'@ schemas.
485+-- | Items for @'SwaggerArray'@ schemas.
578−-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
487+-- @'SwaggerItemsPrimitive'@ should be used only for query params, headers and path pieces.
579−-- it will incorporate Json Schema mostly verbatim.
488+-- The @'CollectionFormat' t@ parameter specifies how elements of an array should be displayed.
489+-- Note that @fmt@ in @'SwaggerItemsPrimitive' fmt schema@ specifies format for elements of type @schema@.
490+-- This is different from the original Swagger's <http://swagger.io/specification/#itemsObject Items Object>.
581−-- @'OpenApiItemsObject'@ should be used to specify homogenous array @'Schema'@s.
492+-- @'SwaggerItemsObject'@ should be used to specify homogenous array @'Schema'@s.
583−-- @'OpenApiItemsArray'@ should be used to specify tuple @'Schema'@s.
494+-- @'SwaggerItemsArray'@ should be used to specify tuple @'Schema'@s.
584−data OpenApiItems where
495+data SwaggerItems t where
585− OpenApiItemsObject :: Referenced Schema -> OpenApiItems
496+ SwaggerItemsPrimitive :: Maybe (CollectionFormat k) -> ParamSchema k-> SwaggerItems k
586− OpenApiItemsArray :: [Referenced Schema] -> OpenApiItems
497+ SwaggerItemsObject :: Referenced Schema -> SwaggerItems 'SwaggerKindSchema
587− deriving (Eq, Show, Typeable, Data)
498+ SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems 'SwaggerKindSchema
588−
499+ deriving (Typeable)
589−data OpenApiType where
500+
590− OpenApiString :: OpenApiType
501+deriving instance Eq (SwaggerItems t)
591− OpenApiNumber :: OpenApiType
502+deriving instance Show (SwaggerItems t)
592− OpenApiInteger :: OpenApiType
503+--deriving instance Typeable (SwaggerItems t)
593− OpenApiBoolean :: OpenApiType
504+
594− OpenApiArray :: OpenApiType
505+swaggerItemsPrimitiveConstr :: Constr
595− OpenApiNull :: OpenApiType
506+swaggerItemsPrimitiveConstr = mkConstr swaggerItemsDataType "SwaggerItemsPrimitive" [] Prefix
596− OpenApiObject :: OpenApiType
507+
597− deriving (Eq, Show, Typeable, Generic, Data)
508+swaggerItemsObjectConstr :: Constr
509+swaggerItemsObjectConstr = mkConstr swaggerItemsDataType "SwaggerItemsObject" [] Prefix
511+swaggerItemsArrayConstr :: Constr
512+swaggerItemsArrayConstr = mkConstr swaggerItemsDataType "SwaggerItemsArray" [] Prefix
514+swaggerItemsDataType :: DataType
515+swaggerItemsDataType = mkDataType "Data.Swagger.SwaggerItems" [swaggerItemsPrimitiveConstr]
517+-- Note: unfortunately we have to write these Data instances by hand,
518+-- to get better contexts / avoid duplicate name when using standalone deriving
520+instance Data t => Data (SwaggerItems ('SwaggerKindNormal t)) where
521+ -- TODO: define gfoldl
522+ gunfold k z c = case constrIndex c of
523+ 1 -> k (k (z SwaggerItemsPrimitive))
524+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type (SwaggerItems t)."
525+ toConstr _ = swaggerItemsPrimitiveConstr
526+ dataTypeOf _ = swaggerItemsDataType
528+-- SwaggerItems SwaggerKindParamOtherSchema can be constructed using SwaggerItemsPrimitive only
529+instance Data (SwaggerItems 'SwaggerKindParamOtherSchema) where
530+ -- TODO: define gfoldl
531+ gunfold k z c = case constrIndex c of
532+ 1 -> k (k (z SwaggerItemsPrimitive))
533+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type (SwaggerItems SwaggerKindParamOtherSchema)."
534+ toConstr _ = swaggerItemsPrimitiveConstr
535+ dataTypeOf _ = swaggerItemsDataType
537+instance Data (SwaggerItems 'SwaggerKindSchema) where
538+ gfoldl _ _ (SwaggerItemsPrimitive _ _) = error " Data.Data.gfoldl: Constructor SwaggerItemsPrimitive used to construct SwaggerItems SwaggerKindSchema"
539+ gfoldl k z (SwaggerItemsObject ref) = z SwaggerItemsObject `k` ref
540+ gfoldl k z (SwaggerItemsArray ref) = z SwaggerItemsArray `k` ref
542+ gunfold k z c = case constrIndex c of
543+ 2 -> k (z SwaggerItemsObject)
544+ 3 -> k (z SwaggerItemsArray)
545+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type (SwaggerItems SwaggerKindSchema)."
547+ toConstr (SwaggerItemsPrimitive _ _) = error "Not supported"
548+ toConstr (SwaggerItemsObject _) = swaggerItemsObjectConstr
549+ toConstr (SwaggerItemsArray _) = swaggerItemsArrayConstr
551+ dataTypeOf _ = swaggerItemsDataType
553+-- | Type used as a kind to avoid overlapping instances.
555+ = SwaggerKindNormal t
556+ | SwaggerKindParamOtherSchema
560+deriving instance Typeable 'SwaggerKindNormal
561+deriving instance Typeable 'SwaggerKindParamOtherSchema
562+deriving instance Typeable 'SwaggerKindSchema
564+type family SwaggerKindType (k :: SwaggerKind *) :: *
565+type instance SwaggerKindType ('SwaggerKindNormal t) = t
566+type instance SwaggerKindType 'SwaggerKindSchema = Schema
567+type instance SwaggerKindType 'SwaggerKindParamOtherSchema = ParamOtherSchema
569+data SwaggerType t where
570+ SwaggerString :: SwaggerType t
571+ SwaggerNumber :: SwaggerType t
572+ SwaggerInteger :: SwaggerType t
573+ SwaggerBoolean :: SwaggerType t
574+ SwaggerArray :: SwaggerType t
575+ SwaggerFile :: SwaggerType 'SwaggerKindParamOtherSchema
576+ SwaggerNull :: SwaggerType 'SwaggerKindSchema
577+ SwaggerObject :: SwaggerType 'SwaggerKindSchema
580+deriving instance Eq (SwaggerType t)
581+deriving instance Show (SwaggerType t)
583+swaggerTypeConstr :: Data (SwaggerType t) => SwaggerType t -> Constr
584+swaggerTypeConstr t = mkConstr (dataTypeOf t) (show t) [] Prefix
586+swaggerTypeDataType :: {- Data (SwaggerType t) => -} SwaggerType t -> DataType
587+swaggerTypeDataType _ = mkDataType "Data.Swagger.SwaggerType" swaggerTypeConstrs
589+swaggerCommonTypes :: [SwaggerType k]
590+swaggerCommonTypes = [SwaggerString, SwaggerNumber, SwaggerInteger, SwaggerBoolean, SwaggerArray]
592+swaggerParamTypes :: [SwaggerType 'SwaggerKindParamOtherSchema]
593+swaggerParamTypes = swaggerCommonTypes ++ [SwaggerFile]
595+swaggerSchemaTypes :: [SwaggerType 'SwaggerKindSchema]
596+swaggerSchemaTypes = swaggerCommonTypes ++ [error "SwaggerFile is invalid SwaggerType Schema", SwaggerNull, SwaggerObject]
598+swaggerTypeConstrs :: [Constr]
599+swaggerTypeConstrs = map swaggerTypeConstr (swaggerCommonTypes :: [SwaggerType 'SwaggerKindSchema])
600+ ++ [swaggerTypeConstr SwaggerFile, swaggerTypeConstr SwaggerNull, swaggerTypeConstr SwaggerObject]
602+instance Typeable t => Data (SwaggerType ('SwaggerKindNormal t)) where
603+ gunfold = gunfoldEnum "SwaggerType" swaggerCommonTypes
604+ toConstr = swaggerTypeConstr
605+ dataTypeOf = swaggerTypeDataType
607+instance Data (SwaggerType 'SwaggerKindParamOtherSchema) where
608+ gunfold = gunfoldEnum "SwaggerType ParamOtherSchema" swaggerParamTypes
609+ toConstr = swaggerTypeConstr
610+ dataTypeOf = swaggerTypeDataType
612+instance Data (SwaggerType 'SwaggerKindSchema) where
613+ gunfold = gunfoldEnum "SwaggerType Schema" swaggerSchemaTypes
614+ toConstr = swaggerTypeConstr
615+ dataTypeOf = swaggerTypeDataType
599data ParamLocation
617data ParamLocation
600 = -- | Parameters that are appended to the URL.
618 = -- | Parameters that are appended to the URL.
@@ -612,6 +630,42 @@ data ParamLocation
613type Format = Text
631type Format = Text
633+-- | Determines the format of the array.
634+data CollectionFormat t where
635+ -- Comma separated values: @foo,bar@.
636+ CollectionCSV :: CollectionFormat t
637+ -- Space separated values: @foo bar@.
638+ CollectionSSV :: CollectionFormat t
639+ -- Tab separated values: @foo\\tbar@.
640+ CollectionTSV :: CollectionFormat t
641+ -- Pipe separated values: @foo|bar@.
642+ CollectionPipes :: CollectionFormat t
643+ -- Corresponds to multiple parameter instances
644+ -- instead of multiple values for a single instance @foo=bar&foo=baz@.
645+ -- This is valid only for parameters in @'ParamQuery'@ or @'ParamFormData'@.
646+ CollectionMulti :: CollectionFormat 'SwaggerKindParamOtherSchema
649+deriving instance Eq (CollectionFormat t)
650+deriving instance Show (CollectionFormat t)
652+collectionFormatConstr :: CollectionFormat t -> Constr
653+collectionFormatConstr cf = mkConstr collectionFormatDataType (show cf) [] Prefix
655+collectionFormatDataType :: DataType
656+collectionFormatDataType = mkDataType "Data.Swagger.CollectionFormat" $
657+ map collectionFormatConstr collectionCommonFormats
659+collectionCommonFormats :: [CollectionFormat t]
660+collectionCommonFormats = [ CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes ]
662+instance Data t => Data (CollectionFormat ('SwaggerKindNormal t)) where
663+ gunfold = gunfoldEnum "CollectionFormat" collectionCommonFormats
664+ toConstr = collectionFormatConstr
665+ dataTypeOf _ = collectionFormatDataType
667+deriving instance Data (CollectionFormat 'SwaggerKindParamOtherSchema)
615type ParamName = Text
669type ParamName = Text
617data Schema = Schema
671data Schema = Schema
@@ -638,33 +692,9 @@ data Schema = Schema
638 , _schemaMaxProperties :: Maybe Integer
692 , _schemaMaxProperties :: Maybe Integer
639 , _schemaMinProperties :: Maybe Integer
693 , _schemaMinProperties :: Maybe Integer
641− , -- | Declares the value of the parameter that the server will use if none is provided,
695+ , _schemaParamSchema :: ParamSchema 'SwaggerKindSchema
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)
696 } deriving (Eq, Show, Generic, Data, Typeable)
665−-- | Regex pattern for @string@ type.
668data Discriminator = Discriminator
698data Discriminator = Discriminator
669 { -- | The name of the property in the payload that will hold the discriminator value.
699 { -- | The name of the property in the payload that will hold the discriminator value.
670 _discriminatorPropertyName :: Text
700 _discriminatorPropertyName :: Text
@@ -680,9 +710,41 @@ data NamedSchema = NamedSchema
680 , _namedSchemaSchema :: Schema
710 , _namedSchemaSchema :: Schema
681 } deriving (Eq, Show, Generic, Data, Typeable)
711 } deriving (Eq, Show, Generic, Data, Typeable)
713+-- | Regex pattern for @string@ type.
716+-- TODO examples for params
718+data ParamSchema (t :: SwaggerKind *) = ParamSchema
719+ { -- | Declares the value of the parameter that the server will use if none is provided,
720+ -- for example a @"count"@ to control the number of results per page might default to @100@
721+ -- if not supplied by the client in the request.
722+ -- (Note: "default" has no meaning for required parameters.)
723+ -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
724+ _paramSchemaDefault :: Maybe Value
726+ , _paramSchemaType :: Maybe (SwaggerType t)
727+ , _paramSchemaFormat :: Maybe Format
728+ , _paramSchemaItems :: Maybe (SwaggerItems t)
729+ , _paramSchemaMaximum :: Maybe Scientific
730+ , _paramSchemaExclusiveMaximum :: Maybe Bool
731+ , _paramSchemaMinimum :: Maybe Scientific
732+ , _paramSchemaExclusiveMinimum :: Maybe Bool
733+ , _paramSchemaMaxLength :: Maybe Integer
734+ , _paramSchemaMinLength :: Maybe Integer
735+ , _paramSchemaPattern :: Maybe Pattern
736+ , _paramSchemaMaxItems :: Maybe Integer
737+ , _paramSchemaMinItems :: Maybe Integer
738+ , _paramSchemaUniqueItems :: Maybe Bool
739+ , _paramSchemaEnum :: Maybe [Value]
740+ , _paramSchemaMultipleOf :: Maybe Scientific
741+ } deriving (Eq, Show, Generic, Typeable)
743+deriving instance (Typeable k, Data (Maybe (SwaggerType k)), Data (SwaggerItems k)) => Data (ParamSchema k)
683data Xml = Xml
745data Xml = Xml
684 { -- | Replaces the name of the element/attribute used for the described schema property.
746 { -- | 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.
747+ -- 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),
748 -- When defined alongside type being array (outside the items),
687 -- it will affect the wrapping element and only if wrapped is true.
749 -- it will affect the wrapping element and only if wrapped is true.
688 -- If wrapped is false, it will be ignored.
750 -- If wrapped is false, it will be ignored.
@@ -734,46 +796,25 @@ data Response = Response
734 -- | A map containing descriptions of potential response payloads.
796 -- | A map containing descriptions of potential response payloads.
735 -- The key is a media type or media type range and the value describes it.
797 -- 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.
798 -- For responses that match multiple keys, only the most specific key is applicable.
737− -- e.g. @text/plain@ overrides @text/\*@.
799+ -- e.g. @text/plain@ overrides @text/*@.
738− , _responseContent :: InsOrdHashMap MediaType MediaTypeObject
800+ , _responseContent :: InsOrdHashMap Text MediaTypeObject
740 -- | Maps a header name to its definition.
802 -- | Maps a header name to its definition.
741 , _responseHeaders :: InsOrdHashMap HeaderName (Referenced Header)
803 , _responseHeaders :: InsOrdHashMap HeaderName (Referenced Header)
743− -- | A map of operations links that can be followed from the response.
805+ -- TODO links
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)
747 } deriving (Eq, Show, Generic, Data, Typeable)
806 } deriving (Eq, Show, Generic, Data, Typeable)
749instance IsString Response where
808instance IsString Response where
750− fromString s = Response (fromString s) mempty mempty mempty
809+ fromString s = Response (fromString s) mempty mempty
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)
760type HeaderName = Text
811type HeaderName = Text
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.
765data Header = Header
813data Header = Header
766 { -- | A short description of the header.
814 { -- | A short description of the header.
767− _headerDescription :: Maybe HeaderName
815+ _headerDescription :: Maybe Text
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)
817+ , _headerParamSchema :: ParamSchema ('SwaggerKindNormal Header)
777 } deriving (Eq, Show, Generic, Data, Typeable)
818 } deriving (Eq, Show, Generic, Data, Typeable)
779-- | The location of the API key.
820-- | The location of the API key.
@@ -797,17 +838,17 @@ type AuthorizationURL = Text
797-- | The token URL to be used for OAuth2 flow. This SHOULD be in the form of a URL.
838-- | The token URL to be used for OAuth2 flow. This SHOULD be in the form of a URL.
798type TokenURL = Text
839type TokenURL = Text
800−newtype OAuth2ImplicitFlow
841+data OAuth2ImplicitFlow = OAuth2ImplicitFlow
801− = OAuth2ImplicitFlow {_oAuth2ImplicitFlowAuthorizationUrl :: AuthorizationURL}
842+ { _oAuth2ImplicitFlowAuthorizationUrl :: AuthorizationURL
802− deriving (Eq, Show, Generic, Data, Typeable)
843+ } deriving (Eq, Show, Generic, Data, Typeable)
804−newtype OAuth2PasswordFlow
845+data OAuth2PasswordFlow = OAuth2PasswordFlow
805− = OAuth2PasswordFlow {_oAuth2PasswordFlowTokenUrl :: TokenURL}
846+ { _oAuth2PasswordFlowTokenUrl :: TokenURL
806− deriving (Eq, Show, Generic, Data, Typeable)
847+ } deriving (Eq, Show, Generic, Data, Typeable)
808−newtype OAuth2ClientCredentialsFlow
849+data OAuth2ClientCredentialsFlow = OAuth2ClientCredentialsFlow
809− = OAuth2ClientCredentialsFlow {_oAuth2ClientCredentialsFlowTokenUrl :: TokenURL}
850+ { _oAuth2ClientCredentialsFlowTokenUrl :: TokenURL
810− deriving (Eq, Show, Generic, Data, Typeable)
851+ } deriving (Eq, Show, Generic, Data, Typeable)
812data OAuth2AuthorizationCodeFlow = OAuth2AuthorizationCodeFlow
853data OAuth2AuthorizationCodeFlow = OAuth2AuthorizationCodeFlow
813 { _oAuth2AuthorizationCodeFlowAuthorizationUrl :: AuthorizationURL
854 { _oAuth2AuthorizationCodeFlowAuthorizationUrl :: AuthorizationURL
@@ -840,50 +881,8 @@ data OAuth2Flows = OAuth2Flows
840 , _oAuth2FlowsAuthorizationCode :: Maybe (OAuth2Flow OAuth2AuthorizationCodeFlow)
881 , _oAuth2FlowsAuthorizationCode :: Maybe (OAuth2Flow OAuth2AuthorizationCodeFlow)
841 } deriving (Eq, Show, Generic, Data, Typeable)
882 } 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
884data SecuritySchemeType
886− = SecuritySchemeHttp HttpSchemeType
885+ = SecuritySchemeHttp
887 | SecuritySchemeApiKey ApiKeyParams
886 | SecuritySchemeApiKey ApiKeyParams
888 | SecuritySchemeOAuth2 OAuth2Flows
887 | SecuritySchemeOAuth2 OAuth2Flows
889 | SecuritySchemeOpenIdConnect URL
888 | SecuritySchemeOpenIdConnect URL
@@ -897,10 +896,6 @@ data SecurityScheme = SecurityScheme
897 , _securitySchemeDescription :: Maybe Text
896 , _securitySchemeDescription :: Maybe Text
898 } deriving (Eq, Show, Generic, Data, Typeable)
897 } deriving (Eq, Show, Generic, Data, Typeable)
900−newtype SecurityDefinitions
901− = SecurityDefinitions (Definitions SecurityScheme)
902− deriving (Eq, Show, Generic, Data, Typeable)
904-- | Lists the required security schemes to execute this operation.
899-- | Lists the required security schemes to execute this operation.
905-- The object can have multiple security schemes declared in it which are all required
900-- The object can have multiple security schemes declared in it which are all required
906-- (that is, there is a logical AND between the schemes).
901-- (that is, there is a logical AND between the schemes).
@@ -918,7 +913,7 @@ data Tag = Tag
918 _tagName :: TagName
913 _tagName :: TagName
920 -- | A short description for the tag.
915 -- | A short description for the tag.
921− -- [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
916+ -- GFM syntax can be used for rich text representation.
922 , _tagDescription :: Maybe Text
917 , _tagDescription :: Maybe Text
924 -- | Additional external documentation for this tag.
919 -- | Additional external documentation for this tag.
@@ -933,7 +928,7 @@ instance IsString Tag where
933-- | Allows referencing an external resource for extended documentation.
928-- | Allows referencing an external resource for extended documentation.
934data ExternalDocs = ExternalDocs
929data ExternalDocs = ExternalDocs
935 { -- | A short description of the target documentation.
930 { -- | A short description of the target documentation.
936− -- [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
931+ -- GFM syntax can be used for rich text representation.
937 _externalDocsDescription :: Maybe Text
932 _externalDocsDescription :: Maybe Text
939 -- | The URL for the target documentation.
934 -- | The URL for the target documentation.
@@ -966,13 +961,13 @@ data AdditionalProperties
966-- Generic instances
961-- Generic instances
967-------------------------------------------------------------------------------
962-------------------------------------------------------------------------------
969−deriveGeneric ''Server
970deriveGeneric ''Components
964deriveGeneric ''Components
971deriveGeneric ''Header
965deriveGeneric ''Header
972deriveGeneric ''OAuth2Flow
966deriveGeneric ''OAuth2Flow
973deriveGeneric ''OAuth2Flows
967deriveGeneric ''OAuth2Flows
974deriveGeneric ''Operation
968deriveGeneric ''Operation
975deriveGeneric ''Param
969deriveGeneric ''Param
970+deriveGeneric ''ParamOtherSchema
976deriveGeneric ''PathItem
971deriveGeneric ''PathItem
977deriveGeneric ''Response
972deriveGeneric ''Response
978deriveGeneric ''RequestBody
973deriveGeneric ''RequestBody
@@ -980,18 +975,18 @@ deriveGeneric ''MediaTypeObject
980deriveGeneric ''Responses
975deriveGeneric ''Responses
981deriveGeneric ''SecurityScheme
976deriveGeneric ''SecurityScheme
982deriveGeneric ''Schema
977deriveGeneric ''Schema
983−deriveGeneric ''OpenApi
978+deriveGeneric ''ParamSchema
979+deriveGeneric ''Swagger
984deriveGeneric ''Example
980deriveGeneric ''Example
985deriveGeneric ''Encoding
981deriveGeneric ''Encoding
988-- =======================================================================
983-- =======================================================================
989-- Monoid instances
984-- Monoid instances
990-- =======================================================================
985-- =======================================================================
992−instance Semigroup OpenApi where
987+instance Semigroup Swagger where
993 (<>) = genericMappend
988 (<>) = genericMappend
994−instance Monoid OpenApi where
989+instance Monoid Swagger where
995 mempty = genericMempty
990 mempty = genericMempty
996 mappend = (<>)
991 mappend = (<>)
@@ -1025,12 +1020,24 @@ instance Monoid Schema where
1025 mempty = genericMempty
1020 mempty = genericMempty
1026 mappend = (<>)
1021 mappend = (<>)
1023+instance Semigroup (ParamSchema t) where
1024+ (<>) = genericMappend
1025+instance Monoid (ParamSchema t) where
1026+ mempty = genericMempty
1028instance Semigroup Param where
1029instance Semigroup Param where
1029 (<>) = genericMappend
1030 (<>) = genericMappend
1030instance Monoid Param where
1031instance Monoid Param where
1031 mempty = genericMempty
1032 mempty = genericMempty
1032 mappend = (<>)
1033 mappend = (<>)
1035+instance Semigroup ParamOtherSchema where
1036+ (<>) = genericMappend
1037+instance Monoid ParamOtherSchema where
1038+ mempty = genericMempty
1034instance Semigroup Header where
1041instance Semigroup Header where
1035 (<>) = genericMappend
1042 (<>) = genericMappend
1036instance Monoid Header where
1043instance Monoid Header where
@@ -1073,41 +1080,9 @@ instance Monoid Operation where
1073 mempty = genericMempty
1080 mempty = genericMempty
1074 mappend = (<>)
1081 mappend = (<>)
1076−instance Semigroup (OAuth2Flow p) where
1077− l@OAuth2Flow{ _oAath2RefreshUrl = lUrl, _oAuth2Scopes = lScopes }
1078− <> OAuth2Flow { _oAath2RefreshUrl = rUrl, _oAuth2Scopes = rScopes } =
1079− l { _oAath2RefreshUrl = swaggerMappend lUrl rUrl, _oAuth2Scopes = lScopes <> rScopes }
1081−-- swaggerMappend has First-like semantics, and here we need mappend'ing under Maybes.
1082instance Semigroup OAuth2Flows where
1083instance Semigroup OAuth2Flows where
1083− l <> r = OAuth2Flows
1084− { _oAuth2FlowsImplicit = _oAuth2FlowsImplicit l <> _oAuth2FlowsImplicit r
1085− , _oAuth2FlowsPassword = _oAuth2FlowsPassword l <> _oAuth2FlowsPassword r
1086− , _oAuth2FlowsClientCredentials = _oAuth2FlowsClientCredentials l <> _oAuth2FlowsClientCredentials r
1087− , _oAuth2FlowsAuthorizationCode = _oAuth2FlowsAuthorizationCode l <> _oAuth2FlowsAuthorizationCode r
1090−instance Monoid OAuth2Flows where
1091− mempty = genericMempty
1094−instance Semigroup SecurityScheme where
1095− SecurityScheme (SecuritySchemeOAuth2 lFlows) lDesc
1096− <> SecurityScheme (SecuritySchemeOAuth2 rFlows) rDesc =
1097− SecurityScheme (SecuritySchemeOAuth2 $ lFlows <> rFlows) (swaggerMappend lDesc rDesc)
1100−instance Semigroup SecurityDefinitions where
1101− (SecurityDefinitions sd1) <> (SecurityDefinitions sd2) =
1102− SecurityDefinitions $ InsOrdHashMap.unionWith (<>) sd1 sd2
1104−instance Monoid SecurityDefinitions where
1105− mempty = SecurityDefinitions InsOrdHashMap.empty
1108−instance Semigroup RequestBody where
1109 (<>) = genericMappend
1084 (<>) = genericMappend
1110−instance Monoid RequestBody where
1085+instance Monoid OAuth2Flows where
1111 mempty = genericMempty
1086 mempty = genericMempty
1112 mappend = (<>)
1087 mappend = (<>)
@@ -1119,19 +1094,20 @@ instance SwaggerMonoid Info
1119instance SwaggerMonoid Components
1094instance SwaggerMonoid Components
1120instance SwaggerMonoid PathItem
1095instance SwaggerMonoid PathItem
1121instance SwaggerMonoid Schema
1096instance SwaggerMonoid Schema
1097+instance SwaggerMonoid (ParamSchema t)
1122instance SwaggerMonoid Param
1098instance SwaggerMonoid Param
1099+instance SwaggerMonoid ParamOtherSchema
1123instance SwaggerMonoid Responses
1100instance SwaggerMonoid Responses
1124instance SwaggerMonoid Response
1101instance SwaggerMonoid Response
1125instance SwaggerMonoid ExternalDocs
1102instance SwaggerMonoid ExternalDocs
1126instance SwaggerMonoid Operation
1103instance SwaggerMonoid Operation
1127instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
1104instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
1128−instance SwaggerMonoid SecurityDefinitions
1130instance SwaggerMonoid MimeList
1106instance SwaggerMonoid MimeList
1131deriving instance SwaggerMonoid URL
1107deriving instance SwaggerMonoid URL
1133−instance SwaggerMonoid OpenApiType where
1109+instance SwaggerMonoid (SwaggerType t) where
1134− swaggerMempty = OpenApiString
1110+ swaggerMempty = SwaggerString
1135 swaggerMappend _ y = y
1111 swaggerMappend _ y = y
1137instance SwaggerMonoid ParamLocation where
1113instance SwaggerMonoid ParamLocation where
@@ -1147,16 +1123,16 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
1147 swaggerMappend (Inline x) (Inline y) = Inline (mappend x y)
1123 swaggerMappend (Inline x) (Inline y) = Inline (mappend x y)
1148 swaggerMappend _ y = y
1124 swaggerMappend _ y = y
1126+instance SwaggerMonoid ParamAnySchema where
1127+ swaggerMempty = ParamOther swaggerMempty
1128+ swaggerMappend (ParamBody x) (ParamBody y) = ParamBody (swaggerMappend x y)
1129+ swaggerMappend (ParamOther x) (ParamOther y) = ParamOther (swaggerMappend x y)
1130+ swaggerMappend _ y = y
1150-- =======================================================================
1132-- =======================================================================
1151-- Simple Generic-based ToJSON instances
1133-- Simple Generic-based ToJSON instances
1152-- =======================================================================
1134-- =======================================================================
1154−instance ToJSON Style where
1155− toJSON = genericToJSON (jsonPrefix "Style")
1157−instance ToJSON OpenApiType where
1158− toJSON = genericToJSON (jsonPrefix "Swagger")
1160instance ToJSON ParamLocation where
1136instance ToJSON ParamLocation where
1161 toJSON = genericToJSON (jsonPrefix "Param")
1137 toJSON = genericToJSON (jsonPrefix "Param")
@@ -1169,6 +1145,9 @@ instance ToJSON Contact where
1169instance ToJSON License where
1145instance ToJSON License where
1170 toJSON = genericToJSON (jsonPrefix "License")
1146 toJSON = genericToJSON (jsonPrefix "License")
1148+instance ToJSON Server where
1149+ toJSON = genericToJSON (jsonPrefix "Server")
1172instance ToJSON ServerVariable where
1151instance ToJSON ServerVariable where
1173 toJSON = genericToJSON (jsonPrefix "ServerVariable")
1152 toJSON = genericToJSON (jsonPrefix "ServerVariable")
@@ -1178,6 +1157,9 @@ instance ToJSON ApiKeyLocation where
1178instance ToJSON ApiKeyParams where
1157instance ToJSON ApiKeyParams where
1179 toJSON = genericToJSON (jsonPrefix "apiKey")
1158 toJSON = genericToJSON (jsonPrefix "apiKey")
1160+instance ToJSON Scheme where
1161+ toJSON = genericToJSON (jsonPrefix "")
1181instance ToJSON Tag where
1163instance ToJSON Tag where
1182 toJSON = genericToJSON (jsonPrefix "Tag")
1164 toJSON = genericToJSON (jsonPrefix "Tag")
@@ -1206,12 +1188,6 @@ instance ToJSON OAuth2AuthorizationCodeFlow where
1206-- Simple Generic-based FromJSON instances
1188-- Simple Generic-based FromJSON instances
1207-- =======================================================================
1189-- =======================================================================
1209−instance FromJSON Style where
1210− parseJSON = genericParseJSON (jsonPrefix "Style")
1212−instance FromJSON OpenApiType where
1213− parseJSON = genericParseJSON (jsonPrefix "Swagger")
1215instance FromJSON ParamLocation where
1191instance FromJSON ParamLocation where
1216 parseJSON = genericParseJSON (jsonPrefix "Param")
1192 parseJSON = genericParseJSON (jsonPrefix "Param")
@@ -1224,6 +1200,9 @@ instance FromJSON Contact where
1224instance FromJSON License where
1200instance FromJSON License where
1225 parseJSON = genericParseJSON (jsonPrefix "License")
1201 parseJSON = genericParseJSON (jsonPrefix "License")
1203+instance FromJSON Server where
1204+ parseJSON = genericParseJSON (jsonPrefix "Server")
1227instance FromJSON ServerVariable where
1206instance FromJSON ServerVariable where
1228 parseJSON = genericParseJSON (jsonPrefix "ServerVariable")
1207 parseJSON = genericParseJSON (jsonPrefix "ServerVariable")
@@ -1233,6 +1212,9 @@ instance FromJSON ApiKeyLocation where
1233instance FromJSON ApiKeyParams where
1212instance FromJSON ApiKeyParams where
1234 parseJSON = genericParseJSON (jsonPrefix "apiKey")
1213 parseJSON = genericParseJSON (jsonPrefix "apiKey")
1215+instance FromJSON Scheme where
1216+ parseJSON = genericParseJSON (jsonPrefix "")
1236instance FromJSON Tag where
1218instance FromJSON Tag where
1237 parseJSON = genericParseJSON (jsonPrefix "Tag")
1219 parseJSON = genericParseJSON (jsonPrefix "Tag")
@@ -1258,14 +1240,7 @@ instance FromJSON OAuth2AuthorizationCodeFlow where
1258-- Manual ToJSON instances
1240-- Manual ToJSON instances
1259-- =======================================================================
1241-- =======================================================================
1261−instance ToJSON MediaType where
1262− toJSON = toJSON . show
1263− toEncoding = toEncoding . show
1265−instance ToJSONKey MediaType where
1266− toJSONKey = JSON.toJSONKeyText (Text.pack . show)
1268−instance (Eq p, ToJSON p, AesonDefaultValue p) => ToJSON (OAuth2Flow p) where
1243+instance (Eq p, ToJSON p, AesonDefaultValue p) =>ToJSON (OAuth2Flow p) where
1269 toJSON = sopSwaggerGenericToJSON
1244 toJSON = sopSwaggerGenericToJSON
1270 toEncoding = sopSwaggerGenericToEncoding
1245 toEncoding = sopSwaggerGenericToEncoding
@@ -1274,49 +1249,33 @@ instance ToJSON OAuth2Flows where
1274 toEncoding = sopSwaggerGenericToEncoding
1249 toEncoding = sopSwaggerGenericToEncoding
1276instance ToJSON SecuritySchemeType where
1251instance ToJSON SecuritySchemeType where
1277− toJSON (SecuritySchemeHttp ty) = case ty of
1252+ 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)
1253+ = object [ "type" .= ("http" :: Text) ]
1290 toJSON (SecuritySchemeApiKey params)
1254 toJSON (SecuritySchemeApiKey params)
1291 = toJSON params
1255 = toJSON params
1292 <+> object [ "type" .= ("apiKey" :: Text) ]
1256 <+> object [ "type" .= ("apiKey" :: Text) ]
1293− toJSON (SecuritySchemeOAuth2 params) = object
1257+ toJSON (SecuritySchemeOAuth2 params)
1294− [ "type" .= ("oauth2" :: Text)
1259+ <+> object [ "type" .= ("oauth2" :: Text) ]
1295− , "flows" .= toJSON params
1297 toJSON (SecuritySchemeOpenIdConnect url) = object
1260 toJSON (SecuritySchemeOpenIdConnect url) = object
1298 [ "type" .= ("openIdConnect" :: Text)
1261 [ "type" .= ("openIdConnect" :: Text)
1299 , "openIdConnectUrl" .= url
1262 , "openIdConnectUrl" .= url
1302−instance ToJSON OpenApi where
1265+instance ToJSON Swagger where
1303 toJSON a = sopSwaggerGenericToJSON a &
1266 toJSON a = sopSwaggerGenericToJSON a &
1304− if InsOrdHashMap.null (_openApiPaths a)
1267+ if InsOrdHashMap.null (_swaggerPaths a)
1305 then (<+> object ["paths" .= object []])
1268 then (<+> object ["paths" .= object []])
1307 toEncoding = sopSwaggerGenericToEncoding
1270 toEncoding = sopSwaggerGenericToEncoding
1309−instance ToJSON Server where
1310− toJSON = sopSwaggerGenericToJSON
1311− toEncoding = sopSwaggerGenericToEncoding
1313instance ToJSON SecurityScheme where
1272instance ToJSON SecurityScheme where
1314 toJSON = sopSwaggerGenericToJSON
1273 toJSON = sopSwaggerGenericToJSON
1315 toEncoding = sopSwaggerGenericToEncoding
1274 toEncoding = sopSwaggerGenericToEncoding
1317instance ToJSON Schema where
1276instance ToJSON Schema where
1318− toJSON = sopSwaggerGenericToJSONWithOpts $
1277+ toJSON = sopSwaggerGenericToJSON
1319− mkSwaggerAesonOptions "schema" & saoSubObject ?~ "items"
1278+ toEncoding = sopSwaggerGenericToEncoding
1321instance ToJSON Header where
1280instance ToJSON Header where
1322 toJSON = sopSwaggerGenericToJSON
1281 toJSON = sopSwaggerGenericToJSON
@@ -1325,26 +1284,31 @@ instance ToJSON Header where
1325-- | As for nullary schema for 0-arity type constructors, see
1284-- | As for nullary schema for 0-arity type constructors, see
1326-- <https://github.com/GetShopTV/swagger2/issues/167>.
1285-- <https://github.com/GetShopTV/swagger2/issues/167>.
1328−-- >>> BSL.putStrLn $ encodePretty (OpenApiItemsArray [])
1287+-- >>> encode (SwaggerItemsArray [])
1332−-- "maxItems": 0
1288+-- "{\"example\":[],\"items\":{},\"maxItems\":0}"
1335−instance ToJSON OpenApiItems where
1290+instance ToJSON (ParamSchema t) => ToJSON (SwaggerItems t) where
1336− toJSON (OpenApiItemsObject x) = object [ "items" .= x ]
1291+ toJSON (SwaggerItemsPrimitive fmt schema) = object
1292+ [ "collectionFormat" .= fmt
1293+ , "items" .= schema ]
1294+ toJSON (SwaggerItemsObject x) = object [ "items" .= x ]
1337− toJSON (OpenApiItemsArray []) = object
1295+ toJSON (SwaggerItemsArray []) = object
1338 [ "items" .= object []
1296 [ "items" .= object []
1339 , "maxItems" .= (0 :: Int)
1297 , "maxItems" .= (0 :: Int)
1340 , "example" .= Array mempty
1298 , "example" .= Array mempty
1342− toJSON (OpenApiItemsArray x) = object [ "items" .= x ]
1300+ toJSON (SwaggerItemsArray x) = object [ "items" .= x ]
1344instance ToJSON Components where
1302instance ToJSON Components where
1345 toJSON = sopSwaggerGenericToJSON
1303 toJSON = sopSwaggerGenericToJSON
1346 toEncoding = sopSwaggerGenericToEncoding
1304 toEncoding = sopSwaggerGenericToEncoding
1306+instance ToJSON Host where
1307+ toJSON (Host host mport) = toJSON $
1310+ Just port -> host ++ ":" ++ show port
1348instance ToJSON MimeList where
1312instance ToJSON MimeList where
1349 toJSON (MimeList xs) = toJSON (map show xs)
1313 toJSON (MimeList xs) = toJSON (map show xs)
@@ -1352,6 +1316,14 @@ instance ToJSON Param where
1352 toJSON = sopSwaggerGenericToJSON
1316 toJSON = sopSwaggerGenericToJSON
1353 toEncoding = sopSwaggerGenericToEncoding
1317 toEncoding = sopSwaggerGenericToEncoding
1319+instance ToJSON ParamAnySchema where
1320+ toJSON (ParamBody s) = object [ "in" .= ("body" :: Text), "schema" .= s ]
1321+ toJSON (ParamOther s) = toJSON s
1323+instance ToJSON ParamOtherSchema where
1324+ toJSON = sopSwaggerGenericToJSON
1325+ toEncoding = sopSwaggerGenericToEncoding
1355instance ToJSON Responses where
1327instance ToJSON Responses where
1356 toJSON = sopSwaggerGenericToJSON
1328 toJSON = sopSwaggerGenericToJSON
1357 toEncoding = sopSwaggerGenericToEncoding
1329 toEncoding = sopSwaggerGenericToEncoding
@@ -1384,13 +1356,6 @@ instance ToJSON Encoding where
1384 toJSON = sopSwaggerGenericToJSON
1356 toJSON = sopSwaggerGenericToJSON
1385 toEncoding = sopSwaggerGenericToEncoding
1357 toEncoding = sopSwaggerGenericToEncoding
1387−instance ToJSON Link where
1388− toJSON = sopSwaggerGenericToJSON
1389− toEncoding = sopSwaggerGenericToEncoding
1391−instance ToJSON SecurityDefinitions where
1392− toJSON (SecurityDefinitions sd) = toJSON sd
1394instance ToJSON Reference where
1359instance ToJSON Reference where
1395 toJSON (Reference ref) = object [ "$ref" .= ref ]
1360 toJSON (Reference ref) = object [ "$ref" .= ref ]
@@ -1404,31 +1369,37 @@ instance ToJSON (Referenced Response) where toJSON = referencedToJSON "#/compone
1404instance ToJSON (Referenced RequestBody) where toJSON = referencedToJSON "#/components/requestBodies/"
1369instance ToJSON (Referenced RequestBody) where toJSON = referencedToJSON "#/components/requestBodies/"
1405instance ToJSON (Referenced Example) where toJSON = referencedToJSON "#/components/examples/"
1370instance ToJSON (Referenced Example) where toJSON = referencedToJSON "#/components/examples/"
1406instance ToJSON (Referenced Header) where toJSON = referencedToJSON "#/components/headers/"
1371instance ToJSON (Referenced Header) where toJSON = referencedToJSON "#/components/headers/"
1407−instance ToJSON (Referenced Link) where toJSON = referencedToJSON "#/components/links/"
1372+
1408−instance ToJSON (Referenced Callback) where toJSON = referencedToJSON "#/components/callbacks/"
1373+instance ToJSON (SwaggerType t) where
1374+ toJSON SwaggerArray = "array"
1375+ toJSON SwaggerString = "string"
1376+ toJSON SwaggerInteger = "integer"
1377+ toJSON SwaggerNumber = "number"
1378+ toJSON SwaggerBoolean = "boolean"
1379+ toJSON SwaggerFile = "file"
1380+ toJSON SwaggerNull = "null"
1381+ toJSON SwaggerObject = "object"
1383+instance ToJSON (CollectionFormat t) where
1384+ toJSON CollectionCSV = "csv"
1385+ toJSON CollectionSSV = "ssv"
1386+ toJSON CollectionTSV = "tsv"
1387+ toJSON CollectionPipes = "pipes"
1388+ toJSON CollectionMulti = "multi"
1390+instance ToJSON (ParamSchema k) where
1391+ -- TODO: this is a bit fishy, why we need sub object only in `ToJSON`?
1392+ toJSON = sopSwaggerGenericToJSONWithOpts $
1393+ mkSwaggerAesonOptions "paramSchema" & saoSubObject ?~ "items"
1410instance ToJSON AdditionalProperties where
1395instance ToJSON AdditionalProperties where
1411 toJSON (AdditionalPropertiesAllowed b) = toJSON b
1396 toJSON (AdditionalPropertiesAllowed b) = toJSON b
1412 toJSON (AdditionalPropertiesSchema s) = toJSON s
1397 toJSON (AdditionalPropertiesSchema s) = toJSON s
1414−instance ToJSON ExpressionOrValue where
1415− toJSON (Expression expr) = toJSON expr
1416− toJSON (Value val) = toJSON val
1418−instance ToJSON Callback where
1419− toJSON (Callback ps) = toJSON ps
1421-- =======================================================================
1399-- =======================================================================
1422-- Manual FromJSON instances
1400-- Manual FromJSON instances
1423-- =======================================================================
1401-- =======================================================================
1425−instance FromJSON MediaType where
1426− parseJSON = withText "MediaType" $ \str ->
1427− maybe (fail $ "Invalid media type literal " <> Text.unpack str) pure $ parseAccept $ encodeUtf8 str
1429−instance FromJSONKey MediaType where
1430− fromJSONKey = FromJSONKeyTextParser (parseJSON . String)
1432instance (Eq p, FromJSON p, AesonDefaultValue p) => FromJSON (OAuth2Flow p) where
1403instance (Eq p, FromJSON p, AesonDefaultValue p) => FromJSON (OAuth2Flow p) where
1433 parseJSON = sopSwaggerGenericParseJSON
1404 parseJSON = sopSwaggerGenericParseJSON
@@ -1439,22 +1410,14 @@ instance FromJSON SecuritySchemeType where
1439 parseJSON js@(Object o) = do
1410 parseJSON js@(Object o) = do
1440 (t :: Text) <- o .: "type"
1411 (t :: Text) <- o .: "type"
1441 case t of
1412 case t of
1443− scheme <- o .: "scheme"
1444− SecuritySchemeHttp <$> case scheme of
1413+ "http" -> pure SecuritySchemeHttp
1445− "bearer" -> HttpSchemeBearer <$> (o .:! "bearerFormat")
1446− "basic" -> pure HttpSchemeBasic
1447− t -> pure $ HttpSchemeCustom t
1448 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
1414 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
1449− "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
1415+ "oauth2" -> SecuritySchemeOAuth2 <$> parseJSON js
1450 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
1416 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
1451 _ -> empty
1417 _ -> empty
1452 parseJSON _ = empty
1418 parseJSON _ = empty
1454−instance FromJSON OpenApi where
1420+instance FromJSON Swagger where
1455− parseJSON = sopSwaggerGenericParseJSON
1457−instance FromJSON Server where
1458 parseJSON = sopSwaggerGenericParseJSON
1421 parseJSON = sopSwaggerGenericParseJSON
1460instance FromJSON SecurityScheme where
1423instance FromJSON SecurityScheme where
@@ -1463,36 +1426,78 @@ instance FromJSON SecurityScheme where
1463instance FromJSON Schema where
1426instance FromJSON Schema where
1464 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
1427 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
1465 where nullaryCleanup :: Schema -> Schema
1428 where nullaryCleanup :: Schema -> Schema
1466− nullaryCleanup s =
1429+ nullaryCleanup s@Schema{_schemaParamSchema=ps} =
1467− if _schemaItems s == Just (OpenApiItemsArray [])
1430+ if _paramSchemaItems ps == Just (SwaggerItemsArray [])
1468 then s { _schemaExample = Nothing
1431 then s { _schemaExample = Nothing
1469− , _schemaMaxItems = Nothing
1432+ , _schemaParamSchema = ps { _paramSchemaMaxItems = Nothing } }
1473instance FromJSON Header where
1435instance FromJSON Header where
1474 parseJSON = sopSwaggerGenericParseJSON
1436 parseJSON = sopSwaggerGenericParseJSON
1476−instance FromJSON OpenApiItems where
1438+instance (FromJSON (CollectionFormat ('SwaggerKindNormal t)), FromJSON (ParamSchema ('SwaggerKindNormal t))) => FromJSON (SwaggerItems ('SwaggerKindNormal t)) where
1439+ parseJSON = withObject "SwaggerItemsPrimitive" $ \o -> SwaggerItemsPrimitive
1440+ <$> o .:? "collectionFormat"
1441+ <*> (o .: "items" >>= parseJSON)
1443+instance FromJSON (SwaggerItems 'SwaggerKindParamOtherSchema) where
1444+ parseJSON = withObject "SwaggerItemsPrimitive" $ \o -> SwaggerItemsPrimitive
1445+ <$> o .:? "collectionFormat"
1446+ <*> ((o .: "items" >>= parseJSON) <|> fail ("foo" ++ show o))
1450+-- >>> decode "{}" :: Maybe (SwaggerItems 'SwaggerKindSchema)
1451+-- Just (SwaggerItemsArray [])
1453+-- >>> eitherDecode "{\"$ref\":\"#/definitions/example\"}" :: Either String (SwaggerItems 'SwaggerKindSchema)
1454+-- Right (SwaggerItemsObject (Ref (Reference {getReference = "example"})))
1456+-- >>> eitherDecode "[{\"$ref\":\"#/definitions/example\"}]" :: Either String (SwaggerItems 'SwaggerKindSchema)
1457+-- Right (SwaggerItemsArray [Ref (Reference {getReference = "example"})])
1459+instance FromJSON (SwaggerItems 'SwaggerKindSchema) where
1477 parseJSON js@(Object obj)
1460 parseJSON js@(Object obj)
1478− | null obj = pure $ OpenApiItemsArray [] -- Nullary schema.
1461+ | null obj = pure $ SwaggerItemsArray [] -- Nullary schema.
1479− | otherwise = OpenApiItemsObject <$> parseJSON js
1462+ | otherwise = SwaggerItemsObject <$> parseJSON js
1480− parseJSON js@(Array _) = OpenApiItemsArray <$> parseJSON js
1463+ parseJSON js@(Array _) = SwaggerItemsArray <$> parseJSON js
1481 parseJSON _ = empty
1464 parseJSON _ = empty
1483instance FromJSON Components where
1466instance FromJSON Components where
1484 parseJSON = sopSwaggerGenericParseJSON
1467 parseJSON = sopSwaggerGenericParseJSON
1469+instance FromJSON Host where
1470+ parseJSON (String s) = case map Text.unpack $ Text.split (== ':') s of
1471+ [host] -> return $ Host host Nothing
1472+ [host, port] -> case readMaybe port of
1473+ Nothing -> fail $ "Invalid port `" ++ port ++ "'"
1474+ Just p -> return $ Host host (Just (fromInteger p))
1475+ _ -> fail $ "Invalid host `" ++ Text.unpack s ++ "'"
1476+ parseJSON _ = empty
1486instance FromJSON MimeList where
1478instance FromJSON MimeList where
1487− parseJSON js = MimeList . map fromString <$> parseJSON js
1479+ parseJSON js = (MimeList . map fromString) <$> parseJSON js
1489instance FromJSON Param where
1481instance FromJSON Param where
1490 parseJSON = sopSwaggerGenericParseJSON
1482 parseJSON = sopSwaggerGenericParseJSON
1484+instance FromJSON ParamAnySchema where
1485+ parseJSON js@(Object o) = do
1486+ (i :: Text) <- o .: "in"
1489+ schema <- o .: "schema"
1490+ ParamBody <$> parseJSON schema
1491+ _ -> ParamOther <$> parseJSON js
1492+ parseJSON _ = empty
1494+instance FromJSON ParamOtherSchema where
1495+ parseJSON = sopSwaggerGenericParseJSON
1492instance FromJSON Responses where
1497instance FromJSON Responses where
1493 parseJSON (Object o) = Responses
1498 parseJSON (Object o) = Responses
1494 <$> o .:? "default"
1499 <$> o .:? "default"
1495− <*> parseJSON (Object (deleteKey "default" o))
1500+ <*> (parseJSON (Object (HashMap.delete "default" o)))
1496 parseJSON _ = empty
1501 parseJSON _ = empty
1498instance FromJSON Example where
1503instance FromJSON Example where
@@ -1507,9 +1512,6 @@ instance FromJSON Operation where
1507instance FromJSON PathItem where
1512instance FromJSON PathItem where
1508 parseJSON = sopSwaggerGenericParseJSON
1513 parseJSON = sopSwaggerGenericParseJSON
1510−instance FromJSON SecurityDefinitions where
1511− parseJSON js = SecurityDefinitions <$> parseJSON js
1513instance FromJSON RequestBody where
1515instance FromJSON RequestBody where
1514 parseJSON = sopSwaggerGenericParseJSON
1516 parseJSON = sopSwaggerGenericParseJSON
@@ -1519,9 +1521,6 @@ instance FromJSON MediaTypeObject where
1519instance FromJSON Encoding where
1521instance FromJSON Encoding where
1520 parseJSON = sopSwaggerGenericParseJSON
1522 parseJSON = sopSwaggerGenericParseJSON
1522−instance FromJSON Link where
1523− parseJSON = sopSwaggerGenericParseJSON
1525instance FromJSON Reference where
1524instance FromJSON Reference where
1526 parseJSON (Object o) = Reference <$> o .: "$ref"
1525 parseJSON (Object o) = Reference <$> o .: "$ref"
1527 parseJSON _ = empty
1526 parseJSON _ = empty
@@ -1545,30 +1544,44 @@ instance FromJSON (Referenced Response) where parseJSON = referencedParseJSON "#
1545instance FromJSON (Referenced RequestBody) where parseJSON = referencedParseJSON "#/components/requestBodies/"
1544instance FromJSON (Referenced RequestBody) where parseJSON = referencedParseJSON "#/components/requestBodies/"
1546instance FromJSON (Referenced Example) where parseJSON = referencedParseJSON "#/components/examples/"
1545instance FromJSON (Referenced Example) where parseJSON = referencedParseJSON "#/components/examples/"
1547instance FromJSON (Referenced Header) where parseJSON = referencedParseJSON "#/components/headers/"
1546instance 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/"
1551instance FromJSON Xml where
1548instance FromJSON Xml where
1552 parseJSON = genericParseJSON (jsonPrefix "xml")
1549 parseJSON = genericParseJSON (jsonPrefix "xml")
1551+instance FromJSON (SwaggerType 'SwaggerKindSchema) where
1552+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray, SwaggerNull, SwaggerObject]
1554+instance FromJSON (SwaggerType 'SwaggerKindParamOtherSchema) where
1555+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray, SwaggerFile]
1557+instance FromJSON (SwaggerType ('SwaggerKindNormal t)) where
1558+ parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray]
1560+instance FromJSON (CollectionFormat ('SwaggerKindNormal t)) where
1561+ parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
1563+-- NOTE: There aren't collections of 'Schema'
1564+--instance FromJSON (CollectionFormat (SwaggerKindSchema)) where
1565+-- parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
1567+instance FromJSON (CollectionFormat 'SwaggerKindParamOtherSchema) where
1568+ parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes, CollectionMulti]
1570+instance (FromJSON (SwaggerType ('SwaggerKindNormal t)), FromJSON (SwaggerItems ('SwaggerKindNormal t))) => FromJSON (ParamSchema ('SwaggerKindNormal t)) where
1571+ parseJSON = sopSwaggerGenericParseJSON
1572+instance FromJSON (ParamSchema 'SwaggerKindParamOtherSchema) where
1573+ parseJSON = sopSwaggerGenericParseJSON
1574+instance FromJSON (ParamSchema 'SwaggerKindSchema) where
1575+ parseJSON = sopSwaggerGenericParseJSON
1554instance FromJSON AdditionalProperties where
1577instance FromJSON AdditionalProperties where
1555 parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
1578 parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
1556 parseJSON js = AdditionalPropertiesSchema <$> parseJSON js
1579 parseJSON js = AdditionalPropertiesSchema <$> parseJSON js
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
1563−instance FromJSON Callback where
1564− parseJSON = fmap Callback . parseJSON
1566−instance HasSwaggerAesonOptions Server where
1567− swaggerAesonOptions _ = mkSwaggerAesonOptions "server"
1568instance HasSwaggerAesonOptions Components where
1581instance HasSwaggerAesonOptions Components where
1569 swaggerAesonOptions _ = mkSwaggerAesonOptions "components"
1582 swaggerAesonOptions _ = mkSwaggerAesonOptions "components"
1570instance HasSwaggerAesonOptions Header where
1583instance HasSwaggerAesonOptions Header where
1571− swaggerAesonOptions _ = mkSwaggerAesonOptions "header"
1584+ swaggerAesonOptions _ = mkSwaggerAesonOptions "header" & saoSubObject ?~ "paramSchema"
1572instance AesonDefaultValue p => HasSwaggerAesonOptions (OAuth2Flow p) where
1585instance AesonDefaultValue p => HasSwaggerAesonOptions (OAuth2Flow p) where
1573 swaggerAesonOptions _ = mkSwaggerAesonOptions "oauth2" & saoSubObject ?~ "params"
1586 swaggerAesonOptions _ = mkSwaggerAesonOptions "oauth2" & saoSubObject ?~ "params"
1574instance HasSwaggerAesonOptions OAuth2Flows where
1587instance HasSwaggerAesonOptions OAuth2Flows where
@@ -1576,7 +1589,9 @@ instance HasSwaggerAesonOptions OAuth2Flows where
1576instance HasSwaggerAesonOptions Operation where
1589instance HasSwaggerAesonOptions Operation where
1577 swaggerAesonOptions _ = mkSwaggerAesonOptions "operation"
1590 swaggerAesonOptions _ = mkSwaggerAesonOptions "operation"
1578instance HasSwaggerAesonOptions Param where
1591instance HasSwaggerAesonOptions Param where
1579− swaggerAesonOptions _ = mkSwaggerAesonOptions "param"
1592+ swaggerAesonOptions _ = mkSwaggerAesonOptions "param" & saoSubObject ?~ "schema"
1593+instance HasSwaggerAesonOptions ParamOtherSchema where
1594+ swaggerAesonOptions _ = mkSwaggerAesonOptions "paramOtherSchema" & saoSubObject ?~ "paramSchema"
1580instance HasSwaggerAesonOptions PathItem where
1595instance HasSwaggerAesonOptions PathItem where
1581 swaggerAesonOptions _ = mkSwaggerAesonOptions "pathItem"
1596 swaggerAesonOptions _ = mkSwaggerAesonOptions "pathItem"
1582instance HasSwaggerAesonOptions Response where
1597instance HasSwaggerAesonOptions Response where
@@ -1591,29 +1606,32 @@ instance HasSwaggerAesonOptions SecurityScheme where
1591 swaggerAesonOptions _ = mkSwaggerAesonOptions "securityScheme" & saoSubObject ?~ "type"
1606 swaggerAesonOptions _ = mkSwaggerAesonOptions "securityScheme" & saoSubObject ?~ "type"
1592instance HasSwaggerAesonOptions Schema where
1607instance HasSwaggerAesonOptions Schema where
1593 swaggerAesonOptions _ = mkSwaggerAesonOptions "schema" & saoSubObject ?~ "paramSchema"
1608 swaggerAesonOptions _ = mkSwaggerAesonOptions "schema" & saoSubObject ?~ "paramSchema"
1594−instance HasSwaggerAesonOptions OpenApi where
1609+instance HasSwaggerAesonOptions Swagger where
1595− swaggerAesonOptions _ = mkSwaggerAesonOptions "swagger" & saoAdditionalPairs .~ [("openapi", "3.0.0")]
1610+ swaggerAesonOptions _ = mkSwaggerAesonOptions "swagger" & saoAdditionalPairs .~ [("openapi", "3.0.3")]
1596instance HasSwaggerAesonOptions Example where
1611instance HasSwaggerAesonOptions Example where
1597 swaggerAesonOptions _ = mkSwaggerAesonOptions "example"
1612 swaggerAesonOptions _ = mkSwaggerAesonOptions "example"
1598instance HasSwaggerAesonOptions Encoding where
1613instance HasSwaggerAesonOptions Encoding where
1599 swaggerAesonOptions _ = mkSwaggerAesonOptions "encoding"
1614 swaggerAesonOptions _ = mkSwaggerAesonOptions "encoding"
1601−instance HasSwaggerAesonOptions Link where
1616+instance HasSwaggerAesonOptions (ParamSchema ('SwaggerKindNormal t)) where
1617+ swaggerAesonOptions _ = mkSwaggerAesonOptions "paramSchema" & saoSubObject ?~ "items"
1618+instance HasSwaggerAesonOptions (ParamSchema 'SwaggerKindParamOtherSchema) where
1602− swaggerAesonOptions _ = mkSwaggerAesonOptions "link"
1619+ swaggerAesonOptions _ = mkSwaggerAesonOptions "paramSchema" & saoSubObject ?~ "items"
1620+-- NOTE: Schema doesn't have 'items' sub object!
1621+instance HasSwaggerAesonOptions (ParamSchema 'SwaggerKindSchema) where
1622+ swaggerAesonOptions _ = mkSwaggerAesonOptions "paramSchema"
1604−instance AesonDefaultValue Server
1605instance AesonDefaultValue Components
1624instance AesonDefaultValue Components
1625+instance AesonDefaultValue (ParamSchema s)
1606instance AesonDefaultValue OAuth2ImplicitFlow
1626instance AesonDefaultValue OAuth2ImplicitFlow
1607instance AesonDefaultValue OAuth2PasswordFlow
1627instance AesonDefaultValue OAuth2PasswordFlow
1608instance AesonDefaultValue OAuth2ClientCredentialsFlow
1628instance AesonDefaultValue OAuth2ClientCredentialsFlow
1609instance AesonDefaultValue OAuth2AuthorizationCodeFlow
1629instance AesonDefaultValue OAuth2AuthorizationCodeFlow
1610instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
1630instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
1611instance AesonDefaultValue Responses
1631instance AesonDefaultValue Responses
1632+instance AesonDefaultValue ParamAnySchema
1612instance AesonDefaultValue SecuritySchemeType
1633instance AesonDefaultValue SecuritySchemeType
1613−instance AesonDefaultValue OpenApiType
1634+instance AesonDefaultValue (SwaggerType a)
1614instance AesonDefaultValue MimeList where defaultValue = Just mempty
1635instance AesonDefaultValue MimeList where defaultValue = Just mempty
1615instance AesonDefaultValue Info
1636instance AesonDefaultValue Info
1616instance AesonDefaultValue ParamLocation
1637instance AesonDefaultValue ParamLocation
1617−instance AesonDefaultValue Link
1618−instance AesonDefaultValue SecurityDefinitions where
1619− defaultValue = Just mempty