Allow full schema customization - #36
Conversation
Codecov Report
@@ Coverage Diff @@
## main #36 +/- ##
==========================================
+ Coverage 93.12% 93.20% +0.07%
==========================================
Files 11 11
Lines 771 780 +9
==========================================
+ Hits 718 727 +9
Misses 53 53
Continue to review full report at Codecov.
|
| self._spec = spec.setdefault("components", {}) | ||
|
|
||
| @property | ||
| def examples(self) -> dict: |
There was a problem hiding this comment.
Should return an object with attribute summary, description, value ...
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#example-object
There was a problem hiding this comment.
To clarify, you'd like me to add a class abstraction similar to the other structs?
There was a problem hiding this comment.
I had followed what the schemas method was doing. Maybe the usage differs significantly enough or is there a better reaon to make the interface not consistent across them?
|
Please, in the readme, add paragraph "Custom Open API Schema" between "Custom Validation error" and "Demo" paragraphs. |
197g
left a comment
There was a problem hiding this comment.
Some maintainer input on this interface decision would be good for consistency and to ensure future developments follows similar concepts.
| attribute, which is invoked as a callback each time the schema is generated. | ||
|
|
||
| .. code-block:: python3 | ||
| def add_custom_example(oas, oas_path, view, oas_operation): |
There was a problem hiding this comment.
Actually, this brings up a bit of an unresolved interface problem. These 4 parameters are somewhat arbitrary. Would it be better to provide a namedtuple so that additional context can be added later, if it turns out that it was missing?
There was a problem hiding this comment.
Most straightforward, imho, would be to differentiate between the item that the modification should be performed on and the remaining context as a namespace (containing the three other parameters as attributes):
def add_custom_example(ctx, oas_operation):
ctx.oas.components.setdefault( // …
Adds a full callback hook to customize schema after the type annotations have been processed, not unlike
pydanticsown__modify_schema__customization point. The goal here is to provide a suitable fallback for arbitrary modifications to the OpenAPI specification, in case the provided attribute processing is not yet ready for the details. The alternative, implementing the full available OpenAPI fields, is unlikely to be feasible and not readily translate to annotations.