2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FunctionalDependencies #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE RankNTypes #-}
8{-# LANGUAGE TemplateHaskell #-}
9{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE UndecidableInstances #-}
11{-# OPTIONS_GHC -fno-warn-orphans #-}
12#include "overlapping-compat.h"
13module Data.Swagger.Lens where
16import Data.Aeson (Value)
17import Data.Scientific (Scientific)
18import Data.Swagger.Internal
19import Data.Swagger.Internal.Utils
20import Data.Text (Text)
33makeLensesWith swaggerFieldRules ''ParamOtherSchema
36makeFields ''NamedSchema
37makeLensesWith swaggerFieldRules ''ParamSchema
39makeLensesWith swaggerFieldRules ''Responses
41makeLensesWith swaggerFieldRules ''SecurityScheme
42makeFields ''ApiKeyParams
43makeFields ''OAuth2Params
44makeFields ''ExternalDocs
47-- ** 'ParamAnySchema' prisms
48makePrisms ''ParamAnySchema
49-- ** 'SecuritySchemeType' prisms
50makePrisms ''SecuritySchemeType
52-- ** 'SwaggerItems' prisms
54_SwaggerItemsArray :: forall t. (t ~ Schema) => Review (SwaggerItems t) [Referenced Schema]
56 = prism (\x -> SwaggerItemsArray x) $ \x -> case x of
57 SwaggerItemsPrimitive c p -> Left (SwaggerItemsPrimitive c p)
58 SwaggerItemsObject o -> Left (SwaggerItemsObject o)
59 SwaggerItemsArray a -> Right a
61_SwaggerItemsObject :: forall t. (t ~ Schema) => Review (SwaggerItems t) (Referenced Schema)
63 = prism (\x -> SwaggerItemsObject x) $ \x -> case x of
64 SwaggerItemsPrimitive c p -> Left (SwaggerItemsPrimitive c p)
65 SwaggerItemsObject o -> Right o
66 SwaggerItemsArray a -> Left (SwaggerItemsArray a)
68_SwaggerItemsPrimitive :: forall t p f. (Profunctor p, Bifunctor p, Functor f) => Optic' p f (SwaggerItems t) (Maybe (CollectionFormat t), ParamSchema t)
69_SwaggerItemsPrimitive = unto (\(c, p) -> SwaggerItemsPrimitive c p)
71-- =============================================================
72-- More helpful instances for easier access to schema properties
74type instance Index Responses = HttpStatusCode
75type instance Index Operation = HttpStatusCode
77type instance IxValue Responses = Referenced Response
78type instance IxValue Operation = Referenced Response
80instance Ixed Responses where ix n = responses . ix n
81instance At Responses where at n = responses . at n
83instance Ixed Operation where ix n = responses . ix n
84instance At Operation where at n = responses . at n
87instance HasType Header (SwaggerType Header) where type_ = paramSchema.type_
88instance HasType Schema (SwaggerType Schema) where type_ = paramSchema.type_
89instance HasType NamedSchema (SwaggerType Schema) where type_ = schema.paramSchema.type_
90instance HasType ParamOtherSchema (SwaggerType ParamOtherSchema) where type_ = paramSchema.type_
92-- HasDefault instances
93instance HasDefault Header (Maybe Value) where default_ = paramSchema.default_
94instance HasDefault Schema (Maybe Value) where default_ = paramSchema.default_
95instance HasDefault ParamOtherSchema (Maybe Value) where default_ = paramSchema.default_
97-- OVERLAPPABLE instances
100#if __GLASGOW_HASKELL__ >= 710
103 HasParamSchema s (ParamSchema t)
104 => HasFormat s (Maybe Format) where
105 format = paramSchema.format
108#if __GLASGOW_HASKELL__ >= 710
111 HasParamSchema s (ParamSchema t)
112 => HasItems s (Maybe (SwaggerItems t)) where
113 items = paramSchema.items
116#if __GLASGOW_HASKELL__ >= 710
119 HasParamSchema s (ParamSchema t)
120 => HasMaximum s (Maybe Scientific) where
121 maximum_ = paramSchema.maximum_
123instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
124 => HasExclusiveMaximum s (Maybe Bool) where
125 exclusiveMaximum = paramSchema.exclusiveMaximum
127instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
128 => HasMinimum s (Maybe Scientific) where
129 minimum_ = paramSchema.minimum_
131instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
132 => HasExclusiveMinimum s (Maybe Bool) where
133 exclusiveMinimum = paramSchema.exclusiveMinimum
135instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
136 => HasMaxLength s (Maybe Integer) where
137 maxLength = paramSchema.maxLength
139instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
140 => HasMinLength s (Maybe Integer) where
141 minLength = paramSchema.minLength
143instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
144 => HasPattern s (Maybe Text) where
145 pattern = paramSchema.pattern
147instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
148 => HasMaxItems s (Maybe Integer) where
149 maxItems = paramSchema.maxItems
151instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
152 => HasMinItems s (Maybe Integer) where
153 minItems = paramSchema.minItems
155instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
156 => HasUniqueItems s (Maybe Bool) where
157 uniqueItems = paramSchema.uniqueItems
159instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
160 => HasEnum s (Maybe [Value]) where
161 enum_ = paramSchema.enum_
163instance OVERLAPPABLE_ HasParamSchema s (ParamSchema t)
164 => HasMultipleOf s (Maybe Scientific) where
165 multipleOf = paramSchema.multipleOf
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list