swagger-api / swagger-api/swagger-codegen
[Typescript-Fetch] - Default Configuration Class conflicts with Generated Class of same name
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The default Configuration class that is used to pass in parameters to setup API security is the same name as a generated classes from the Swagger file. This class is created in the configuration.mustache template but is then used in the api.mustache template.
Swagger-codegen version
2.4.0
Swagger declaration file content or url
{
"swagger": "2.0",
"info": {
"version": "3.0.0",
"title": "Service API"
},
"host": "a.host.com",
"basePath": "/apis/3.0",
"paths":{
"/service/tickets/{id}/configurations": {
"post": {
"tags": [
"Tickets"
],
"description": "Create Configuration Association",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "id",
"type": "integer",
"format": "int32",
"in": "path",
"required": true
},
{
"name": "configuration",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ConfigurationReference"
}
}
],
}
}
},
"definitions": {
"ConfigurationReference": {
"type": "object",
"properties": {
"id": {
"format": "int32",
"type": "integer"
},
"deviceIdentifier": {
"type": "string"
},
"_info": {
"$ref": "#/definitions/Metadata",
"description": "Metadata of the entity",
"readOnly": true
}
}
}
}
}
Command line used for generation
generate -i test.json -l typescript-fetch -o out/
Steps to reproduce
Generate the code and you should get warnings in the IDE about the generated class(es).
Suggest a fix/enhancement
Allow a command line option that gives you the ability to name the Configuration class to something of your choice to avoid conflict with any classes generated from your Swagger definition. If nothing is passed in, use the default class named Configuration.
But if you did something like this:
generate -i test.json -l typescript-fetch -o out/ --additional-properties apiConfigClassName=ApiConfiguration, then the generated class name would be ApiConfiguration.
This change would also use Mustache Lamda expressions to Lower and Upper case class names automatically so as to stick to standard naming conventions.
Finally, FWIW, I've already complete the core coding for this suggested change and can submit a pull request if you think there is value in this. While this change is only specific to the typescript-fetch client, it should probably be enacted across the board for all clients where the Configuration class is being automatically added. That's beyond the scope of what I need out of this at the moment, but thought I would mention it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the typescript-fetch configuration.mustache and api.mustache templates, then trace how additional-properties are passed during generate. Verify the generated output with the supplied Swagger definition and command; done means a configurable API configuration class name avoids conflicts while the default remains Configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100