git.iko.soy/typeable/openapi3
on master help sign in
change SwaggerItems to OpenApiItems
commit98e9537bd3caaf0f583af3859ad08d710e1b8b08 authorPaweł Nosal <pawel.nosal@ocado.com> dateTue 4 Aug 2020, 09:36 (6 years ago) parent1d2e9d2
9 files changed+65−65
examples/hackage.hs+6−6 src/Data/OpenApi.hs+2−2 src/Data/OpenApi/Internal.hs+17−17 src/Data/OpenApi/Internal/ParamSchema.hs+1−1 src/Data/OpenApi/Internal/Schema.hs+10−10 src/Data/OpenApi/Internal/Schema/Validation.hs+2−2 src/Data/OpenApi/Lens.hs+14−14 src/Data/OpenApi/Optics.hs+11−11 src/Data/OpenApi/Schema/Generator.hs+2−2
examples/hackage.hs+6−6
@@ -47,13 +47,13 @@ data UserDetailed = UserDetailed
4747newtype Package = Package { packageName :: Text }
4848 deriving (Generic, ToSchema)
4949
50−hackageSwagger :: OpenApi
51−hackageSwagger = spec & components.schemas .~ defs
50+hackageOpenApi :: OpenApi
51+hackageOpenApi = spec & components.schemas .~ defs
5252 where
53− (defs, spec) = runDeclare declareHackageSwagger mempty
53+ (defs, spec) = runDeclare declareHackageOpenApi mempty
5454
55−declareHackageSwagger :: Declare (Definitions Schema) OpenApi
56−declareHackageSwagger = do
55+declareHackageOpenApi :: Declare (Definitions Schema) OpenApi
56+declareHackageOpenApi = do
5757 -- param schemas
5858 let usernameParamSchema = toParamSchema (Proxy :: Proxy Username)
5959
@@ -78,5 +78,5 @@ declareHackageSwagger = do
7878 ]
7979
8080main :: IO ()
81−main = putStrLn . read . show . encode $ hackageSwagger
81+main = putStrLn . read . show . encode $ hackageOpenApi
8282
src/Data/OpenApi.hs+2−2
@@ -75,7 +75,7 @@ module Data.OpenApi (
7575 -- ** Schemas
7676 Schema(..),
7777 NamedSchema(..),
78− SwaggerItems(..),
78+ OpenApiItems(..),
7979 Xml(..),
8080 Pattern,
8181 AdditionalProperties(..),
@@ -244,7 +244,7 @@ import Data.OpenApi.Internal
244244-- @'ParamSchema'@ and @'Schema'@ are the two core types for data model specification.
245245--
246246-- @'ParamSchema' t@ specifies all the common properties, available for every data schema.
247−-- The @t@ parameter imposes some restrictions on @type@ and @items@ properties (see @'OpenApiType'@ and @'SwaggerItems'@).
247+-- The @t@ parameter imposes some restrictions on @type@ and @items@ properties (see @'OpenApiType'@ and @'OpenApiItems'@).
248248--
249249-- @'Schema'@ is used for request and response bodies and allows specifying objects
250250-- with properties in addition to what @'ParamSchema'@ provides.
src/Data/OpenApi/Internal.hs+17−17
@@ -576,12 +576,12 @@ data Link = Link
576576-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
577577-- it will incorporate Json Schema mostly verbatim.
578578--
579−-- @'SwaggerItemsObject'@ should be used to specify homogenous array @'Schema'@s.
579+-- @'OpenApiItemsObject'@ should be used to specify homogenous array @'Schema'@s.
580580--
581−-- @'SwaggerItemsArray'@ should be used to specify tuple @'Schema'@s.
582−data SwaggerItems where
583− SwaggerItemsObject :: Referenced Schema -> SwaggerItems
584− SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems
581+-- @'OpenApiItemsArray'@ should be used to specify tuple @'Schema'@s.
582+data OpenApiItems where
583+ OpenApiItemsObject :: Referenced Schema -> OpenApiItems
584+ OpenApiItemsArray :: [Referenced Schema] -> OpenApiItems
585585 deriving (Eq, Show, Typeable, Data)
586586
587587data OpenApiType where
@@ -645,7 +645,7 @@ data Schema = Schema
645645
646646 , _schemaType :: Maybe OpenApiType
647647 , _schemaFormat :: Maybe Format
648− , _schemaItems :: Maybe SwaggerItems
648+ , _schemaItems :: Maybe OpenApiItems
649649 , _schemaMaximum :: Maybe Scientific
650650 , _schemaExclusiveMaximum :: Maybe Bool
651651 , _schemaMinimum :: Maybe Scientific
@@ -680,7 +680,7 @@ data NamedSchema = NamedSchema
680680
681681data Xml = Xml
682682 { -- | Replaces the name of the element/attribute used for the described schema property.
683− -- When defined within the @'SwaggerItems'@ (items), it will affect the name of the individual XML elements within the list.
683+ -- When defined within the @'OpenApiItems'@ (items), it will affect the name of the individual XML elements within the list.
684684 -- When defined alongside type being array (outside the items),
685685 -- it will affect the wrapping element and only if wrapped is true.
686686 -- If wrapped is false, it will be ignored.
@@ -1269,17 +1269,17 @@ instance ToJSON Header where
12691269-- | As for nullary schema for 0-arity type constructors, see
12701270-- <https://github.com/GetShopTV/swagger2/issues/167>.
12711271--
1272−-- >>> encode (SwaggerItemsArray [])
1272+-- >>> encode (OpenApiItemsArray [])
12731273-- "{\"example\":[],\"items\":{},\"maxItems\":0}"
12741274--
1275−instance ToJSON SwaggerItems where
1276− toJSON (SwaggerItemsObject x) = object [ "items" .= x ]
1277− toJSON (SwaggerItemsArray []) = object
1275+instance ToJSON OpenApiItems where
1276+ toJSON (OpenApiItemsObject x) = object [ "items" .= x ]
1277+ toJSON (OpenApiItemsArray []) = object
12781278 [ "items" .= object []
12791279 , "maxItems" .= (0 :: Int)
12801280 , "example" .= Array mempty
12811281 ]
1282− toJSON (SwaggerItemsArray x) = object [ "items" .= x ]
1282+ toJSON (OpenApiItemsArray x) = object [ "items" .= x ]
12831283
12841284instance ToJSON Components where
12851285 toJSON = sopSwaggerGenericToJSON
@@ -1399,7 +1399,7 @@ instance FromJSON Schema where
13991399 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
14001400 where nullaryCleanup :: Schema -> Schema
14011401 nullaryCleanup s =
1402− if _schemaItems s == Just (SwaggerItemsArray [])
1402+ if _schemaItems s == Just (OpenApiItemsArray [])
14031403 then s { _schemaExample = Nothing
14041404 , _schemaMaxItems = Nothing
14051405 }
@@ -1408,11 +1408,11 @@ instance FromJSON Schema where
14081408instance FromJSON Header where
14091409 parseJSON = sopSwaggerGenericParseJSON
14101410
1411−instance FromJSON SwaggerItems where
1411+instance FromJSON OpenApiItems where
14121412 parseJSON js@(Object obj)
1413− | null obj = pure $ SwaggerItemsArray [] -- Nullary schema.
1414− | otherwise = SwaggerItemsObject <$> parseJSON js
1415− parseJSON js@(Array _) = SwaggerItemsArray <$> parseJSON js
1413+ | null obj = pure $ OpenApiItemsArray [] -- Nullary schema.
1414+ | otherwise = OpenApiItemsObject <$> parseJSON js
1415+ parseJSON js@(Array _) = OpenApiItemsArray <$> parseJSON js
14161416 parseJSON _ = empty
14171417
14181418instance FromJSON Components where
src/Data/OpenApi/Internal/ParamSchema.hs+1−1
@@ -260,7 +260,7 @@ instance ToParamSchema a => ToParamSchema (Identity a) where toParamSchema _ = t
260260instance ToParamSchema a => ToParamSchema [a] where
261261 toParamSchema _ = mempty
262262 & type_ ?~ OpenApiArray
263− & items ?~ SwaggerItemsObject (Inline $ toParamSchema (Proxy :: Proxy a))
263+ & items ?~ OpenApiItemsObject (Inline $ toParamSchema (Proxy :: Proxy a))
264264
265265instance ToParamSchema a => ToParamSchema (V.Vector a) where toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
266266instance ToParamSchema a => ToParamSchema (VP.Vector a) where toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
src/Data/OpenApi/Internal/Schema.hs+10−10
@@ -319,8 +319,8 @@ sketchSchema = sketch . toJSON
319319 go (Array xs) = mempty
320320 & type_ ?~ OpenApiArray
321321 & items ?~ case ischema of
322− Just s -> SwaggerItemsObject (Inline s)
323− _ -> SwaggerItemsArray (map Inline ys)
322+ Just s -> OpenApiItemsObject (Inline s)
323+ _ -> OpenApiItemsArray (map Inline ys)
324324 where
325325 ys = map go (V.toList xs)
326326 allSame = and ((zipWith (==)) ys (tail ys))
@@ -372,7 +372,7 @@ sketchStrictSchema = go . toJSON
372372 & type_ ?~ OpenApiArray
373373 & maxItems ?~ fromIntegral sz
374374 & minItems ?~ fromIntegral sz
375− & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
375+ & items ?~ OpenApiItemsArray (map (Inline . go) (V.toList xs))
376376 & uniqueItems ?~ allUnique
377377 & enum_ ?~ [js]
378378 where
@@ -396,7 +396,7 @@ instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
396396 ref <- declareSchemaRef (Proxy :: Proxy a)
397397 return $ unnamed $ mempty
398398 & type_ ?~ OpenApiArray
399− & items ?~ SwaggerItemsObject ref
399+ & items ?~ OpenApiItemsObject ref
400400
401401instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
402402instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
@@ -660,7 +660,7 @@ paramSchemaToSchema = toParamSchema
660660nullarySchema :: Schema
661661nullarySchema = mempty
662662 & type_ ?~ OpenApiArray
663− & items ?~ SwaggerItemsArray []
663+ & items ?~ OpenApiItemsArray []
664664
665665gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
666666gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
@@ -690,7 +690,7 @@ instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s
690690 | unwrapUnaryRecords opts = fieldSchema
691691 | otherwise =
692692 case schema ^. items of
693− Just (SwaggerItemsArray [_]) -> fieldSchema
693+ Just (OpenApiItemsArray [_]) -> fieldSchema
694694 _ -> do
695695 declare defs
696696 return (unnamed schema)
@@ -718,10 +718,10 @@ gdeclareSchemaRef opts proxy = do
718718 return $ Ref (Reference name)
719719 _ -> Inline <$> gdeclareSchema opts proxy
720720
721−appendItem :: Referenced Schema -> Maybe SwaggerItems -> Maybe SwaggerItems
722−appendItem x Nothing = Just (SwaggerItemsArray [x])
723−appendItem x (Just (SwaggerItemsArray xs)) = Just (SwaggerItemsArray (xs ++ [x]))
724−appendItem _ _ = error "GToSchema.appendItem: cannot append to SwaggerItemsObject"
721+appendItem :: Referenced Schema -> Maybe OpenApiItems -> Maybe OpenApiItems
722+appendItem x Nothing = Just (OpenApiItemsArray [x])
723+appendItem x (Just (OpenApiItemsArray xs)) = Just (OpenApiItemsArray (xs ++ [x]))
724+appendItem _ _ = error "GToSchema.appendItem: cannot append to OpenApiItemsObject"
725725
726726withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
727727 SchemaOptions -> proxy s f -> Bool -> Schema -> Declare (Definitions Schema) Schema
src/Data/OpenApi/Internal/Schema/Validation.hs+2−2
@@ -353,8 +353,8 @@ validateArray xs = do
353353 invalid ("array is too short (size should be >=" ++ show n ++ ")")
354354
355355 check items $ \case
356− SwaggerItemsObject itemSchema -> traverse_ (validateWithSchemaRef itemSchema) xs
357− SwaggerItemsArray itemSchemas -> do
356+ OpenApiItemsObject itemSchema -> traverse_ (validateWithSchemaRef itemSchema) xs
357+ OpenApiItemsArray itemSchemas -> do
358358 when (len /= length itemSchemas) $
359359 invalid ("array size is invalid (should be exactly " ++ show (length itemSchemas) ++ ")")
360360 sequenceA_ (zipWith validateWithSchemaRef itemSchemas (Vector.toList xs))
src/Data/OpenApi/Lens.hs+14−14
@@ -64,24 +64,24 @@ makePrisms ''SecuritySchemeType
6464-- ** 'Referenced' prisms
6565makePrisms ''Referenced
6666
67−-- ** 'SwaggerItems' prisms
67+-- ** 'OpenApiItems' prisms
6868
69−_SwaggerItemsArray :: Review SwaggerItems [Referenced Schema]
70−_SwaggerItemsArray
71− = unto (\x -> SwaggerItemsArray x)
69+_OpenApiItemsArray :: Review OpenApiItems [Referenced Schema]
70+_OpenApiItemsArray
71+ = unto (\x -> OpenApiItemsArray x)
7272{- \x -> case x of
73− SwaggerItemsPrimitive c p -> Left (SwaggerItemsPrimitive c p)
74− SwaggerItemsObject o -> Left (SwaggerItemsObject o)
75− SwaggerItemsArray a -> Right a
73+ OpenApiItemsPrimitive c p -> Left (OpenApiItemsPrimitive c p)
74+ OpenApiItemsObject o -> Left (OpenApiItemsObject o)
75+ OpenApiItemsArray a -> Right a
7676-}
7777
78−_SwaggerItemsObject :: Review SwaggerItems (Referenced Schema)
79−_SwaggerItemsObject
80− = unto (\x -> SwaggerItemsObject x)
78+_OpenApiItemsObject :: Review OpenApiItems (Referenced Schema)
79+_OpenApiItemsObject
80+ = unto (\x -> OpenApiItemsObject x)
8181{- \x -> case x of
82− SwaggerItemsPrimitive c p -> Left (SwaggerItemsPrimitive c p)
83− SwaggerItemsObject o -> Right o
84− SwaggerItemsArray a -> Left (SwaggerItemsArray a)
82+ OpenApiItemsPrimitive c p -> Left (OpenApiItemsPrimitive c p)
83+ OpenApiItemsObject o -> Right o
84+ OpenApiItemsArray a -> Left (OpenApiItemsArray a)
8585-}
8686
8787-- =============================================================
@@ -112,7 +112,7 @@ instance
112112instance
113113 {-# OVERLAPPABLE #-}
114114 HasSchema s Schema
115− => HasItems s (Maybe SwaggerItems) where
115+ => HasItems s (Maybe OpenApiItems) where
116116 items = schema.items
117117
118118instance
src/Data/OpenApi/Optics.hs+11−11
@@ -103,30 +103,30 @@ makeFieldLabels ''Link
103103makePrismLabels ''SecuritySchemeType
104104makePrismLabels ''Referenced
105105
106−-- SwaggerItems prisms
106+-- OpenApiItems prisms
107107
108108instance
109109 ( a ~ [Referenced Schema]
110110 , b ~ [Referenced Schema]
111− ) => LabelOptic "_SwaggerItemsArray"
111+ ) => LabelOptic "_OpenApiItemsArray"
112112 A_Review
113− SwaggerItems
114− SwaggerItems
113+ OpenApiItems
114+ OpenApiItems
115115 a
116116 b where
117− labelOptic = unto (\x -> SwaggerItemsArray x)
117+ labelOptic = unto (\x -> OpenApiItemsArray x)
118118 {-# INLINE labelOptic #-}
119119
120120instance
121121 ( a ~ Referenced Schema
122122 , b ~ Referenced Schema
123− ) => LabelOptic "_SwaggerItemsObject"
123+ ) => LabelOptic "_OpenApiItemsObject"
124124 A_Review
125− SwaggerItems
126− SwaggerItems
125+ OpenApiItems
126+ OpenApiItems
127127 a
128128 b where
129− labelOptic = unto (\x -> SwaggerItemsObject x)
129+ labelOptic = unto (\x -> OpenApiItemsObject x)
130130 {-# INLINE labelOptic #-}
131131
132132-- =============================================================
@@ -180,8 +180,8 @@ instance
180180-- #items
181181
182182instance
183− ( a ~ Maybe SwaggerItems
184− , b ~ Maybe SwaggerItems
183+ ( a ~ Maybe OpenApiItems
184+ , b ~ Maybe OpenApiItems
185185 ) => LabelOptic "items" A_Lens NamedSchema NamedSchema a b where
186186 labelOptic = #schema % #items
187187 {-# INLINE labelOptic #-}
src/Data/OpenApi/Schema/Generator.hs+2−2
@@ -57,7 +57,7 @@ schemaGen defns schema =
5757 | Just 0 <- schema ^. maxLength -> pure $ Array V.empty
5858 | Just items <- schema ^. items ->
5959 case items of
60− SwaggerItemsObject ref -> do
60+ OpenApiItemsObject ref -> do
6161 size <- getSize
6262 let itemSchema = dereference defns ref
6363 minLength' = fromMaybe 0 $ fromInteger <$> schema ^. minItems
@@ -65,7 +65,7 @@ schemaGen defns schema =
6565 arrayLength <- choose (minLength', max minLength' maxLength')
6666 generatedArray <- vectorOf arrayLength $ schemaGen defns itemSchema
6767 return . Array $ V.fromList generatedArray
68− SwaggerItemsArray refs ->
68+ OpenApiItemsArray refs ->
6969 let itemGens = schemaGen defns . dereference defns <$> refs
7070 in fmap (Array . V.fromList) $ sequence itemGens
7171 Just OpenApiString -> do