-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Description
We are using 2 java classes in our code: SystemDto, and SystemDTO (different casing in the class suffix, Dto vs DTO). The former is local from the current project while the latter is an external dependency.
I noticed that only one class is generated with one class overwriting the other.

Notice that a file JsonSystemDTO is generated with the class name as JsonSystemDto
In this scenario, I believe that swagger codegen is resolving the files in a case insensitive manner and overwriting each other.
Swagger-codegen version
Using swagger-codegen-maven-plugin version: 2.4.10
Maven Plugin config
<!-- maven plugin to support the swagger code generation project -->
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${swagger-codegen-maven-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.outputDirectory}/static/apidocs/ui/swagger.json</inputSpec>
<language>java</language>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<output>${project.build.outputDirectory}/generated-sources/swagger</output>
<groupId>com.company.router</groupId>
<artifactId>company-router-sdk</artifactId>
<artifactVersion>6.5.0-SNAPSHOT</artifactVersion>
<modelPackage>com.company.router.sdk.model</modelPackage>
<apiPackage>com.company.router.sdk.api</apiPackage>
<invokerPackage>com.company.router.sdk</invokerPackage>
<variableNamingConvention>camelCase</variableNamingConvention>
<serializableModel>true</serializableModel>
<fullJavaUtil>true</fullJavaUtil>
<library>resteasy</library>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>Command line used for generation
Since this is attached to our build, code was generated using mvn clean install
Suggest a fix/enhancement
I am not entirely sure since I have not debugged the project, but I noticed that io.swagger.codegen.DefaultCodegen has code which capitalizes model names, and api names. This can cause the following map below to have the same map key:
io.swagger.codegen.DefaultGenerator.java line 385
Model model = definitions.get(name);
Map<String, Model> modelMap = new HashMap<String, Model>();
modelMap.put(name, model);
Map<String, Object> models = processModels(config, modelMap, definitions);
if (models != null) {
models.put("classname", config.toModelName(name));
models.putAll(config.additionalProperties());
allProcessedModels.put(name, models);
}io.swagger.codegen.DefaultCodegen
/**
* Output the API (class) name (capitalized) ending with "Api"
* Return DefaultApi if name is empty
*
* @param name the name of the Api
* @return capitalized Api name ending with "Api"
*/
public String toApiName(String name) {
if (name.length() == 0) {
return "DefaultApi";
}
return initialCaps(name) + "Api";
}
/**
* Output the proper model name (capitalized).
* In case the name belongs to the TypeSystem it won't be renamed.
*
* @param name the name of the model
* @return capitalized model name
*/
public String toModelName(final String name) {
return initialCaps(modelNamePrefix + name + modelNameSuffix);
}It may or may not be related.