git.iko.soy/typeable/openapi3
on master help sign in
change SwaggerItems to OpenApiItems
98e9537Paweł Nosal
examples/hackage.hs+6−6
@@ -47,13 +47,13 @@ data UserDetailed = UserDetailed
47newtype Package = Package { packageName :: Text }
47newtype Package = Package { packageName :: Text }
48 deriving (Generic, ToSchema)
48 deriving (Generic, ToSchema)
49
49
50−hackageSwagger :: OpenApi
50+hackageOpenApi :: OpenApi
51−hackageSwagger = spec & components.schemas .~ defs
51+hackageOpenApi = spec & components.schemas .~ defs
52 where
52 where
53− (defs, spec) = runDeclare declareHackageSwagger mempty
53+ (defs, spec) = runDeclare declareHackageOpenApi mempty
54
54
55−declareHackageSwagger :: Declare (Definitions Schema) OpenApi
55+declareHackageOpenApi :: Declare (Definitions Schema) OpenApi
56−declareHackageSwagger = do
56+declareHackageOpenApi = do
57 -- param schemas
57 -- param schemas
58 let usernameParamSchema = toParamSchema (Proxy :: Proxy Username)
58 let usernameParamSchema = toParamSchema (Proxy :: Proxy Username)
59
59
@@ -78,5 +78,5 @@ declareHackageSwagger = do
78 ]
78 ]
79
79
80main :: IO ()
80main :: IO ()
81−main = putStrLn . read . show . encode $ hackageSwagger
81+main = putStrLn . read . show . encode $ hackageOpenApi
82
82
src/Data/OpenApi.hs+2−2
@@ -75,7 +75,7 @@ module Data.OpenApi (
75 -- ** Schemas
75 -- ** Schemas
76 Schema(..),
76 Schema(..),
77 NamedSchema(..),
77 NamedSchema(..),
78− SwaggerItems(..),
78+ OpenApiItems(..),
79 Xml(..),
79 Xml(..),
80 Pattern,
80 Pattern,
81 AdditionalProperties(..),
81 AdditionalProperties(..),
@@ -244,7 +244,7 @@ import Data.OpenApi.Internal
244-- @'ParamSchema'@ and @'Schema'@ are the two core types for data model specification.
244-- @'ParamSchema'@ and @'Schema'@ are the two core types for data model specification.
245--
245--
246-- @'ParamSchema' t@ specifies all the common properties, available for every data schema.
246-- @'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'@).
248--
248--
249-- @'Schema'@ is used for request and response bodies and allows specifying objects
249-- @'Schema'@ is used for request and response bodies and allows specifying objects
250-- with properties in addition to what @'ParamSchema'@ provides.
250-- with properties in addition to what @'ParamSchema'@ provides.
src/Data/OpenApi/Internal.hs+17−17
@@ -576,12 +576,12 @@ data Link = Link
576-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
576-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
577-- it will incorporate Json Schema mostly verbatim.
577-- it will incorporate Json Schema mostly verbatim.
578--
578--
579−-- @'SwaggerItemsObject'@ should be used to specify homogenous array @'Schema'@s.
579+-- @'OpenApiItemsObject'@ should be used to specify homogenous array @'Schema'@s.
580--
580--
581−-- @'SwaggerItemsArray'@ should be used to specify tuple @'Schema'@s.
581+-- @'OpenApiItemsArray'@ should be used to specify tuple @'Schema'@s.
582−data SwaggerItems where
582+data OpenApiItems where
583− SwaggerItemsObject :: Referenced Schema -> SwaggerItems
583+ OpenApiItemsObject :: Referenced Schema -> OpenApiItems
584− SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems
584+ OpenApiItemsArray :: [Referenced Schema] -> OpenApiItems
585 deriving (Eq, Show, Typeable, Data)
585 deriving (Eq, Show, Typeable, Data)
586
586
587data OpenApiType where
587data OpenApiType where
@@ -645,7 +645,7 @@ data Schema = Schema
645
645
646 , _schemaType :: Maybe OpenApiType
646 , _schemaType :: Maybe OpenApiType
647 , _schemaFormat :: Maybe Format
647 , _schemaFormat :: Maybe Format
648− , _schemaItems :: Maybe SwaggerItems
648+ , _schemaItems :: Maybe OpenApiItems
649 , _schemaMaximum :: Maybe Scientific
649 , _schemaMaximum :: Maybe Scientific
650 , _schemaExclusiveMaximum :: Maybe Bool
650 , _schemaExclusiveMaximum :: Maybe Bool
651 , _schemaMinimum :: Maybe Scientific
651 , _schemaMinimum :: Maybe Scientific
@@ -680,7 +680,7 @@ data NamedSchema = NamedSchema
680
680
681data Xml = Xml
681data Xml = Xml
682 { -- | Replaces the name of the element/attribute used for the described schema property.
682 { -- | 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.
684 -- When defined alongside type being array (outside the items),
684 -- When defined alongside type being array (outside the items),
685 -- it will affect the wrapping element and only if wrapped is true.
685 -- it will affect the wrapping element and only if wrapped is true.
686 -- If wrapped is false, it will be ignored.
686 -- If wrapped is false, it will be ignored.
@@ -1269,17 +1269,17 @@ instance ToJSON Header where
1269-- | As for nullary schema for 0-arity type constructors, see
1269-- | As for nullary schema for 0-arity type constructors, see
1270-- <https://github.com/GetShopTV/swagger2/issues/167>.
1270-- <https://github.com/GetShopTV/swagger2/issues/167>.
1271--
1271--
1272−-- >>> encode (SwaggerItemsArray [])
1272+-- >>> encode (OpenApiItemsArray [])
1273-- "{\"example\":[],\"items\":{},\"maxItems\":0}"
1273-- "{\"example\":[],\"items\":{},\"maxItems\":0}"
1274--
1274--
1275−instance ToJSON SwaggerItems where
1275+instance ToJSON OpenApiItems where
1276− toJSON (SwaggerItemsObject x) = object [ "items" .= x ]
1276+ toJSON (OpenApiItemsObject x) = object [ "items" .= x ]
1277− toJSON (SwaggerItemsArray []) = object
1277+ toJSON (OpenApiItemsArray []) = object
1278 [ "items" .= object []
1278 [ "items" .= object []
1279 , "maxItems" .= (0 :: Int)
1279 , "maxItems" .= (0 :: Int)
1280 , "example" .= Array mempty
1280 , "example" .= Array mempty
1281 ]
1281 ]
1282− toJSON (SwaggerItemsArray x) = object [ "items" .= x ]
1282+ toJSON (OpenApiItemsArray x) = object [ "items" .= x ]
1283
1283
1284instance ToJSON Components where
1284instance ToJSON Components where
1285 toJSON = sopSwaggerGenericToJSON
1285 toJSON = sopSwaggerGenericToJSON
@@ -1399,7 +1399,7 @@ instance FromJSON Schema where
1399 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
1399 parseJSON = fmap nullaryCleanup . sopSwaggerGenericParseJSON
1400 where nullaryCleanup :: Schema -> Schema
1400 where nullaryCleanup :: Schema -> Schema
1401 nullaryCleanup s =
1401 nullaryCleanup s =
1402− if _schemaItems s == Just (SwaggerItemsArray [])
1402+ if _schemaItems s == Just (OpenApiItemsArray [])
1403 then s { _schemaExample = Nothing
1403 then s { _schemaExample = Nothing
1404 , _schemaMaxItems = Nothing
1404 , _schemaMaxItems = Nothing
1405 }
1405 }
@@ -1408,11 +1408,11 @@ instance FromJSON Schema where
1408instance FromJSON Header where
1408instance FromJSON Header where
1409 parseJSON = sopSwaggerGenericParseJSON
1409 parseJSON = sopSwaggerGenericParseJSON
1410
1410
1411−instance FromJSON SwaggerItems where
1411+instance FromJSON OpenApiItems where
1412 parseJSON js@(Object obj)
1412 parseJSON js@(Object obj)
1413− | null obj = pure $ SwaggerItemsArray [] -- Nullary schema.
1413+ | null obj = pure $ OpenApiItemsArray [] -- Nullary schema.
1414− | otherwise = SwaggerItemsObject <$> parseJSON js
1414+ | otherwise = OpenApiItemsObject <$> parseJSON js
1415− parseJSON js@(Array _) = SwaggerItemsArray <$> parseJSON js
1415+ parseJSON js@(Array _) = OpenApiItemsArray <$> parseJSON js
1416 parseJSON _ = empty
1416 parseJSON _ = empty
1417
1417
1418instance FromJSON Components where
1418instance FromJSON Components where
src/Data/OpenApi/Internal/ParamSchema.hs+1−1
@@ -260,7 +260,7 @@ instance ToParamSchema a => ToParamSchema (Identity a) where toParamSchema _ = t
260instance ToParamSchema a => ToParamSchema [a] where
260instance ToParamSchema a => ToParamSchema [a] where
261 toParamSchema _ = mempty
261 toParamSchema _ = mempty
262 & type_ ?~ OpenApiArray
262 & type_ ?~ OpenApiArray
263− & items ?~ SwaggerItemsObject (Inline $ toParamSchema (Proxy :: Proxy a))
263+ & items ?~ OpenApiItemsObject (Inline $ toParamSchema (Proxy :: Proxy a))
264
264
265instance ToParamSchema a => ToParamSchema (V.Vector a) where toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
265instance ToParamSchema a => ToParamSchema (V.Vector a) where toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
266instance ToParamSchema a => ToParamSchema (VP.Vector a) where toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
266instance 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
319 go (Array xs) = mempty
319 go (Array xs) = mempty
320 & type_ ?~ OpenApiArray
320 & type_ ?~ OpenApiArray
321 & items ?~ case ischema of
321 & items ?~ case ischema of
322− Just s -> SwaggerItemsObject (Inline s)
322+ Just s -> OpenApiItemsObject (Inline s)
323− _ -> SwaggerItemsArray (map Inline ys)
323+ _ -> OpenApiItemsArray (map Inline ys)
324 where
324 where
325 ys = map go (V.toList xs)
325 ys = map go (V.toList xs)
326 allSame = and ((zipWith (==)) ys (tail ys))
326 allSame = and ((zipWith (==)) ys (tail ys))
@@ -372,7 +372,7 @@ sketchStrictSchema = go . toJSON
372 & type_ ?~ OpenApiArray
372 & type_ ?~ OpenApiArray
373 & maxItems ?~ fromIntegral sz
373 & maxItems ?~ fromIntegral sz
374 & minItems ?~ fromIntegral sz
374 & minItems ?~ fromIntegral sz
375− & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
375+ & items ?~ OpenApiItemsArray (map (Inline . go) (V.toList xs))
376 & uniqueItems ?~ allUnique
376 & uniqueItems ?~ allUnique
377 & enum_ ?~ [js]
377 & enum_ ?~ [js]
378 where
378 where
@@ -396,7 +396,7 @@ instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
396 ref <- declareSchemaRef (Proxy :: Proxy a)
396 ref <- declareSchemaRef (Proxy :: Proxy a)
397 return $ unnamed $ mempty
397 return $ unnamed $ mempty
398 & type_ ?~ OpenApiArray
398 & type_ ?~ OpenApiArray
399− & items ?~ SwaggerItemsObject ref
399+ & items ?~ OpenApiItemsObject ref
400
400
401instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
401instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
402instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
402instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
@@ -660,7 +660,7 @@ paramSchemaToSchema = toParamSchema
660nullarySchema :: Schema
660nullarySchema :: Schema
661nullarySchema = mempty
661nullarySchema = mempty
662 & type_ ?~ OpenApiArray
662 & type_ ?~ OpenApiArray
663− & items ?~ SwaggerItemsArray []
663+ & items ?~ OpenApiItemsArray []
664
664
665gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
665gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
666gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
666gtoNamedSchema 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
690 | unwrapUnaryRecords opts = fieldSchema
690 | unwrapUnaryRecords opts = fieldSchema
691 | otherwise =
691 | otherwise =
692 case schema ^. items of
692 case schema ^. items of
693− Just (SwaggerItemsArray [_]) -> fieldSchema
693+ Just (OpenApiItemsArray [_]) -> fieldSchema
694 _ -> do
694 _ -> do
695 declare defs
695 declare defs
696 return (unnamed schema)
696 return (unnamed schema)
@@ -718,10 +718,10 @@ gdeclareSchemaRef opts proxy = do
718 return $ Ref (Reference name)
718 return $ Ref (Reference name)
719 _ -> Inline <$> gdeclareSchema opts proxy
719 _ -> Inline <$> gdeclareSchema opts proxy
720
720
721−appendItem :: Referenced Schema -> Maybe SwaggerItems -> Maybe SwaggerItems
721+appendItem :: Referenced Schema -> Maybe OpenApiItems -> Maybe OpenApiItems
722−appendItem x Nothing = Just (SwaggerItemsArray [x])
722+appendItem x Nothing = Just (OpenApiItemsArray [x])
723−appendItem x (Just (SwaggerItemsArray xs)) = Just (SwaggerItemsArray (xs ++ [x]))
723+appendItem x (Just (OpenApiItemsArray xs)) = Just (OpenApiItemsArray (xs ++ [x]))
724−appendItem _ _ = error "GToSchema.appendItem: cannot append to SwaggerItemsObject"
724+appendItem _ _ = error "GToSchema.appendItem: cannot append to OpenApiItemsObject"
725
725
726withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
726withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
727 SchemaOptions -> proxy s f -> Bool -> Schema -> Declare (Definitions Schema) Schema
727 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
353 invalid ("array is too short (size should be >=" ++ show n ++ ")")
353 invalid ("array is too short (size should be >=" ++ show n ++ ")")
354
354
355 check items $ \case
355 check items $ \case
356− SwaggerItemsObject itemSchema -> traverse_ (validateWithSchemaRef itemSchema) xs
356+ OpenApiItemsObject itemSchema -> traverse_ (validateWithSchemaRef itemSchema) xs
357− SwaggerItemsArray itemSchemas -> do
357+ OpenApiItemsArray itemSchemas -> do
358 when (len /= length itemSchemas) $
358 when (len /= length itemSchemas) $
359 invalid ("array size is invalid (should be exactly " ++ show (length itemSchemas) ++ ")")
359 invalid ("array size is invalid (should be exactly " ++ show (length itemSchemas) ++ ")")
360 sequenceA_ (zipWith validateWithSchemaRef itemSchemas (Vector.toList xs))
360 sequenceA_ (zipWith validateWithSchemaRef itemSchemas (Vector.toList xs))
src/Data/OpenApi/Lens.hs+14−14
@@ -64,24 +64,24 @@ makePrisms ''SecuritySchemeType
64-- ** 'Referenced' prisms
64-- ** 'Referenced' prisms
65makePrisms ''Referenced
65makePrisms ''Referenced
66
66
67−-- ** 'SwaggerItems' prisms
67+-- ** 'OpenApiItems' prisms
68
68
69−_SwaggerItemsArray :: Review SwaggerItems [Referenced Schema]
69+_OpenApiItemsArray :: Review OpenApiItems [Referenced Schema]
70−_SwaggerItemsArray
70+_OpenApiItemsArray
71− = unto (\x -> SwaggerItemsArray x)
71+ = unto (\x -> OpenApiItemsArray x)
72{- \x -> case x of
72{- \x -> case x of
73− SwaggerItemsPrimitive c p -> Left (SwaggerItemsPrimitive c p)
73+ OpenApiItemsPrimitive c p -> Left (OpenApiItemsPrimitive c p)
74− SwaggerItemsObject o -> Left (SwaggerItemsObject o)
74+ OpenApiItemsObject o -> Left (OpenApiItemsObject o)
75− SwaggerItemsArray a -> Right a
75+ OpenApiItemsArray a -> Right a
76-}
76-}
77
77
78−_SwaggerItemsObject :: Review SwaggerItems (Referenced Schema)
78+_OpenApiItemsObject :: Review OpenApiItems (Referenced Schema)
79−_SwaggerItemsObject
79+_OpenApiItemsObject
80− = unto (\x -> SwaggerItemsObject x)
80+ = unto (\x -> OpenApiItemsObject x)
81{- \x -> case x of
81{- \x -> case x of
82− SwaggerItemsPrimitive c p -> Left (SwaggerItemsPrimitive c p)
82+ OpenApiItemsPrimitive c p -> Left (OpenApiItemsPrimitive c p)
83− SwaggerItemsObject o -> Right o
83+ OpenApiItemsObject o -> Right o
84− SwaggerItemsArray a -> Left (SwaggerItemsArray a)
84+ OpenApiItemsArray a -> Left (OpenApiItemsArray a)
85-}
85-}
86
86
87-- =============================================================
87-- =============================================================
@@ -112,7 +112,7 @@ instance
112instance
112instance
113 {-# OVERLAPPABLE #-}
113 {-# OVERLAPPABLE #-}
114 HasSchema s Schema
114 HasSchema s Schema
115− => HasItems s (Maybe SwaggerItems) where
115+ => HasItems s (Maybe OpenApiItems) where
116 items = schema.items
116 items = schema.items
117
117
118instance
118instance
src/Data/OpenApi/Optics.hs+11−11
@@ -103,30 +103,30 @@ makeFieldLabels ''Link
103makePrismLabels ''SecuritySchemeType
103makePrismLabels ''SecuritySchemeType
104makePrismLabels ''Referenced
104makePrismLabels ''Referenced
105
105
106−-- SwaggerItems prisms
106+-- OpenApiItems prisms
107
107
108instance
108instance
109 ( a ~ [Referenced Schema]
109 ( a ~ [Referenced Schema]
110 , b ~ [Referenced Schema]
110 , b ~ [Referenced Schema]
111− ) => LabelOptic "_SwaggerItemsArray"
111+ ) => LabelOptic "_OpenApiItemsArray"
112 A_Review
112 A_Review
113− SwaggerItems
113+ OpenApiItems
114− SwaggerItems
114+ OpenApiItems
115 a
115 a
116 b where
116 b where
117− labelOptic = unto (\x -> SwaggerItemsArray x)
117+ labelOptic = unto (\x -> OpenApiItemsArray x)
118 {-# INLINE labelOptic #-}
118 {-# INLINE labelOptic #-}
119
119
120instance
120instance
121 ( a ~ Referenced Schema
121 ( a ~ Referenced Schema
122 , b ~ Referenced Schema
122 , b ~ Referenced Schema
123− ) => LabelOptic "_SwaggerItemsObject"
123+ ) => LabelOptic "_OpenApiItemsObject"
124 A_Review
124 A_Review
125− SwaggerItems
125+ OpenApiItems
126− SwaggerItems
126+ OpenApiItems
127 a
127 a
128 b where
128 b where
129− labelOptic = unto (\x -> SwaggerItemsObject x)
129+ labelOptic = unto (\x -> OpenApiItemsObject x)
130 {-# INLINE labelOptic #-}
130 {-# INLINE labelOptic #-}
131
131
132-- =============================================================
132-- =============================================================
@@ -180,8 +180,8 @@ instance
180-- #items
180-- #items
181
181
182instance
182instance
183− ( a ~ Maybe SwaggerItems
183+ ( a ~ Maybe OpenApiItems
184− , b ~ Maybe SwaggerItems
184+ , b ~ Maybe OpenApiItems
185 ) => LabelOptic "items" A_Lens NamedSchema NamedSchema a b where
185 ) => LabelOptic "items" A_Lens NamedSchema NamedSchema a b where
186 labelOptic = #schema % #items
186 labelOptic = #schema % #items
187 {-# INLINE labelOptic #-}
187 {-# INLINE labelOptic #-}
src/Data/OpenApi/Schema/Generator.hs+2−2
@@ -57,7 +57,7 @@ schemaGen defns schema =
57 | Just 0 <- schema ^. maxLength -> pure $ Array V.empty
57 | Just 0 <- schema ^. maxLength -> pure $ Array V.empty
58 | Just items <- schema ^. items ->
58 | Just items <- schema ^. items ->
59 case items of
59 case items of
60− SwaggerItemsObject ref -> do
60+ OpenApiItemsObject ref -> do
61 size <- getSize
61 size <- getSize
62 let itemSchema = dereference defns ref
62 let itemSchema = dereference defns ref
63 minLength' = fromMaybe 0 $ fromInteger <$> schema ^. minItems
63 minLength' = fromMaybe 0 $ fromInteger <$> schema ^. minItems
@@ -65,7 +65,7 @@ schemaGen defns schema =
65 arrayLength <- choose (minLength', max minLength' maxLength')
65 arrayLength <- choose (minLength', max minLength' maxLength')
66 generatedArray <- vectorOf arrayLength $ schemaGen defns itemSchema
66 generatedArray <- vectorOf arrayLength $ schemaGen defns itemSchema
67 return . Array $ V.fromList generatedArray
67 return . Array $ V.fromList generatedArray
68− SwaggerItemsArray refs ->
68+ OpenApiItemsArray refs ->
69 let itemGens = schemaGen defns . dereference defns <$> refs
69 let itemGens = schemaGen defns . dereference defns <$> refs
70 in fmap (Array . V.fromList) $ sequence itemGens
70 in fmap (Array . V.fromList) $ sequence itemGens
71 Just OpenApiString -> do
71 Just OpenApiString -> do