OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.78k stars 6.57k forks source link

[BUG][typescript-fetch] reserved word should not take into account response keys #19832

Open babariviere opened 3 weeks ago

babariviere commented 3 weeks ago

Bug Report Checklist

Description

When using a reserved word with typescript-fetch generator, the field will be prefixed with _ but it would not conflict with any types generated by openapi-generator.

openapi-generator version

7.9.0

OpenAPI declaration file content or url
openapi: "3.1.0"
info:
  title: OpenAPI Generator repro
  version: "1.0"
paths:
  /:
    get:
      responses:
        "200":
          content:
            application/json:
              schema:
                type: object
                properties:
                  configuration:
                    type: string
Generation Details
npm install -D @openapitools/openapi-generator-cli
npx openapi-generator-cli version-manager set 7.9.0
npx openapi-generator-cli generate -i openapi.yaml -g typescript-fetch --skip-validate-spec -o out --additional-properties=withoutRuntimeChecks=true
Steps to reproduce

If you reproduce the generation steps with the given schema, you will have in out/models/index.ts this interface:

export interface Get200Response {
    /**
     *
     * @type {string}
     * @memberof Get200Response
     */
    _configuration?: string;
}

I have provided a reproduction repo if needed: https://github.com/babariviere/openapi-generator-repro

Related issues/PRs

7474

Suggest a fix

Request / response fields should be ignored for reserved word. Mapping should be 1:1.

wing328 commented 3 weeks ago

did you try setting the modelPropertyNaming option to original ?

ref: https://openapi-generator.tech/docs/generators/typescript-fetch/

babariviere commented 3 weeks ago

@wing328 just tested it and the result is the same.

wing328 commented 3 weeks ago

what about using the nameMapping option?

https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#name-mapping

babariviere commented 3 weeks ago

Well yes it works... but shouldn't the default behavior to preserve the original property naming? This feels like a bug, I except my models to be the same as in my openapi when using minimal settings.