Closed sanlee42 closed 3 years ago
"$ref": "#/definitions/MyType"
this is not relative, it uses the document as the root, which doesn't exist. (it would have to be something like #/methods/0/params/0/schema/definitions/MyType
)
I'd recommend using the components
section to separate out reusable snippets like schemas:
Also, you dont need $schema
{
"openrpc": "1.1.0",
"info": {
"title": "My JSON-RPC",
"version": "0.1"
},
"methods": [
{
"name": "hello.method.call",
"params": [
{
"name": "first_param",
"schema": {
"title": "MyParam",
"type": "object",
"required": [
"my_bool",
"my_int",
"my_type"
],
"properties": {
"my_bool": {
"type": "boolean"
},
"my_int": {
"type": "integer",
"format": "int32"
},
"my_type": {
"$ref": "#/components/schemas/MyType"
}
}
}
}
],
"result": {
"name": "ret",
"schema": {
"title": "MyRet",
"type": "object",
"required": [
"success"
],
"properties": {
"success": {
"type": "boolean"
}
}
}
}
}
],
"components": {
"schemas": {
"MyType": {
"type": "object",
"required": [
"my_int"
],
"properties": {
"my_int": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}
@shanejonas, Really appreciate your answer. I was working on generating the open rpc schema for my json rpc methods automatically. And the schema objects are generated by the json schema library. It seems that I can't use them directly, since I need to put them into the components section.
@fikgol if you are using golang there is this library to generate the openrpc document from your code: https://github.com/etclabscore/go-openrpc-reflect
Also the advanced section of the webinar is all about go-openrpc-reflect
and generating documents from code: https://open-rpc.org/webinar/
@shanejonas Thanks for the suggestion. I use rust, and I read the codes of go-openrpc-reflect, which uses inline subschemas instead of components section or definitions field to work around this issue. This may produce some duplicate codes, but it works.
Describe the bug The schema object with definitions field would got a resolving error:
but "definitions" field is valid in json schema draft-07.
To Reproduce Steps to reproduce the behavior: