You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a Connexion app with an OpenAPI spec which uses $ref to reference the request body schema, requesting /openapi.json leads to an error after the endpoint which uses $ref in the specification has been called.
Minimal example
Install connexion["swagger-ui"] (and uvicorn for serving), and paste the files below.
connexion.exceptions.InvalidSpecification: {'content': {'application/json': {'schema': {'type': 'object', 'properties': {'name': {'type': 'string', 'description': 'A name'}}, 'components': {'schemas': {'Test': {'type': 'object', 'properties': {'name': {'type': 'string', 'description': 'A name'}}}}}}}}} is not valid under any of the given schemas
Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^\\/']['patternProperties']['^(get|put|post|delete|options|head|patch|trace)$']['properties']['requestBody']:
{'oneOf': [{'$ref': '#/definitions/RequestBody'},
{'$ref': '#/definitions/Reference'}]}
On instance['paths']['/greeting']['post']['requestBody']:
{'content': {'application/json': {'schema': {'type': 'object',
'properties': {'name': {'type': 'string',
'description': 'A '
'name'}},
'components': {'schemas': {'Test': {'type': 'object',
'properties': {'name': {'type': 'string',
'description': 'A '
'name'}}}}}}}}}
More details
The issue seems to be that #2002 returns the processed OpenAPI spec, which contains a components key inside the schema, so that the OpenAPI schema validator complains (correctly) about an invalid spec and /openapi.json refuses to deliver the spec. In fact, some testing shows that reverting bb48fb3 fixes the issue.
I'm not really sure but this might be related to the discussion in #1829.
Sample test
Something like the following might work as an integration test with the openapi.yaml from above (I used this for finding bb48fb3; maybe this helps):
from connexion import AsyncApp
from os import path
def post_greeting(body):
return f"Hello {body['name']}", 200
def test_esoteric_error():
app = AsyncApp(__name__)
app.add_api(path.join(path.dirname(__file__), "fixtures/simple/esoteric-error.yaml"))
client = app.test_client()
response = client.get("/openapi.json")
assert response.status_code == 200
response = client.post("/greeting", data={"name": "XYZ"}, headers={"Content-Type": "application/json"})
# assert response.status_code == 200 <-- returns Bad Request for some reason I didn't investigate; however it's sufficient to reproduce the error
response = client.get("/openapi.json")
assert response.status_code == 200
The text was updated successfully, but these errors were encountered:
I have a similar error - spec validation failing with components appearing out of nowhere alongside properties and type in requestBody - but I don't have a $ref in requestBody, only in responses" So I don't think that the $ref in requestBody is the cause.
Same here. Looks like this was introduced in the latest release. As a workaround, downgrading from connexion==3.2.0 to connexion==3.1.0 resolved it for me.
Problem description
When creating a Connexion app with an OpenAPI spec which uses
$ref
to reference the request body schema, requesting/openapi.json
leads to an error after the endpoint which uses$ref
in the specification has been called.Minimal example
connexion["swagger-ui"]
(anduvicorn
for serving), and paste the files below.uvicorn run:app
/greeting
endpointContents of openapi.yaml:
Contents of run.py:
Error message
More details
The issue seems to be that #2002 returns the processed OpenAPI spec, which contains a
components
key inside theschema
, so that the OpenAPI schema validator complains (correctly) about an invalid spec and/openapi.json
refuses to deliver the spec. In fact, some testing shows that reverting bb48fb3 fixes the issue.I'm not really sure but this might be related to the discussion in #1829.
Sample test
Something like the following might work as an integration test with the
openapi.yaml
from above (I used this for finding bb48fb3; maybe this helps):The text was updated successfully, but these errors were encountered: