OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-axios] Incorrect handling of property.title with unicode content in version 6.x.x

Open
#15,226 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

After updating to version 7 of generator, it can not longer generate code for enum union correctly.

I think it's based on incorrect usage of property "title" to generate type:

[main] INFO o.o.codegen.InlineModelResolver - Inline schema created as ______. To have complete control of the model name, set the title field or use the inlineSchemaNameMapping option (--inline-schema-name-mappings in CLI).

We have property with "title" set to unicode value (becouse it's supposed to be human-readable property name. We're using drf-spectacular to generate api schema from django-rest-framework, and it put field verbose name there.).

From version 6 openapi-generator tries to use it for generation of enum names, which leads to this error.

Diff of the generated code inv v5.x vs v6.x looks like this:

--- a/src/model/personal-info-account.ts
+++ b/src/model/personal-info-account.ts
@@ -13,8 +13,6 @@
  */


-import { BlankEnum } from './blank-enum';
-import { CountryEnum } from './country-enum';

 /**
  *
@@ -24,9 +22,9 @@ import { CountryEnum } from './country-enum';
 export interface PersonalInfoAccount {
     /**
      *
-     * @type {CountryEnum | BlankEnum}
+     * @type {}
      * @memberof PersonalInfoAccount
      */
-    'country'?: CountryEnum | BlankEnum;
+    'country'?: ;
 }

And it generated one additional file with empty name:

// cat src/model/.ts
// ...
// May contain unused imports in some cases
// @ts-ignore
import { BlankEnum } from './blank-enum';
// May contain unused imports in some cases
// @ts-ignore
import { CountryEnum } from './country-enum';

/**
 * @type
 * @export
 */
export type  = BlankEnum | CountryEnum;
openapi-generator version

6.5.0 (any 6.x.x)

This issue was not present in 5.4.0.

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  description: API Client
  title: App
  version: 1.0.0
paths:
  /account/personal_info/:
    get:
      operationId: account_personal_info_retrieve
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PersonalInfoAccount'
          description: ''
      security:
        - cookieAuth: []
        - basicAuth: []
      tags:
        - account
components:
  schemas:
    BlankEnum:
      enum:
      - ''
    CountryEnum:
      enum:
      - UA
      - US
      type: string
    PersonalInfoAccount:
      properties:
        country:
          title: Країна
          oneOf:
          - $ref: '#/components/schemas/CountryEnum'
          - $ref: '#/components/schemas/BlankEnum'
      type: object
Generation Details
openapi-generator-cli generate -i schema.yml -g typescript-axios -o src -p apiPackage=api,modelPackage=model,withSeparateModelsAndApi=true
Steps to reproduce
  1. Save schema to schema.yml
  2. Run openapi-generator
  3. Look at the invalid files:
  • src/model/.ts
  • src/model/personal-info-account.ts
Related issues/PRs

Not found.

Suggest a fix

title should not be used to generate enum name, becouse it's human-readable text and can contain unicode characters.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided openapi-generator-cli command with the schema.yml example and inspect the generated src/model/.ts and src/model/personal-info-account.ts files. Trace the typescript-axios generator's handling of the property title and inline enum naming, then confirm that Unicode titles no longer produce empty filenames or invalid TypeScript types.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.