Hi,
Let's consider the 3 following files :
openapi1.yaml
openapi: 3.0.4
info:
title: My title
version: '1.0'
servers:
- url: http://127.0.0.1:8000
paths:
/endpoint1:
get:
operationId: operationId1
responses:
'200':
description: My description
openapi2.yaml
openapi: 3.0.4
info:
title: My title
version: '1.0'
servers:
- url: http://127.0.0.1:8000/path2
paths:
/endpoint2:
get:
operationId: operationId2
responses:
'200':
description: My description
script.py
from connexion import AsyncApp
from connexion.resolver import Resolver
class MockResolver(Resolver):
def __init__(self, mock):
super().__init__()
self.mock = mock
self.operations = {}
def resolve_operation_id(self, operation):
self.operations[operation.operation_id] = operation
return operation.operation_id
def resolve_function_from_operation_id(self, operation_id):
def _call_mock(*args, **kwargs):
return self.mock[operation_id](*args, operation_id=operation_id, **kwargs)
return _call_mock
def my_function1(**kwargs):
return "OK1"
def my_function2(**kwargs):
return "OK2"
mock = {
"operationId1": my_function1,
"operationId2": my_function2
}
resolver = MockResolver(mock)
app = AsyncApp(__name__)
app.add_api(specification="openapi1.yaml", resolver=resolver, strict_validation=True)
app.add_api(specification="openapi2.yaml", resolver=resolver, strict_validation=True)
app.run()
When calling endpoints, its is working properly
curl http://127.0.0.1:8000/endpoint1
"OK1"
curl http://127.0.0.1:8000/path2/endpoint2
"OK2"
Now, in the python script, we swap the order in which the openapis are added.
From
app.add_api(specification="openapi1.yaml", resolver=resolver, strict_validation=True)
app.add_api(specification="openapi2.yaml", resolver=resolver, strict_validation=True)
To
app.add_api(specification="openapi2.yaml", resolver=resolver, strict_validation=True)
app.add_api(specification="openapi1.yaml", resolver=resolver, strict_validation=True)
Then, we call the endpoints the same way than previously.
Expected behavior
curl http://127.0.0.1:8000/endpoint1
"OK1"
curl http://127.0.0.1:8000/path2/endpoint2
"OK2"
Obtained behavior
curl http://127.0.0.1:8000/endpoint1
"OK1"
curl http://127.0.0.1:8000/path2/endpoint2
{"type": "about:blank", "title": "Not Found", "detail": "Not Found", "status": 404}
Why does the order in which the two openapis are added affect the behavior of spec-first/connection when we calls the 2 endpoints ?
Thank you :-)
Hi,
Let's consider the 3 following files :
openapi1.yaml
openapi2.yaml
script.py
When calling endpoints, its is working properly
Now, in the python script, we swap the order in which the openapis are added.
From
To
Then, we call the endpoints the same way than previously.
Expected behavior
Obtained behavior
Why does the order in which the two openapis are added affect the behavior of spec-first/connection when we calls the 2 endpoints ?
Thank you :-)