@@ -1,17 +1,15 @@
2{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
3−{-# LANGUAGE DataKinds #-}
4{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE DefaultSignatures #-}
5{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
6{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
7{-# LANGUAGE KindSignatures #-}
5{-# LANGUAGE KindSignatures #-}
6+{-# LANGUAGE DataKinds #-}
8{-# LANGUAGE OverloadedLists #-}
7{-# LANGUAGE OverloadedLists #-}
9{-# LANGUAGE OverloadedStrings #-}
8{-# LANGUAGE OverloadedStrings #-}
10{-# LANGUAGE PackageImports #-}
9{-# LANGUAGE PackageImports #-}
11{-# LANGUAGE PolyKinds #-}
10{-# LANGUAGE PolyKinds #-}
12{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE ScopedTypeVariables #-}
13{-# LANGUAGE TupleSections #-}
12{-# LANGUAGE TupleSections #-}
14−{-# LANGUAGE TypeApplications #-}
15{-# LANGUAGE TypeFamilies #-}
13{-# LANGUAGE TypeFamilies #-}
16{-# LANGUAGE TypeOperators #-}
14{-# LANGUAGE TypeOperators #-}
17{-# LANGUAGE TypeSynonymInstances #-}
15{-# LANGUAGE TypeSynonymInstances #-}
@@ -19,7 +17,7 @@
19{-# OPTIONS_GHC -Wno-redundant-constraints #-}
17{-# OPTIONS_GHC -Wno-redundant-constraints #-}
20-- For TypeErrors
18-- For TypeErrors
21{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}
19{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}
22−module Data.OpenApi.Internal.Schema where
20+module Data.Swagger.Internal.Schema where
24import Prelude ()
22import Prelude ()
25import Prelude.Compat
23import Prelude.Compat
@@ -42,7 +40,6 @@ import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
42import Data.Int
40import Data.Int
43import Data.IntSet (IntSet)
41import Data.IntSet (IntSet)
44import Data.IntMap (IntMap)
42import Data.IntMap (IntMap)
45−import Data.List (sort)
46import Data.List.NonEmpty.Compat (NonEmpty)
43import Data.List.NonEmpty.Compat (NonEmpty)
47import Data.Map (Map)
44import Data.Map (Map)
48import Data.Maybe (fromMaybe)
45import Data.Maybe (fromMaybe)
@@ -62,16 +59,14 @@ import Numeric.Natural.Compat (Natural)
62import Data.Word
59import Data.Word
63import GHC.Generics
60import GHC.Generics
64import qualified Data.UUID.Types as UUID
61import qualified Data.UUID.Types as UUID
65−import Type.Reflection (Typeable, typeRep)
67−import Data.OpenApi.Aeson.Compat (keyToText, objectKeys, toInsOrdHashMap)
68−import Data.OpenApi.Declare
63+import Data.Swagger.Declare
69−import Data.OpenApi.Internal
64+import Data.Swagger.Internal
70−import Data.OpenApi.Internal.ParamSchema (ToParamSchema (..))
65+import Data.Swagger.Internal.ParamSchema (ToParamSchema(..))
71−import Data.OpenApi.Internal.TypeShape
72−import Data.OpenApi.Lens hiding (name, schema)
66+import Data.Swagger.Lens hiding (name, schema)
73−import qualified Data.OpenApi.Lens as Swagger
67+import qualified Data.Swagger.Lens as Swagger
74−import Data.OpenApi.SchemaOptions
68+import Data.Swagger.SchemaOptions
69+import Data.Swagger.Internal.TypeShape
76import qualified Data.ByteString as BS
71import qualified Data.ByteString as BS
77import qualified Data.ByteString.Lazy.Char8 as BSL
72import qualified Data.ByteString.Lazy.Char8 as BSL
@@ -102,7 +97,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
103-- import Control.Lens
98-- import Control.Lens
104-- import Data.Proxy
99-- import Data.Proxy
105−-- import Data.OpenApi
100+-- import Data.Swagger
107-- data Coord = Coord { x :: Double, y :: Double }
102-- data Coord = Coord { x :: Double, y :: Double }
@@ -110,7 +105,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
110-- declareNamedSchema _ = do
105-- declareNamedSchema _ = do
111-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
106-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
112-- return $ NamedSchema (Just \"Coord\") $ mempty
107-- return $ NamedSchema (Just \"Coord\") $ mempty
113−-- & type_ ?~ OpenApiObject
108+-- & type_ ?~ SwaggerObject
114-- & properties .~
109-- & properties .~
115-- [ (\"x\", doubleSchema)
110-- [ (\"x\", doubleSchema)
116-- , (\"y\", doubleSchema)
111-- , (\"y\", doubleSchema)
@@ -136,7 +131,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
137-- instance ToSchema Coord
132-- instance ToSchema Coord
139−class Typeable a => ToSchema a where
134+class ToSchema a where
140 -- | Convert a type into an optionally named schema
135 -- | Convert a type into an optionally named schema
141 -- together with all used definitions.
136 -- together with all used definitions.
142 -- Note that the schema itself is included in definitions
137 -- Note that the schema itself is included in definitions
@@ -158,19 +153,13 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
159-- >>> toNamedSchema (Proxy :: Proxy String) ^. name
154-- >>> toNamedSchema (Proxy :: Proxy String) ^. name
160-- Nothing
155-- Nothing
161−-- >>> BSL.putStrLn $ encodePretty (toNamedSchema (Proxy :: Proxy String) ^. schema)
156+-- >>> BSL.putStrLn $ encode (toNamedSchema (Proxy :: Proxy String) ^. schema)
163−-- "type": "string"
157+-- {"type":"string"}
166-- >>> toNamedSchema (Proxy :: Proxy Day) ^. name
159-- >>> toNamedSchema (Proxy :: Proxy Day) ^. name
167-- Just "Day"
160-- Just "Day"
168−-- >>> BSL.putStrLn $ encodePretty (toNamedSchema (Proxy :: Proxy Day) ^. schema)
161+-- >>> BSL.putStrLn $ encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
170−-- "example": "2016-07-22",
162+-- {"example":"2016-07-22","format":"date","type":"string"}
174toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
163toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
175toNamedSchema = undeclare . declareNamedSchema
164toNamedSchema = undeclare . declareNamedSchema
@@ -186,35 +175,22 @@ schemaName = _namedSchemaName . toNamedSchema
187-- | Convert a type into a schema.
176-- | Convert a type into a schema.
189−-- >>> BSL.putStrLn $ encodePretty $ toSchema (Proxy :: Proxy Int8)
178+-- >>> BSL.putStrLn $ encode $ toSchema (Proxy :: Proxy Int8)
193−-- "type": "integer"
179+-- {"maximum":127,"minimum":-128,"type":"integer"}
196−-- >>> BSL.putStrLn $ encodePretty $ toSchema (Proxy :: Proxy [Day])
181+-- >>> BSL.putStrLn $ encode $ toSchema (Proxy :: Proxy [Day])
199−-- "$ref": "#/components/schemas/Day"
182+-- {"items":{"$ref":"#/components/schemas/Day"},"type":"array"}
203toSchema :: ToSchema a => Proxy a -> Schema
183toSchema :: ToSchema a => Proxy a -> Schema
204toSchema = _namedSchemaSchema . toNamedSchema
184toSchema = _namedSchemaSchema . toNamedSchema
206-- | Convert a type into a referenced schema if possible.
186-- | Convert a type into a referenced schema if possible.
207-- Only named schemas can be referenced, nameless schemas are inlined.
187-- Only named schemas can be referenced, nameless schemas are inlined.
209−-- >>> BSL.putStrLn $ encodePretty $ toSchemaRef (Proxy :: Proxy Integer)
189+-- >>> BSL.putStrLn $ encode $ toSchemaRef (Proxy :: Proxy Integer)
211−-- "type": "integer"
190+-- {"type":"integer"}
214−-- >>> BSL.putStrLn $ encodePretty $ toSchemaRef (Proxy :: Proxy Day)
192+-- >>> BSL.putStrLn $ encode $ toSchemaRef (Proxy :: Proxy Day)
216−-- "$ref": "#/components/schemas/Day"
193+-- {"$ref":"#/components/schemas/Day"}
218toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
194toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
219toSchemaRef = undeclare . declareSchemaRef
195toSchemaRef = undeclare . declareSchemaRef
@@ -282,15 +258,8 @@ inlineAllSchemas = inlineSchemasWhen (const True)
283-- | Convert a type into a schema without references.
259-- | Convert a type into a schema without references.
285−-- >>> BSL.putStrLn $ encodePretty $ toInlinedSchema (Proxy :: Proxy [Day])
261+-- >>> BSL.putStrLn $ encode $ toInlinedSchema (Proxy :: Proxy [Day])
288−-- "example": "2016-07-22",
262+-- {"items":{"example":"2016-07-22","format":"date","type":"string"},"type":"array"}
295-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
264-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
296-- when inlining recursive schemas.
265-- when inlining recursive schemas.
@@ -323,64 +292,19 @@ inlineNonRecursiveSchemas defs = inlineSchemasWhen nonRecursive defs
323-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
292-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
324-- Produced schema can be used for further refinement.
293-- Produced schema can be used for further refinement.
326−-- >>> BSL.putStrLn $ encodePretty $ sketchSchema "hello"
295+-- >>> BSL.putStrLn $ encode $ sketchSchema "hello"
328−-- "example": "hello",
296+-- {"example":"hello","type":"string"}
332−-- >>> BSL.putStrLn $ encodePretty $ sketchSchema (1, 2, 3)
298+-- >>> BSL.putStrLn $ encode $ sketchSchema (1, 2, 3)
340−-- "type": "number"
299+-- {"example":[1,2,3],"items":{"type":"number"},"type":"array"}
345−-- >>> BSL.putStrLn $ encodePretty $ sketchSchema ("Jack", 25)
301+-- >>> BSL.putStrLn $ encode $ sketchSchema ("Jack", 25)
346−-- {
302+-- {"example":["Jack",25],"items":[{"type":"string"},{"type":"number"}],"type":"array"}
362-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
304-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
363-- >>> instance ToJSON Person
305-- >>> instance ToJSON Person
364−-- >>> BSL.putStrLn $ encodePretty $ sketchSchema (Person "Jack" 25)
306+-- >>> BSL.putStrLn $ encode $ sketchSchema (Person "Jack" 25)
365−-- {
307+-- {"example":{"age":25,"name":"Jack"},"required":["age","name"],"type":"object","properties":{"age":{"type":"number"},"name":{"type":"string"}}}
384sketchSchema :: ToJSON a => a -> Schema
308sketchSchema :: ToJSON a => a -> Schema
385sketchSchema = sketch . toJSON
309sketchSchema = sketch . toJSON
@@ -388,15 +312,15 @@ sketchSchema = sketch . toJSON
388 sketch js@(Bool _) = go js
312 sketch js@(Bool _) = go js
389 sketch js = go js & example ?~ js
313 sketch js = go js & example ?~ js
391− go Null = mempty & type_ ?~ OpenApiNull
315+ go Null = mempty & type_ ?~ SwaggerNull
392− go (Bool _) = mempty & type_ ?~ OpenApiBoolean
316+ go (Bool _) = mempty & type_ ?~ SwaggerBoolean
393− go (String _) = mempty & type_ ?~ OpenApiString
317+ go (String _) = mempty & type_ ?~ SwaggerString
394− go (Number _) = mempty & type_ ?~ OpenApiNumber
318+ go (Number _) = mempty & type_ ?~ SwaggerNumber
395 go (Array xs) = mempty
319 go (Array xs) = mempty
396− & type_ ?~ OpenApiArray
320+ & type_ ?~ SwaggerArray
397 & items ?~ case ischema of
321 & items ?~ case ischema of
398− Just s -> OpenApiItemsObject (Inline s)
322+ Just s -> SwaggerItemsObject (Inline s)
399− _ -> OpenApiItemsArray (map Inline ys)
323+ _ -> SwaggerItemsArray (map Inline ys)
401 ys = map go (V.toList xs)
325 ys = map go (V.toList xs)
402 allSame = and ((zipWith (==)) ys (tail ys))
326 allSame = and ((zipWith (==)) ys (tail ys))
@@ -405,178 +329,64 @@ sketchSchema = sketch . toJSON
405 (z:_) | allSame -> Just z
329 (z:_) | allSame -> Just z
406 _ -> Nothing
330 _ -> Nothing
407 go (Object o) = mempty
331 go (Object o) = mempty
408− & type_ ?~ OpenApiObject
332+ & type_ ?~ SwaggerObject
409− & required .~ sort (objectKeys o)
333+ & required .~ HashMap.keys o
410− & properties .~ fmap (Inline . go) (toInsOrdHashMap o)
334+ & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
412-- | Make a restrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
336-- | Make a restrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
413-- Produced schema uses as much constraints as possible.
337-- Produced schema uses as much constraints as possible.
415−-- >>> BSL.putStrLn $ encodePretty $ sketchStrictSchema "hello"
339+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema "hello"
416−-- {
340+-- {"maxLength":5,"pattern":"hello","minLength":5,"type":"string","enum":["hello"]}
422−-- "pattern": "hello",
426−-- >>> BSL.putStrLn $ encodePretty $ sketchStrictSchema (1, 2, 3)
342+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema (1, 2, 3)
427−-- {
343+-- {"minItems":3,"uniqueItems":true,"items":[{"maximum":1,"minimum":1,"multipleOf":1,"type":"number","enum":[1]},{"maximum":2,"minimum":2,"multipleOf":2,"type":"number","enum":[2]},{"maximum":3,"minimum":3,"multipleOf":3,"type":"number","enum":[3]}],"maxItems":3,"type":"array","enum":[[1,2,3]]}
467−-- "uniqueItems": true
470−-- >>> BSL.putStrLn $ encodePretty $ sketchStrictSchema ("Jack", 25)
345+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema ("Jack", 25)
471−-- {
346+-- {"minItems":2,"uniqueItems":true,"items":[{"maxLength":4,"pattern":"Jack","minLength":4,"type":"string","enum":["Jack"]},{"maximum":25,"minimum":25,"multipleOf":25,"type":"number","enum":[25]}],"maxItems":2,"type":"array","enum":[["Jack",25]]}
485−-- "pattern": "Jack",
501−-- "uniqueItems": true
504-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
348-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
505-- >>> instance ToJSON Person
349-- >>> instance ToJSON Person
506−-- >>> BSL.putStrLn $ encodePretty $ sketchStrictSchema (Person "Jack" 25)
350+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema (Person "Jack" 25)
507−-- {
351+-- {"minProperties":2,"required":["age","name"],"maxProperties":2,"type":"object","enum":[{"age":25,"name":"Jack"}],"properties":{"age":{"maximum":25,"minimum":25,"multipleOf":25,"type":"number","enum":[25]},"name":{"maxLength":4,"pattern":"Jack","minLength":4,"type":"string","enum":["Jack"]}}}
514−-- "maxProperties": 2,
515−-- "minProperties": 2,
532−-- "pattern": "Jack",
542sketchStrictSchema :: ToJSON a => a -> Schema
352sketchStrictSchema :: ToJSON a => a -> Schema
543sketchStrictSchema = go . toJSON
353sketchStrictSchema = go . toJSON
545− go Null = mempty & type_ ?~ OpenApiNull
355+ go Null = mempty & type_ ?~ SwaggerNull
546 go js@(Bool _) = mempty
356 go js@(Bool _) = mempty
547− & type_ ?~ OpenApiBoolean
357+ & type_ ?~ SwaggerBoolean
548 & enum_ ?~ [js]
358 & enum_ ?~ [js]
549 go js@(String s) = mempty
359 go js@(String s) = mempty
550− & type_ ?~ OpenApiString
360+ & type_ ?~ SwaggerString
551 & maxLength ?~ fromIntegral (T.length s)
361 & maxLength ?~ fromIntegral (T.length s)
552 & minLength ?~ fromIntegral (T.length s)
362 & minLength ?~ fromIntegral (T.length s)
553 & pattern ?~ s
363 & pattern ?~ s
554 & enum_ ?~ [js]
364 & enum_ ?~ [js]
555 go js@(Number n) = mempty
365 go js@(Number n) = mempty
556− & type_ ?~ OpenApiNumber
366+ & type_ ?~ SwaggerNumber
557 & maximum_ ?~ n
367 & maximum_ ?~ n
558 & minimum_ ?~ n
368 & minimum_ ?~ n
559 & multipleOf ?~ n
369 & multipleOf ?~ n
560 & enum_ ?~ [js]
370 & enum_ ?~ [js]
561 go js@(Array xs) = mempty
371 go js@(Array xs) = mempty
562− & type_ ?~ OpenApiArray
372+ & type_ ?~ SwaggerArray
563 & maxItems ?~ fromIntegral sz
373 & maxItems ?~ fromIntegral sz
564 & minItems ?~ fromIntegral sz
374 & minItems ?~ fromIntegral sz
565− & items ?~ OpenApiItemsArray (map (Inline . go) (V.toList xs))
375+ & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
566 & uniqueItems ?~ allUnique
376 & uniqueItems ?~ allUnique
567 & enum_ ?~ [js]
377 & enum_ ?~ [js]
569 sz = length xs
379 sz = length xs
570 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
380 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
571 go js@(Object o) = mempty
381 go js@(Object o) = mempty
572− & type_ ?~ OpenApiObject
382+ & type_ ?~ SwaggerObject
573− & required .~ sort names
383+ & required .~ names
574− & properties .~ fmap (Inline . go) (toInsOrdHashMap o)
384+ & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
575 & maxProperties ?~ fromIntegral (length names)
385 & maxProperties ?~ fromIntegral (length names)
576 & minProperties ?~ fromIntegral (length names)
386 & minProperties ?~ fromIntegral (length names)
577 & enum_ ?~ [js]
387 & enum_ ?~ [js]
579− names = objectKeys o
389+ names = HashMap.keys o
581class GToSchema (f :: * -> *) where
391class GToSchema (f :: * -> *) where
582 gdeclareNamedSchema :: SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
392 gdeclareNamedSchema :: SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
@@ -585,8 +395,8 @@ instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
585 declareNamedSchema _ = do
395 declareNamedSchema _ = do
586 ref <- declareSchemaRef (Proxy :: Proxy a)
396 ref <- declareSchemaRef (Proxy :: Proxy a)
587 return $ unnamed $ mempty
397 return $ unnamed $ mempty
588− & type_ ?~ OpenApiArray
398+ & type_ ?~ SwaggerArray
589− & items ?~ OpenApiItemsObject ref
399+ & items ?~ SwaggerItemsObject ref
591instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
401instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
592instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
402instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
@@ -611,7 +421,7 @@ instance ToSchema Scientific where declareNamedSchema = plain . paramSchemaToSc
611instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
421instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
612instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema
422instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema
614−instance (Typeable (Fixed a), HasResolution a) => ToSchema (Fixed a) where declareNamedSchema = plain . paramSchemaToSchema
424+instance HasResolution a => ToSchema (Fixed a) where declareNamedSchema = plain . paramSchemaToSchema
616instance ToSchema a => ToSchema (Maybe a) where
426instance ToSchema a => ToSchema (Maybe a) where
617 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)
427 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)
@@ -628,22 +438,16 @@ instance ToSchema UUID.UUID where
628 declareNamedSchema p = pure $ named "UUID" $ paramSchemaToSchema p
438 declareNamedSchema p = pure $ named "UUID" $ paramSchemaToSchema p
629 & example ?~ toJSON (UUID.toText UUID.nil)
439 & example ?~ toJSON (UUID.toText UUID.nil)
631−instance (ToSchema a, ToSchema b) => ToSchema (a, b) where
441+instance (ToSchema a, ToSchema b) => ToSchema (a, b)
632− declareNamedSchema = fmap unname . genericDeclareNamedSchema defaultSchemaOptions
633−instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c) where
442+instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
634− declareNamedSchema = fmap unname . genericDeclareNamedSchema defaultSchemaOptions
635−instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d) where
443+instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
636− declareNamedSchema = fmap unname . genericDeclareNamedSchema defaultSchemaOptions
637−instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e) => ToSchema (a, b, c, d, e) where
444+instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e) => ToSchema (a, b, c, d, e)
638− declareNamedSchema = fmap unname . genericDeclareNamedSchema defaultSchemaOptions
639−instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f) => ToSchema (a, b, c, d, e, f) where
445+instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f) => ToSchema (a, b, c, d, e, f)
640− declareNamedSchema = fmap unname . genericDeclareNamedSchema defaultSchemaOptions
641−instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f, ToSchema g) => ToSchema (a, b, c, d, e, f, g) where
446+instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f, ToSchema g) => ToSchema (a, b, c, d, e, f, g)
642− declareNamedSchema = fmap unname . genericDeclareNamedSchema defaultSchemaOptions
644timeSchema :: T.Text -> Schema
448timeSchema :: T.Text -> Schema
645timeSchema fmt = mempty
449timeSchema fmt = mempty
646− & type_ ?~ OpenApiString
450+ & type_ ?~ SwaggerString
647 & format ?~ fmt
451 & format ?~ fmt
649-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
453-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -658,7 +462,7 @@ instance ToSchema LocalTime where
658 declareNamedSchema _ = pure $ named "LocalTime" $ timeSchema "yyyy-mm-ddThh:MM:ss"
462 declareNamedSchema _ = pure $ named "LocalTime" $ timeSchema "yyyy-mm-ddThh:MM:ss"
659 & example ?~ toJSON (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0))
463 & example ?~ toJSON (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0))
661−-- | Format @"date-time"@ corresponds to @yyyy-mm-ddThh:MM:ss(Z|+hh:MM)@ format.
465+-- | Format @"date"@ corresponds to @yyyy-mm-ddThh:MM:ss(Z|+hh:MM)@ format.
662instance ToSchema ZonedTime where
466instance ToSchema ZonedTime where
663 declareNamedSchema _ = pure $ named "ZonedTime" $ timeSchema "date-time"
467 declareNamedSchema _ = pure $ named "ZonedTime" $ timeSchema "date-time"
664 & example ?~ toJSON (ZonedTime (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0)) (hoursToTimeZone 3))
468 & example ?~ toJSON (ZonedTime (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0)) (hoursToTimeZone 3))
@@ -690,7 +494,7 @@ instance ToSchemaByteStringError BSL.ByteString => ToSchema BSL.ByteString where
690instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
494instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
692-- | NOTE: This schema does not account for the uniqueness of keys.
496-- | NOTE: This schema does not account for the uniqueness of keys.
693−instance (ToSchema a) => ToSchema (IntMap a) where
497+instance ToSchema a => ToSchema (IntMap a) where
694 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
498 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
696instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
500instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
@@ -701,7 +505,7 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
701 declareObjectMapSchema = do
505 declareObjectMapSchema = do
702 schema <- declareSchemaRef (Proxy :: Proxy v)
506 schema <- declareSchemaRef (Proxy :: Proxy v)
703 return $ unnamed $ mempty
507 return $ unnamed $ mempty
704− & type_ ?~ OpenApiObject
508+ & type_ ?~ SwaggerObject
705 & additionalProperties ?~ AdditionalPropertiesSchema schema
509 & additionalProperties ?~ AdditionalPropertiesSchema schema
707instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
511instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
@@ -709,7 +513,7 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
710instance {-# OVERLAPPING #-} ToSchema Object where
514instance {-# OVERLAPPING #-} ToSchema Object where
711 declareNamedSchema _ = pure $ NamedSchema (Just "Object") $ mempty
515 declareNamedSchema _ = pure $ NamedSchema (Just "Object") $ mempty
712− & type_ ?~ OpenApiObject
516+ & type_ ?~ SwaggerObject
713 & description ?~ "Arbitrary JSON object."
517 & description ?~ "Arbitrary JSON object."
714 & additionalProperties ?~ AdditionalPropertiesAllowed True
518 & additionalProperties ?~ AdditionalPropertiesAllowed True
@@ -746,15 +550,11 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
747-- | Default schema for @'Bounded'@, @'Integral'@ types.
551-- | Default schema for @'Bounded'@, @'Integral'@ types.
749−-- >>> BSL.putStrLn $ encodePretty $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
553+-- >>> BSL.putStrLn $ encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
751−-- "maximum": 32767,
554+-- {"maximum":32767,"minimum":-32768,"type":"integer"}
752−-- "minimum": -32768,
755toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
555toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
756toSchemaBoundedIntegral _ = mempty
556toSchemaBoundedIntegral _ = mempty
757− & type_ ?~ OpenApiInteger
557+ & type_ ?~ SwaggerInteger
758 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
558 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
759 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
559 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
@@ -783,27 +583,8 @@ genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$>
783-- >>> instance ToSchema ButtonState
583-- >>> instance ToSchema ButtonState
784-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
584-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
785-- >>> type ImageUrl = T.Text
585-- >>> type ImageUrl = T.Text
786−-- >>> BSL.putStrLn $ encodePretty $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
586+-- >>> BSL.putStrLn $ encode $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
787−-- {
587+-- {"type":"object","properties":{"Focus":{"type":"string"},"Disabled":{"type":"string"},"Active":{"type":"string"},"Neutral":{"type":"string"},"Hover":{"type":"string"}}}
808-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
589-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
809-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
590-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
@@ -811,15 +592,15 @@ declareSchemaBoundedEnumKeyMapping :: forall map key value.
811 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
592 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
812 => Proxy (map key value) -> Declare (Definitions Schema) Schema
593 => Proxy (map key value) -> Declare (Definitions Schema) Schema
813declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key of
594declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key of
814− ToJSONKeyText getKey _ -> objectSchema getKey
595+ ToJSONKeyText keyToText _ -> objectSchema keyToText
815 ToJSONKeyValue _ _ -> declareSchema (Proxy :: Proxy [(key, value)])
596 ToJSONKeyValue _ _ -> declareSchema (Proxy :: Proxy [(key, value)])
817− objectSchema getKey = do
598+ objectSchema keyToText = do
818 valueRef <- declareSchemaRef (Proxy :: Proxy value)
599 valueRef <- declareSchemaRef (Proxy :: Proxy value)
819 let allKeys = [minBound..maxBound :: key]
600 let allKeys = [minBound..maxBound :: key]
820− mkPair k = (keyToText $ getKey k, valueRef)
601+ mkPair k = (keyToText k, valueRef)
821 return $ mempty
602 return $ mempty
822− & type_ ?~ OpenApiObject
603+ & type_ ?~ SwaggerObject
823 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
604 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
825-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
606-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
@@ -830,27 +611,8 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
830-- >>> instance ToSchema ButtonState
611-- >>> instance ToSchema ButtonState
831-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
612-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
832-- >>> type ImageUrl = T.Text
613-- >>> type ImageUrl = T.Text
833−-- >>> BSL.putStrLn $ encodePretty $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
614+-- >>> BSL.putStrLn $ encode $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
834−-- {
615+-- {"type":"object","properties":{"Focus":{"type":"string"},"Disabled":{"type":"string"},"Active":{"type":"string"},"Neutral":{"type":"string"},"Hover":{"type":"string"}}}
855-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
617-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
856-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
618-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
@@ -860,7 +622,7 @@ toSchemaBoundedEnumKeyMapping :: forall map key value.
860toSchemaBoundedEnumKeyMapping = flip evalDeclare mempty . declareSchemaBoundedEnumKeyMapping
622toSchemaBoundedEnumKeyMapping = flip evalDeclare mempty . declareSchemaBoundedEnumKeyMapping
862-- | A configurable generic @'Schema'@ creator.
624-- | A configurable generic @'Schema'@ creator.
863−genericDeclareSchema :: (Generic a, GToSchema (Rep a), Typeable a) =>
625+genericDeclareSchema :: (Generic a, GToSchema (Rep a)) =>
864 SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
626 SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
865genericDeclareSchema opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchema opts proxy
627genericDeclareSchema opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchema opts proxy
@@ -868,24 +630,9 @@ genericDeclareSchema opts proxy = _namedSchemaSchema <$> genericDeclareNamedSche
868-- This function applied to @'defaultSchemaOptions'@
630-- This function applied to @'defaultSchemaOptions'@
869-- is used as the default for @'declareNamedSchema'@
631-- is used as the default for @'declareNamedSchema'@
870-- when the type is an instance of @'Generic'@.
632-- when the type is an instance of @'Generic'@.
872−-- Default implementation will use the name from 'Typeable' instance, including concrete
873−-- instantioations of type variables.
877−-- >>> _namedSchemaName $ undeclare $ genericDeclareNamedSchema defaultSchemaOptions (Proxy :: Proxy (Either Int Bool))
878−-- Just "Either_Int_Bool"
879−genericDeclareNamedSchema :: forall a. (Generic a, GToSchema (Rep a), Typeable a) =>
633+genericDeclareNamedSchema :: forall a. (Generic a, GToSchema (Rep a)) =>
880 SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
634 SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
881−genericDeclareNamedSchema opts _ =
882− rename (Just $ T.pack name) <$> gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
635+genericDeclareNamedSchema opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
886− orig = fmap unspace $ show $ typeRep @a
887− name = datatypeNameModifier opts orig
890-- | Derive a 'Generic'-based name for a datatype and assign it to a given 'Schema'.
637-- | Derive a 'Generic'-based name for a datatype and assign it to a given 'Schema'.
891genericNameSchema :: forall a d f.
638genericNameSchema :: forall a d f.
@@ -912,8 +659,8 @@ paramSchemaToSchema = toParamSchema
913nullarySchema :: Schema
660nullarySchema :: Schema
914nullarySchema = mempty
661nullarySchema = mempty
915− & type_ ?~ OpenApiArray
662+ & type_ ?~ SwaggerArray
916− & items ?~ OpenApiItemsArray []
663+ & items ?~ SwaggerItemsArray []
918gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
665gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
919gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
666gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
@@ -943,15 +690,12 @@ instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s
943 | unwrapUnaryRecords opts = fieldSchema
690 | unwrapUnaryRecords opts = fieldSchema
944 | otherwise =
691 | otherwise =
945 case schema ^. items of
692 case schema ^. items of
946− Just (OpenApiItemsArray [_]) -> fieldSchema
693+ Just (SwaggerItemsArray [_]) -> fieldSchema
948− -- We have to run recordSchema instead of just using its defs,
695+ declare defs
949− -- since those can be recursive and will lead to infinite loop,
950− -- see https://github.com/biocad/openapi3/pull/37
951− NamedSchema _ schema' <- recordSchema
952− return (unnamed schema')
696+ return (unnamed schema)
954− (_, NamedSchema _ schema) = runDeclare recordSchema mempty
698+ (defs, NamedSchema _ schema) = runDeclare recordSchema mempty
955 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
699 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
956 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
700 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
@@ -974,10 +718,10 @@ gdeclareSchemaRef opts proxy = do
974 return $ Ref (Reference name)
718 return $ Ref (Reference name)
975 _ -> Inline <$> gdeclareSchema opts proxy
719 _ -> Inline <$> gdeclareSchema opts proxy
977−appendItem :: Referenced Schema -> Maybe OpenApiItems -> Maybe OpenApiItems
721+appendItem :: Referenced Schema -> Maybe SwaggerItems -> Maybe SwaggerItems
978−appendItem x Nothing = Just (OpenApiItemsArray [x])
722+appendItem x Nothing = Just (SwaggerItemsArray [x])
979−appendItem x (Just (OpenApiItemsArray xs)) = Just (OpenApiItemsArray (xs ++ [x]))
723+appendItem x (Just (SwaggerItemsArray xs)) = Just (SwaggerItemsArray (xs ++ [x]))
980−appendItem _ _ = error "GToSchema.appendItem: cannot append to OpenApiItemsObject"
724+appendItem _ _ = error "GToSchema.appendItem: cannot append to SwaggerItemsObject"
982withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
726withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
983 SchemaOptions -> proxy s f -> Bool -> Schema -> Declare (Definitions Schema) Schema
727 SchemaOptions -> proxy s f -> Bool -> Schema -> Declare (Definitions Schema) Schema
@@ -986,12 +730,12 @@ withFieldSchema opts _ isRequiredField schema = do
987 if T.null fname
731 if T.null fname
988 then schema
732 then schema
989− & type_ ?~ OpenApiArray
733+ & type_ ?~ SwaggerArray
990 & items %~ appendItem ref
734 & items %~ appendItem ref
991 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
735 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
992 & minItems %~ Just . maybe 1 (+1) -- increment minItems
736 & minItems %~ Just . maybe 1 (+1) -- increment minItems
993 else schema
737 else schema
994− & type_ ?~ OpenApiObject
738+ & type_ ?~ SwaggerObject
995 & properties . at fname ?~ ref
739 & properties . at fname ?~ ref
996 & if isRequiredField
740 & if isRequiredField
997 then required %~ (++ [fname])
741 then required %~ (++ [fname])
@@ -1026,14 +770,14 @@ gdeclareNamedSumSchema opts proxy _
1026 | otherwise = do
770 | otherwise = do
1027 (schemas, _) <- runWriterT declareSumSchema
771 (schemas, _) <- runWriterT declareSumSchema
1028 return $ unnamed $ mempty
772 return $ unnamed $ mempty
1029− & type_ ?~ OpenApiObject
773+ & type_ ?~ SwaggerObject
1030 & oneOf ?~ (snd <$> schemas)
774 & oneOf ?~ (snd <$> schemas)
1032 declareSumSchema = gsumToSchema opts proxy
776 declareSumSchema = gsumToSchema opts proxy
1033 (sumSchemas, All allNullary) = undeclare (runWriterT declareSumSchema)
777 (sumSchemas, All allNullary) = undeclare (runWriterT declareSumSchema)
1035 toStringTag schemas = mempty
779 toStringTag schemas = mempty
1036− & type_ ?~ OpenApiString
780+ & type_ ?~ SwaggerString
1037 & enum_ ?~ map (String . fst) sumSchemas
781 & enum_ ?~ map (String . fst) sumSchemas
1039type AllNullary = All
783type AllNullary = All
@@ -1055,15 +799,15 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
1055 case ref of
799 case ref of
1056 -- If subschema is an object and constructor is a record, we add tag directly
800 -- If subschema is an object and constructor is a record, we add tag directly
1057 -- to the record, as Aeson does it.
801 -- to the record, as Aeson does it.
1058− Just (Inline sub) | sub ^. type_ == Just OpenApiObject && isRecord -> Inline $ sub
802+ Just (Inline sub) | sub ^. type_ == Just SwaggerObject && isRecord -> Inline $ sub
1059 & required <>~ [T.pack tagField]
803 & required <>~ [T.pack tagField]
1060− & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ OpenApiString & enum_ ?~ [String tag])
804+ & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ SwaggerString & enum_ ?~ [String tag])
1062 -- If it is not a record, we need to put subschema into "contents" field.
806 -- If it is not a record, we need to put subschema into "contents" field.
1063 _ | not isRecord -> Inline $ mempty
807 _ | not isRecord -> Inline $ mempty
1064− & type_ ?~ OpenApiObject
808+ & type_ ?~ SwaggerObject
1065 & required .~ [T.pack tagField]
809 & required .~ [T.pack tagField]
1066− & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ OpenApiString & enum_ ?~ [String tag])
810+ & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ SwaggerString & enum_ ?~ [String tag])
1067 -- If constructor is nullary, there is no content.
811 -- If constructor is nullary, there is no content.
1068 & case ref of
812 & case ref of
1069 Just r -> (properties . at (T.pack contentsField) ?~ r) . (required <>~ [T.pack contentsField])
813 Just r -> (properties . at (T.pack contentsField) ?~ r) . (required <>~ [T.pack contentsField])
@@ -1071,17 +815,17 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
1072 -- In the remaining cases we combine "tag" object and "contents" object using allOf.
816 -- In the remaining cases we combine "tag" object and "contents" object using allOf.
1073 _ -> Inline $ mempty
817 _ -> Inline $ mempty
1074− & type_ ?~ OpenApiObject
818+ & type_ ?~ SwaggerObject
1075 & allOf ?~ [Inline $ mempty
819 & allOf ?~ [Inline $ mempty
1076− & type_ ?~ OpenApiObject
820+ & type_ ?~ SwaggerObject
1077 & required .~ (T.pack tagField : if isRecord then [] else [T.pack contentsField])
821 & required .~ (T.pack tagField : if isRecord then [] else [T.pack contentsField])
1078− & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ OpenApiString & enum_ ?~ [String tag])]
822+ & properties . at (T.pack tagField) ?~ (Inline $ mempty & type_ ?~ SwaggerString & enum_ ?~ [String tag])]
1079 & if isRecord
823 & if isRecord
1080 then allOf . _Just <>~ [refOrNullary]
824 then allOf . _Just <>~ [refOrNullary]
1081− else allOf . _Just <>~ [Inline $ mempty & type_ ?~ OpenApiObject & properties . at (T.pack contentsField) ?~ refOrNullary]
825+ else allOf . _Just <>~ [Inline $ mempty & type_ ?~ SwaggerObject & properties . at (T.pack contentsField) ?~ refOrNullary]
1082 UntaggedValue -> refOrEnum -- Aeson encodes nullary constructors as strings in this case.
826 UntaggedValue -> refOrEnum -- Aeson encodes nullary constructors as strings in this case.
1083 ObjectWithSingleField -> Inline $ mempty
827 ObjectWithSingleField -> Inline $ mempty
1084− & type_ ?~ OpenApiObject
828+ & type_ ?~ SwaggerObject
1085 & required .~ [tag]
829 & required .~ [tag]
1086 & properties . at tag ?~ refOrNullary
830 & properties . at tag ?~ refOrNullary
1087 TwoElemArray -> error "unrepresentable in OpenAPI 3"
831 TwoElemArray -> error "unrepresentable in OpenAPI 3"
@@ -1089,7 +833,7 @@ gsumConToSchemaWith ref opts _ = (tag, schema)
1089 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
833 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
1090 isRecord = conIsRecord (Proxy3 :: Proxy3 c f p)
834 isRecord = conIsRecord (Proxy3 :: Proxy3 c f p)
1091 refOrNullary = fromMaybe (Inline nullarySchema) ref
835 refOrNullary = fromMaybe (Inline nullarySchema) ref
1092− refOrEnum = fromMaybe (Inline $ mempty & type_ ?~ OpenApiString & enum_ ?~ [String tag]) ref
836+ refOrEnum = fromMaybe (Inline $ mempty & type_ ?~ SwaggerString & enum_ ?~ [String tag]) ref
1094gsumConToSchema :: (GToSchema (C1 c f), Constructor c) =>
838gsumConToSchema :: (GToSchema (C1 c f), Constructor c) =>
1095 SchemaOptions -> Proxy (C1 c f) -> Declare (Definitions Schema) [(T.Text, Referenced Schema)]
839 SchemaOptions -> Proxy (C1 c f) -> Declare (Definitions Schema) [(T.Text, Referenced Schema)]
@@ -1114,13 +858,7 @@ data Proxy2 a b = Proxy2
1115data Proxy3 a b c = Proxy3
859data Proxy3 a b c = Proxy3
1117−{- $setup
861+-- $setup
1118−>>> import Data.OpenApi
862+-- >>> import Data.Swagger
1119−>>> import Data.Aeson (encode)
863+-- >>> import Data.Aeson (encode)
1120−>>> import Data.Aeson.Types (toJSONKeyText)
864+-- >>> import Data.Aeson.Types (toJSONKeyText)
1121−>>> import Data.OpenApi.Internal.Utils
1122−>>> :set -XScopedTypeVariables
1123−>>> :set -XDeriveAnyClass
1124−>>> :set -XStandaloneDeriving
1125−>>> :set -XTypeApplications