-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OpenRPC schema generator #56
Conversation
fastapi_jsonrpc/__init__.py
Outdated
'code': error.CODE, | ||
'message': error.MESSAGE, | ||
} | ||
for error in route.errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about more complicated error schema? OpenRPC allow use extra fields except code
and message
?
Right now fastapi-jsonrpc support custom ErrorModel which allow you extend jsonrpc error results and this custom schema is visible in openapi (Swagger)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, https://spec.open-rpc.org/#error-object allow custom data too
BaseError
(item of route.errors
list) have a get_data_model() method. You can use it to pass correct schema into openRPC data part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, custom errors' schemas are now supported 818c158
LGTM, other minor improvements like cache and route override/customize schema we can do later. You can start make tests 🔥 |
All right, now we have some tests f9cb6cb |
Is there support for examples in openRPC? I mean if we have two error with the same code like |
There is, but it's meant to be used only for params and result values. As for errors, the only place to store them is At the same time, {
"error": 6000,
"message": "ValidationError",
"data": {
"anyOf": [
{"title": "MyError.Data", "type": "object", "properties": {"details": {"title": "Details", "type": "string"}}, "required": ["details"]},
{"title": "MyError.Data", "type": "string"}
]
}
} |
Can you make it? But i think current implementation of openRPC playground does not supported it. Other things looks good for me |
I had to move errors' defs into |
Closes #54
@smagafurov @spumer Please have a look. I'll add some tests if this looks good enough to you