-
-
Notifications
You must be signed in to change notification settings - Fork 181
Description
Hello there.
I am trying to create a path operation using ApiSpec as follows:
apiSpec.path(
path = "/my-item",
operations = dict(
post = dict(
tags = ["MyItem"],
operationId = "createMyItem",
description = "Create MyItem",
requestBody ={ "$ref": "#/components/requestBodies/MyItem" } ,
responses = {'200': {'$ref': '#/components/responses/OK'}, '500': {'$ref': '#/components/responses/GeneralError'}}
)
))
When I try to pass the ResponseBody as ref, as above, I get below error:
File "c:\workspace.venv\Lib\site-packages\apispec\core.py", line 549, in path
self.components.resolve_refs_in_path(self._paths[path])
File "c:\workspace.venv\Lib\site-packages\apispec\core.py", line 410, in resolve_refs_in_path
self._resolve_refs_in_operation(path[method])
File "c:\workspace.venv\Lib\site-packages\apispec\core.py", line 382, in _resolve_refs_in_operation
self._resolve_refs_in_request_body(operation["requestBody"])
File "c:\workspace.venv\Lib\site-packages\apispec\core.py", line 352, in _resolve_refs_in_request_body
for media_type in request_body["content"].values():
~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 'content'
I could pass the whole ResponseBody schema, which is already present in my apiSpec.options['components']['requestBodies']['MyItem'], but this would add duplication for each of my path operations and I would like to avoid this.
Could you advice if it is possible to pass a $ref for RequestBody, which should result in:
post:
description: Create MyItem
operationId: createMyItem
requestBody:
$ref: '#/components/requestBodies/MyItem'
In my generated .yaml file?
Also some doc with more real case example would be very handy to work with the ApiSpec library. I checked examples in the ApiSpec read the docs but I could not find proper example of how to add / manipulate operation to a path etc.
Thank you in advance :)