Currently, the instance is this:
instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction k of
ToJSONKeyText _ _ -> declareObjectMapSchema
ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, v)])
where
declareObjectMapSchema = do
schema <- declareSchemaRef (Proxy :: Proxy v)
return $ unnamed $ mempty
& type_ ?~ OpenApiObject
& additionalProperties ?~ AdditionalPropertiesSchema schema
so when toJSONKey returns a ToJSONKeyText, the resulting schema only uses the schema for v to define additionalProperties, but it doesn't do anything with to schema for k. This means that if k's schema & FromJSONKey instance do restrict what keys are valid, this is silently ignored and the generated schema is incorrect.
JSON Schema has a propertyNames keyword as of draft 6 (source) that could be used to define a correct schema, but I don't know if that's also included yet in the OpenAPI version that this library targets. If propertyNames can't be used, then IMO the instance should be changed to be more restrictive, so that k has to have an equivalent schema to Text.
This also affects the instance for HashMap since that just reuses the instance for Map.
Currently, the instance is this:
so when
toJSONKeyreturns aToJSONKeyText, the resulting schema only uses the schema forvto defineadditionalProperties, but it doesn't do anything with to schema fork. This means that ifk's schema &FromJSONKeyinstance do restrict what keys are valid, this is silently ignored and the generated schema is incorrect.JSON Schema has a
propertyNameskeyword as of draft 6 (source) that could be used to define a correct schema, but I don't know if that's also included yet in the OpenAPI version that this library targets. IfpropertyNamescan't be used, then IMO the instance should be changed to be more restrictive, so thatkhas to have an equivalent schema toText.This also affects the instance for
HashMapsince that just reuses the instance forMap.