git.iko.soy/typeable/swagger2
on master help sign in
Add doctests for to[Inlined]Schema[Ref] and schemaName
d2570deNickolay Kudasov
src/Data/Swagger/Internal/Schema.hs+27
@@ -123,19 +123,43 @@ declareSchema :: ToSchema a => proxy a -> Declare Definitions Schema
123declareSchema = fmap snd . declareNamedSchema
123declareSchema = fmap snd . declareNamedSchema
124
124
125-- | Convert a type into an optionally named schema.
125-- | Convert a type into an optionally named schema.
126+--
127+-- >>> encode <$> toNamedSchema (Proxy :: Proxy String)
128+-- (Nothing,"{\"type\":\"string\"}")
129+--
130+-- >>> encode <$> toNamedSchema (Proxy :: Proxy Day)
131+-- (Just "Day","{\"format\":\"yyyy-mm-dd\",\"type\":\"string\"}")
126toNamedSchema :: ToSchema a => proxy a -> NamedSchema
132toNamedSchema :: ToSchema a => proxy a -> NamedSchema
127toNamedSchema = undeclare . declareNamedSchema
133toNamedSchema = undeclare . declareNamedSchema
128
134
129-- | Get type's schema name according to its @'ToSchema'@ instance.
135-- | Get type's schema name according to its @'ToSchema'@ instance.
136+--
137+-- >>> schemaName (Proxy :: Proxy Int)
138+-- Nothing
139+--
140+-- >>> schemaName (Proxy :: Proxy UTCTime)
141+-- Just "UTCTime"
130schemaName :: ToSchema a => proxy a -> Maybe T.Text
142schemaName :: ToSchema a => proxy a -> Maybe T.Text
131schemaName = fst . toNamedSchema
143schemaName = fst . toNamedSchema
132
144
133-- | Convert a type into a schema.
145-- | Convert a type into a schema.
146+--
147+-- >>> encode $ toSchema (Proxy :: Proxy Int8)
148+-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
149+--
150+-- >>> encode $ toSchema (Proxy :: Proxy [Day])
151+-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
134toSchema :: ToSchema a => proxy a -> Schema
152toSchema :: ToSchema a => proxy a -> Schema
135toSchema = snd . toNamedSchema
153toSchema = snd . toNamedSchema
136
154
137-- | Convert a type into a referenced schema if possible.
155-- | Convert a type into a referenced schema if possible.
138-- Only named schemas can be referenced, nameless schemas are inlined.
156-- Only named schemas can be referenced, nameless schemas are inlined.
157+--
158+-- >>> encode $ toSchemaRef (Proxy :: Proxy Integer)
159+-- "{\"type\":\"integer\"}"
160+--
161+-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
162+-- "{\"$ref\":\"#/definitions/Day\"}"
139toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
163toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
140toSchemaRef = undeclare . declareSchemaRef
164toSchemaRef = undeclare . declareSchemaRef
141
165
@@ -203,6 +227,9 @@ inlineAllSchemas = inlineSchemasWhen (const True)
203
227
204-- | Convert a type into a schema without references.
228-- | Convert a type into a schema without references.
205--
229--
230+-- >>> encode $ toInlinedSchema (Proxy :: Proxy [Day])
231+-- "{\"items\":{\"format\":\"yyyy-mm-dd\",\"type\":\"string\"},\"type\":\"array\"}"
232+--
206-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
233-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
207-- when inlining recursive schemas.
234-- when inlining recursive schemas.
208toInlinedSchema :: ToSchema a => proxy a -> Schema
235toInlinedSchema :: ToSchema a => proxy a -> Schema