Bypass Sanitizer or override it
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
Same here -- I'm using the typescript-rxjs generator and it is changing "-" in some of my property names to "_", which means that my models don't match the spec, which defeats the point of using open-api entirely.
I'm amazed that this isn't overrideable.
The relevant code appears to be here: https://github.com/OpenAPITools/openapi-generator/blob/783e68c7acbbdcbb2282d167d1644b069f12d486/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L6481