New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize setup_openapi #84
Comments
Hi @chobeat Thanks for your question, I’m curious whether this trick helps you: https://rororo.readthedocs.io/en/latest/openapi_speedups.html#testing-cache-reading-schema-and-spec-creation Here the example in rororo test suite: rororo/tests/test_openapi_openapi.py Line 43 in 4e32b4a
In my projects passing |
As of initial proposal of passing spec instance directly in Thanks again for starting discussion about the topic |
Oh, it looks totally fine. I was using an older version of rororo and I must have missed that parameter. I will try it for sure, thanks. |
Great! But I believe directly passing And shouldn’t take long to implement and test |
I tried your suggestion: it goes faster but I think I've found an unrelated bug. In I think it's happening on all my responses that contain at least a None value somewhere. |
…up_openapi` Previously *rororo* relies only on `schema_path` positional argument and does read schema from path and instantiate spec instance inside of `setup_openapi` call. This commit allows to directly path `schema` and `spec` keyword args to `setup_openapi`, which gives developers wider range of caching / reusing schema & spec for environments, which needs to instantiate `web.Application` (and call `setup_openapi`) a lot. Fixes: #84
Hi @chobeat, Your initial proposal on passing After it will be merged into from pathlib import Path
import yaml
from aiohttp import web
from openapi_core.shortcuts import create_spec
from rororo import setup_openapi
openapi_yaml = Path(__file__).parent / "openapi.yaml"
schema = yaml.load(
openapi_yaml.read_bytes(), Loader=yaml.CSafeLoader
)
spec = create_spec(schema)
app = setup_openapi(
web.Application(),
operations,
schema=schema,
spec=spec,
) Also, in contradiction, with your initial request, you must pass
|
…up_openapi` (#86) Previously *rororo* relies only on `schema_path` positional argument and does read schema from path and instantiate spec instance inside of `setup_openapi` call. This commit allows to directly path `schema` and `spec` keyword args to `setup_openapi`, which gives developers wider range of caching / reusing schema & spec for environments, which needs to instantiate `web.Application` (and call `setup_openapi`) a lot. Fixes: #84
Problem: Using rororo with aiohttp, I end up reloading the openapi.yaml for every test and populating the app with setup_openapi. This takes up 30% of the total time of my test suite. 15% is just loading the file in read_schema, while another 12% is spent in create_spec.
Proposal: decouple the spec creation from the addition of fields and routes to the app. After this, create a separate setup_openapi (maybe called setup_test_openapi) that can take a
Spec
object as an additional parameter and set it instead of creating it. The underlying implementation will be the same, but the first half of the current setup_openapi will be optionalI can try to work on this if you don't see conflicts arising
The text was updated successfully, but these errors were encountered: