cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Precedence and/or logic when using nested allOf and anyOf #148

Closed jurgenf closed 3 years ago

jurgenf commented 3 years ago

Given the following OpenApi property defintion:

PropertyName:
    type: array
    items:
      allOf:
        - $ref: [basic implementation].yaml
        - anyOf:
            - $ref: [concrete implementation 1].yaml
            - $ref: [concrete implementation 2].yaml

I expect this to mean: all items have to adhere to definition [basic implementation] and any of the referenced concrete implementations.

The generated model has the following typehint:

PropertyName: Array<BasicImplementation & ConcreteImplementation1 | ConcreteImplementation2>;

Given that the & operator precedes the | operator this is interpreted as:

PropertyName: Array<(BasicImplementation & ConcreteImplementation1) | ConcreteImplementation2>;

But I would expect this to be:

PropertyName: Array<BasicImplementation & (ConcreteImplementation1 | ConcreteImplementation2)>;

I suspect the generated code is incorrect and the or parts should be parenthesized. Or is my understanding of the usage of the allOf/anyOf incorrect?

luisfpg commented 3 years ago

This is a duplicate of #111. The mentioned PR includes tentative fix for #109, which is way more complex. That's why it wasn't merged. Any help is welcome.