git.iko.soy/typeable/openapi3
on master help sign in
Add schema templates for binary, byte and password formats
63ed597Nickolay Kudasov
src/Data/Swagger/Internal/ParamSchema.hs+19
@@ -35,6 +35,25 @@ import Data.Swagger.Internal
35import Data.Swagger.Lens
35import Data.Swagger.Lens
36import Data.Swagger.SchemaOptions
36import Data.Swagger.SchemaOptions
37
37
38+-- | Default schema for binary data (any sequence of octets).
39+binaryParamSchema :: ParamSchema t
40+binaryParamSchema = mempty
41+ & type_ .~ SwaggerString
42+ & format ?~ "binary"
43+
44+-- | Default schema for binary data (base64 encoded).
45+byteParamSchema :: ParamSchema t
46+byteParamSchema = mempty
47+ & type_ .~ SwaggerString
48+ & format ?~ "byte"
49+
50+-- | Default schema for password string.
51+-- @"password"@ format is used to hint UIs the input needs to be obscured.
52+passwordParamSchema :: ParamSchema t
53+passwordParamSchema = mempty
54+ & type_ .~ SwaggerString
55+ & format ?~ "password"
56+
38-- | Convert a type into a plain @'ParamSchema'@.
57-- | Convert a type into a plain @'ParamSchema'@.
39--
58--
40-- An example type and instance:
59-- An example type and instance:
src/Data/Swagger/Internal/Schema.hs+19
@@ -267,6 +267,25 @@ inlineNonRecursiveSchemas defs = inlineSchemasWhen nonRecursive defs
267 traverse_ usedNames (HashMap.lookup name defs)
267 traverse_ usedNames (HashMap.lookup name defs)
268 Inline subschema -> usedNames subschema
268 Inline subschema -> usedNames subschema
269
269
270+-- | Default schema for binary data (any sequence of octets).
271+binarySchema :: Schema
272+binarySchema = mempty
273+ & type_ .~ SwaggerString
274+ & format ?~ "binary"
275+
276+-- | Default schema for binary data (base64 encoded).
277+byteSchema :: Schema
278+byteSchema = mempty
279+ & type_ .~ SwaggerString
280+ & format ?~ "byte"
281+
282+-- | Default schema for password string.
283+-- @"password"@ format is used to hint UIs the input needs to be obscured.
284+passwordSchema :: Schema
285+passwordSchema = mempty
286+ & type_ .~ SwaggerString
287+ & format ?~ "password"
288+
270class GToSchema (f :: * -> *) where
289class GToSchema (f :: * -> *) where
271 gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
290 gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
272
291
src/Data/Swagger/ParamSchema.hs+5
@@ -14,6 +14,11 @@ module Data.Swagger.ParamSchema (
14 genericToParamSchema,
14 genericToParamSchema,
15 toParamSchemaBoundedIntegral,
15 toParamSchemaBoundedIntegral,
16
16
17+ -- * Schema templates
18+ passwordParamSchema,
19+ binaryParamSchema,
20+ byteParamSchema,
21+
17 -- * Generic encoding configuration
22 -- * Generic encoding configuration
18 SchemaOptions(..),
23 SchemaOptions(..),
19 defaultSchemaOptions,
24 defaultSchemaOptions,
src/Data/Swagger/Schema.hs+5
@@ -24,6 +24,11 @@ module Data.Swagger.Schema (
24 paramSchemaToNamedSchema,
24 paramSchemaToNamedSchema,
25 paramSchemaToSchema,
25 paramSchemaToSchema,
26
26
27+ -- * Schema templates
28+ passwordSchema,
29+ binarySchema,
30+ byteSchema,
31+
27 -- * Inlining @'Schema'@s
32 -- * Inlining @'Schema'@s
28 inlineNonRecursiveSchemas,
33 inlineNonRecursiveSchemas,
29 inlineAllSchemas,
34 inlineAllSchemas,