@@ -123,19 +123,43 @@ declareSchema :: ToSchema a => proxy a -> Declare Definitions Schema
123declareSchema = fmap snd . declareNamedSchema
123declareSchema = fmap snd . declareNamedSchema
125-- | Convert a type into an optionally named schema.
125-- | Convert a type into an optionally named schema.
127+-- >>> encode <$> toNamedSchema (Proxy :: Proxy String)
128+-- (Nothing,"{\"type\":\"string\"}")
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
129-- | Get type's schema name according to its @'ToSchema'@ instance.
135-- | Get type's schema name according to its @'ToSchema'@ instance.
137+-- >>> schemaName (Proxy :: Proxy Int)
140+-- >>> schemaName (Proxy :: Proxy UTCTime)
130schemaName :: ToSchema a => proxy a -> Maybe T.Text
142schemaName :: ToSchema a => proxy a -> Maybe T.Text
131schemaName = fst . toNamedSchema
143schemaName = fst . toNamedSchema
133-- | Convert a type into a schema.
145-- | Convert a type into a schema.
147+-- >>> encode $ toSchema (Proxy :: Proxy Int8)
148+-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
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
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.
158+-- >>> encode $ toSchemaRef (Proxy :: Proxy Integer)
159+-- "{\"type\":\"integer\"}"
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
@@ -203,6 +227,9 @@ inlineAllSchemas = inlineSchemasWhen (const True)
204-- | Convert a type into a schema without references.
228-- | Convert a type into a schema without references.
230+-- >>> encode $ toInlinedSchema (Proxy :: Proxy [Day])
231+-- "{\"items\":{\"format\":\"yyyy-mm-dd\",\"type\":\"string\"},\"type\":\"array\"}"
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