OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-fetch] Special characters in `paramName` are left out in generated client / interfaces

Open
#15,261 0 comments 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?
    Generated interfaces should contain special characters to match the spec file.
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I’m using typescript-fetch to auto-generate a client and facing an issue:
The API I’m working with returns a field called @type (including the @-sign). However, this is not correctly reflected in the generated interface.
I would like to open up a PR to fix this issue. Any suggestions to tackle the problem? Simply wrapping quotes around the props of the interface? Or is there a setting I’m missing here?

Bildschirmfoto 2023-04-19 um 11 03 38
openapi-generator version

6.3.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: DemoAPI
  termsOfService: http://swagger.io/terms/
  version: 0.0.1
servers:
  - url: https://sandboxapi.demo.com
    description: Sandbox
    
paths:
  /ring:
    get:
      tags:
        - ring
      summary: Get the ring
      operationId: getRing
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Ring'

    
components:
  schemas:
    Ring:
      description: A closed loop consisting of a set of points in a two-dimensional space.
      type: object
      properties:
        "@type": 
          type: string
          example: Ring
        type: 
          type: string
          example: exterior
          description: Specifies whether the ring is an exterior or interior boundary of a polygon.
        passable: 
          type: boolean
          description: Specifies whether the ring can be crossed or not.
Generation Details
java -jar ".../node_modules/@openapitools/openapi-generator-cli/versions/6.3.0.jar" generate --input-spec="./schema/swagger.yaml" --generator-name="typescript-fetch" --output="./.generated/" --additional-properties="supportsES6=true,withInterfaces=true"
Steps to reproduce
  1. Use the OpenAPI CLI to generate an API client
  2. Open up the generated files afterwards.
Related issues/PRs
Suggest a fix

I'd like to provide pull request that fixed the issue. However, I'm not completely sure how to tackle this.
We could escape special characters in property names by wrapping quotes around them, but I'd like to hear other opinions on this first.

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 CLI command with schema/swagger.yaml and the typescript-fetch generator. Inspect the generated interfaces for the Ring schema, especially the @type property, and compare them with the OpenAPI declaration. Done means generated TypeScript interfaces preserve special-character property names while remaining valid for the specified client output.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.