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 openapi is 3.1.0 the isinstance check prints 1, but when it is 3.0.2 then we get 0.
Is there a better way to handle this, without knowing ahead of time the version of the OAS to be loaded?
Right now I've fallen back to using if hasattr(pet, "ref") when I want to check if the current object is a Reference, but this doesn't scale very well.
Suggestions?
The text was updated successfully, but these errors were encountered:
Hi @jtreminio - you're right that the top-level imports default to the latest version (3.1.x) objects for convenience. However both the 3.0 and 3.1 objects can also be imported explicitly from openapi_pydantic.v3.v3_0 and openapi_pydantic.v3.v3_1 too.
You should therefore either be able to use the isinstance check against the explicit version of Reference that you are expecting (in this case from openapi_pydantic.v3.v3_0 import Reference), or you can import both the v3_0 and v3_1 models and use the tuple form to check both models (ie isinstance(obj, (v3_0.Reference, v3_1.Reference))).
Seems depending on the OAS version used, a different set of libraries will be loaded
v3_0
vsv3_1
.This is fine, and a great help, but I seem to be running into issues when testing an object with
isinstance
.With the following simple OAS
and the following code:
When
openapi
is3.1.0
theisinstance
check prints1
, but when it is3.0.2
then we get0
.Is there a better way to handle this, without knowing ahead of time the version of the OAS to be loaded?
Right now I've fallen back to using
if hasattr(pet, "ref")
when I want to check if the current object is a Reference, but this doesn't scale very well.Suggestions?
The text was updated successfully, but these errors were encountered: