BlackSheep
BlackSheep copied to clipboard
Support mapping types in OpenAPI schema
It is useful to return some grouped data
@dataclass
class User:
id: str
name: str
Example for Dict[str, list[User]]
{
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" }
},
"required": ["id", "name"]
}
}
}
I've pinned black to 23.12.1 because in the 24 release it wants to make a lot of changes. I guess it should be a separate patch.
Codecov Report
Attention: 3 lines
in your changes are missing coverage. Please review.
Comparison is base (
bec8e14
) 96.37% compared to head (7d6659b
) 96.35%.
Files | Patch % | Lines |
---|---|---|
blacksheep/server/openapi/v3.py | 84.21% | 3 Missing :warning: |
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@ Coverage Diff @@
## main #476 +/- ##
==========================================
- Coverage 96.37% 96.35% -0.03%
==========================================
Files 69 69
Lines 6487 6506 +19
==========================================
+ Hits 6252 6269 +17
- Misses 235 237 +2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I don't understand what is the meaning of this fragment:
description: Success response
content:
application/json:
schema:
type: object
properties:
^[a-z0-9!\"#$%&'()*+,.\/:;<=>?@\[\] ^_`{|}~-]+$:
type: object
properties:
^[0-9]+$:
$ref: '#/components/schemas/Cat'
nullable: false
nullable: false
The documentation here for OpenAPI specification 3.0 describes structures that look much simpler than this one: https://swagger.io/docs/specification/data-models/dictionaries/
@RobertoPrevato Oh, I forgot about additionalProperties
, thanks for the example. The idea was to also add type validation(via regex) for keys in dicts. The regex looks ugly, but I couldn't find another way to validate a type for keys.
I'll prepare changes with additionalProperties
. I think it will look much better
it requires https://github.com/Neoteroi/essentials-openapi/pull/43