OpenAPITools / OpenAPITools/openapi-generator

Bypass Sanitizer or override it

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

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

hi, everyone, i'm using openapi-generator for generate TS services and models

I m using Symfony 4 with Doctrine and API Platform to build the backend of my application. I generated entities using php bin/console make:entity. Each class has an id field like this one

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass=CategoryRepository::class)
 */
class Category
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;
    ...

I generated the api doc file php bin/console api:openapi:export --output=swagger.json Then I use OpenAPI Generator to generate the client part for the frontend npx openapi-generator-cli generate -i swagger.json -g typescript-angular --enable-post-process-file -o build The resulting model file categoryJsonld.ts containes 2 id fields

 export interface CategoryJsonld { 
    readonly context?: string | any | null;
    readonly id?: string;
    readonly type?: string;
   id?: number;
    ... 

I found why

because of the sanitazer in AbstractTypeScriptClientCodegen.java

name = sanitizeName(name, "[^\\w$]");

Solution ?

i we can add a parameter to bypass this sanitize or to override it that would be great !

example :

--additional-properties=notSanitize =true

output

 export interface CategoryJsonld { 
    readonly context?: string | any | null;
    readonly '@id'?: string;
    readonly type?: string;
    id?: number;
    ... 

i found a topic related !#13999
best regard,
Pierre

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 in AbstractTypeScriptClientCodegen.java at the sanitizeName call, then reproduce the issue with the api:openapi:export and typescript-angular generation commands shown. Done means the generated categoryJsonld.ts preserves the '@id' property without producing the conflicting duplicate id field, with the requested override or bypass behavior covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, php, symfony, typescript
Domain
api, tooling
Issue type
Feature
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.