A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/OpenAPITools/openapi-generator/issues/9684 below:

[BUG][python] allOf with subobjects generates "Invalid inputs" · Issue #9684 · OpenAPITools/openapi-generator · GitHub

Bug Report Checklist Description

The current testcases for allOf in petstore seem to work on the assumption that passing model arguments in init() can be passed to all objects in the allOf.

In particular, the method "validate_get_composed_info" description says:

Exceptions are raised if:
- 0 or > 1 oneOf schema matches the model_args input data
- no anyOf schema matches the model_args input data
- any of the allOf schemas do not match the model_args input data

This seems to suggest that I cannot instantiate a composedObject (via its constructor), with arguments that are associated with a particular object in the oneOf list.

I made a very simple change to the petstore api model spec to highlight this:

+    SpecialAttributes:
+      type: string
+      minLength: 1
+      maxLength: 100
     ShapeInterface:
       properties:
         shapeType:
           type: string
+        name:
+          $ref: '#/components/schemas/SpecialAttributes'
       required:
         - shapeType

Adding a name to ShapeInterface, with min/max arguments now makes it ModelNormal, (rather than a simple string).

instantiating this:

equilateral_triangle.EquilateralTriangle(triangle_type="EquilateralTriangle", shape_type="Triangle", name=SpecialAttributes("aname"))

gives the following error:

petstore_api.exceptions.ApiValueError: Invalid inputs given to generate an instance of 'TriangleInterface'. The input data was invalid for the allOf schema 'TriangleInterface' in the composed schema 'EquilateralTriangle'. Error=Invalid type for variable 'name'. Required value type is one of [NoneType, bool, date, datetime, dict, float, int, list, str] and passed type was SpecialAttributes at ['name']

I believe this error is due to the "SpecialAttributes" property, which is valid for ShapeInterface, but not valid for the TriangleInterface. So the loop of passing the constructor arguments to each allOf class hits the TriangleInterfac, and then errors out. If SpecialAttribute was a normal string, it would work, since that is a primitive value type.

openapi-generator version

master

Suggest a fix

Its not clear what the correct solution is. It appears to me that the premise of allOf compostion currently works by way of "additionalTypes" being passed into each allOf object, and as long as the types are of primitive types, it is able to instantiate this composed objects. The oneOf, anyOf works since it is able to catch the exception and continue. With the allOf implementation, since all constructor arguments are passed into the list of allOf objects, there is a potential for an argument to not be succesful since it doesn't understand that type.

I suspect with the current allOf implementation, there is a side effect that all arguments/properties make there way to all allOf objects, as additionalTypes.

Is it possible that this type of constructor instantiation is not fesible, and possible only via deserialization?
For example, I also tried the following:

        tri = equilateral_triangle.EquilateralTriangle(triangle_type="EquilateralTriangle", shape_type="Triangle")
        tri["name"] = SpecialAttributes("something")

but this also failed with:

petstore_api.exceptions.ApiTypeError: Invalid type for variable 'name'. Required value type is one of [NoneType, bool, date, datetime, dict, float, int, list, str] and passed type was SpecialAttributes at ['name']

This is possibly a different issue, but I'm now unclear as to any workaround.

Since the composed object knows about each argument, shouldn't the composed object prune the argument list based on which allOf object it is passing the information to? It would introspect each allOf object and determine the arguments that intersect.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4