Skip to content
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

allOf ignored when the property is used on its own #4146

Open
smasala opened this issue Oct 14, 2019 · 3 comments
Open

allOf ignored when the property is used on its own #4146

smasala opened this issue Oct 14, 2019 · 3 comments

Comments

@smasala
Copy link
Contributor

smasala commented Oct 14, 2019

Description

#3771 (v4.1.2) breaks code generation (TypeScript) when a model only defines a single allOf/$ref and no other properties.

Example

MyModel:
      description: a model
      allOf:
        - $ref: '#/components/schemas/MyOtherModel'

Generated output

import { SomeImportPropertyType } from './propModel';    // this is correct

/**
 * MyModel
 */
export interface MyModel { 
    // properties from {MyOtherModel} are missing
}
export namespace MyModel {
}

@wing328 I assume this is what you meant could happen by your comment #3771 (comment)

openapi-generator version

latest

@wing328
Copy link
Member

wing328 commented Oct 15, 2019

@smasala right looks like we need an option for different use cases.

@ohing504
Copy link

We have the same problem. If the model has allOf with a single subschema, the generated interface is incorrect in typescript-angular (but correct in typescript-node).

I think allOf with single subschema is not normal way. But, we want to keep same format for shared schemas that may be added later.

  • Example schema
components:
  schemas:

    Sample:
      type: object
      properties:
        name:
          type: string

    AllOfTestWithSingleRef:
      allOf:
        - $ref: "#/components/schemas/Sample"

    OneOfTestWithSingleRef:
      oneOf:
        - $ref: "#/components/schemas/Sample"

After generate to typescript-angular and typescript-node,

  • AllOfTestWithSingleRef

    • typescript-node generated correctly
      import { Sample } from './sample';
      
      export class AllOfTestWithSingleRef extends Sample {
      
        static discriminator: string | undefined = undefined;
      
        static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
        ];
      
        static getAttributeTypeMap() {
            return super.getAttributeTypeMap().concat(AllOfTestWithSingleRef.attributeTypeMap);
        }
      }
      
    • In typescript-angular, AllOfTestWithSingleRef has empty body
      import { Sample } from './sample';
      
      
      export interface AllOfTestWithSingleRef { 
      }
      
  • OneOfTestWithSingleRef

    • typescript-node generated correctly
      import { Sample } from './sample';
      
      export class OneOfTestWithSingleRef extends Sample {
      
          static discriminator: string | undefined = undefined;
      
          static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
          ];
      
          static getAttributeTypeMap() {
              return super.getAttributeTypeMap().concat(OneOfTestWithSingleRef.attributeTypeMap);
          }
      }
      
    • In typescript-angular also generated correctly
      import { Sample } from './sample';
      
      /**
      * @type OneOfTestWithSingleRef
      * @export
      */
      export type OneOfTestWithSingleRef = Sample;
      

@amakhrov
Copy link
Contributor

Perhaps a duplicate of #4770 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants