OpenAPITools/openapi-generator

[BUG][typescript-fetch] Any schema overlaps with the type of another property of the same name.

uruha opened this issue · 1 comments

uruha commented

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

If the schemas have Hoge and Fuga and the property in Fuga has hoge, then this Fuga > hoge is characteristic only if the title name is the same as Hoge and lowercase hoge (case sensitive). Hoge properties overlap with Fuga > hoge properties for generated Models.

openapi-generator version

3.0.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
components:
  schemas:
    Hoge:
      type: object
      properties:
        hogeid:
          type: integer
          format: int64
          title: id
        hogename:
          type: string
          title: name
    Fuga:
      type: object
      properties:
        fugaid:
          type: integer
          format: int64
          example: 1
          title: id
        fuganame:
          type: string
          example: Laptop
          title: name
        hoge:
          title: hoge
          type: object
          properties:
            id:
              type: integer
              format: int64
              example: 1
              title: id
            name:
              type: string
              example: Laptop
              title: name
          required:
          - id
          - name
      required:
      - hoge
paths:
  /hoge:
    get:
      description: hoge
      responses:
        '200':
          description: hoge
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Hoge'
  /fuga:
    get:
      description: fuga
      responses:
        '200':
          description: fuga
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Fuga'
Generation Details

This report is node.js execution environment.

node.js: v14.15.0
@openapitools/openapi-generator-cli: ^2.1.5

The symptom is that Hoge's properties should be hogeid and hogename, but they are replaced by Fuga's hoge property type (id, name).

// Hoge.ts
/**
 * 
 * @export
 * @interface Hoge
 */
export interface Hoge {
    /**
     * 
     * @type {number}
     * @memberof Hoge
     */
    id: number; // Oops... Fuga's hoge property overlap it...
    /**
     * 
     * @type {string}
     * @memberof Hoge
     */
    name: string;
}
// Fuga.ts
import {
    Hoge,
    HogeFromJSON,
    HogeFromJSONTyped,
    HogeToJSON,
} from './';

/**
 * 
 * @export
 * @interface Fuga
 */
export interface Fuga {
    /**
     * 
     * @type {number}
     * @memberof Fuga
     */
    fugaid?: number;
    /**
     * 
     * @type {string}
     * @memberof Fuga
     */
    fuganame?: string;
    /**
     * 
     * @type {Hoge}
     * @memberof Fuga
     */
    hoge: Hoge; // The reference is Hoge, but the contents match with the properties of Fuga> hoge.
}

This can be fixed by removing the title or renaming the title to something other than hoge.
ex) If you try to change the title of Fuga> hoge to upper camel case.

Fuga:
    #...
    hoge:
        title: Hoge # <= I made it into an upper camel case
        type: object
        properties:
        id:
            type: integer
            format: int64
            example: 1
            title: id
        name:
            type: string
            example: Laptop
            title: name
        required:
        - id
        - name

Result is ...

// Hoge.ts
/**
 * 
 * @export
 * @interface Hoge
 */
export interface Hoge {
    /**
     * 
     * @type {number}
     * @memberof Hoge
     */
    hogeid?: number;
    /**
     * 
     * @type {string}
     * @memberof Hoge
     */
    hogename?: string;
}
// Fuga.ts
import {
    Hoge1,
    Hoge1FromJSON,
    Hoge1FromJSONTyped,
    Hoge1ToJSON,
} from './';

/**
 * 
 * @export
 * @interface Fuga
 */
export interface Fuga {
    /**
     * 
     * @type {number}
     * @memberof Fuga
     */
    fugaid?: number;
    /**
     * 
     * @type {string}
     * @memberof Fuga
     */
    fuganame?: string;
    /**
     * 
     * @type {Hoge1}
     * @memberof Fuga
     */
    hoge: Hoge1;
}
// Fuga's hoge model type file.
/**
 * 
 * @export
 * @interface Hoge1
 */
export interface Hoge1 {
    /**
     * 
     * @type {number}
     * @memberof Hoge1
     */
    id: number;
    /**
     * 
     * @type {string}
     * @memberof Hoge1
     */
    name: string;
}
Steps to reproduce

Use CLI for

$ openapi-generator-cli generate -g typescript-fetch -i sample.yaml -o ./sample/yaml --additional-properties=typescriptThreePlus=true,modelPropertyNaming=original
Related issues/PRs

I looked for it but couldn't find it 🥺.

Suggest a fix

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.