[BUG][typescript-fetch] Name clash between models and operations
Created by: haraldF
Description
Imagine a Model:
SubscribeRequest:
type: object
properties:
# ...
and an operation called subscribe:
paths:
/subscriptions:
post:
summary: Subscribe
operationId: subscribe
parameters:
# ...
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SubscribeRequest'
required: true
The generated TypeScript operation would import SubscribeRequest
but also generate a class called SubscribeRequest
in the same file, which leads to a compilation error:
import {
SubscribeRequest,
SubscribeRequestFromJSON,
SubscribeRequestToJSON,
} from '../models';
// ...
// ERROR - SubscribeRequest name already taken
export interface SubscribeRequest {
// ...
}
openapi-generator version
Today's master (but also happens with latest released version)
Suggest a fix
One "naive" fix would be to simply escape all models that end with Request
:
@Override
public String toModelName(final String name) {
String modelName = super.toModelName(name);
if (modelName.endsWith("Request") && !modelName.startsWith("Model")) {
modelName = "Model" + modelName;
}
return modelName;
}