Skip to content

Commit

Permalink
openapi schema generation bug fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dapper91 committed Dec 7, 2023
1 parent cbe54a0 commit c6ea241
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pjrpc/server/specs/extractors/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def extract_result_schema(self, method: MethodType) -> Schema:
description=result_schema.get('description', UNSET),
deprecated=result_schema.get('deprecated', UNSET),
required=required,
definitions=model_schema.get('definitions', UNSET),
definitions=model_schema.get('$defs', UNSET),
)

return result_schema
Expand Down
15 changes: 14 additions & 1 deletion tests/server/resources/openapi-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
]
},
"result": {
"$ref": "#/components/schemas/Model"
"$ref": "#/components/schemas/ResultModel"
}
},
"required": [
Expand Down Expand Up @@ -1221,6 +1221,19 @@
"field1",
"field3"
]
},
"ResultModel": {
"properties": {
"field1": {
"title": "Field1",
"type": "string"
}
},
"required": [
"field1"
],
"title": "ResultModel",
"type": "object"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion tests/server/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Model(pydantic.BaseModel):
field2: Optional[int] = 1
field3: SubModel

class ResultModel(pydantic.BaseModel):
field1: str

class TestError(pjrpc.common.exceptions.JsonRpcError):
code = 2001
message = 'test error 1'
Expand Down Expand Up @@ -91,7 +94,7 @@ class TestError(pjrpc.common.exceptions.JsonRpcError):
def method1(ctx, param1: int, param2: Model, param3) -> int:
pass

def method2(param1: int, param2) -> Model:
def method2(param1: int, param2) -> ResultModel:
pass

def method3(param1: Optional[float] = None, param2: int = 1) -> Optional[str]:
Expand Down

0 comments on commit c6ea241

Please sign in to comment.