swagger-api / swagger-api/swagger-codegen

[typescript-angular] model name matches existing language type

Open
#9,491 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I've coded this documentation annotations:

@ApiResponses(value = {
    @ApiResponse(code=HttpStatus.SC_CONFLICT, response = ResponseError.class),
	@ApiResponse(code=HttpStatus.SC_UNAUTHORIZED, response = ResponseError.class),
	@ApiResponse(code=HttpStatus.SC_BAD_REQUEST, response = ResponseError.class),
	@ApiResponse(code=HttpStatus.SC_INTERNAL_SERVER_ERROR, response = ResponseError.class)
})
public ResponseEntity<User> addUser(

As you can see it's returning an ResponseError class. ResponseError is third-party class I'm not able to change and it looks like:

package cat.gencat.ctti.canigo.arch.web.rs.response;
public class ResponseError {
    private java.util.List<cat.gencat.ctti.canigo.arch.web.rs.model.Error> errors;

I'm using maven swagger-codegen-maven-plugin plugin in order to generate my TypeScript model classes.

Currently, I'm getting this warning message:

Error (model name matches existing language type) cannot be used as a model name. Renamed to ModelError

As far I've been able to figure out, it's renaming cat.gencat.ctti.canigo.arch.web.rs.model.Error class to ModelError.

So, an modelError.ts class code is generated:

export interface ModelError {
    code?: number;
    message?: string;
}

However, if I take a look on generated responseError.ts class, it's using an Error class yet.

export interface ResponseError {
    errors?: Array<Error>;
}

Any ideas?

Swagger-codegen version

swagger-codegen-maven-plugin 2.3.1

Command line used for generation

mvn clean compile

 <plugin>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-codegen-maven-plugin</artifactId>
			<version>2.4.5</version>
			<executions>
				<execution>
					<phase>compile</phase>
					<goals>
						<goal>generate</goal>
					</goals>
					<configuration>
<inputSpec>${project.basedir}/src/main/swagger/swagger.json</inputSpec>
						<language>typescript-angular</language>
						<generateSupportingFiles>false</generateSupportingFiles>
						<generateApis>false</generateApis>
						<generateModels>true</generateModels>
						<configHelp>false</configHelp>
					<output>${project.basedir}/src/gen/typescript/main</output>
						<configOptions>
	<sourceFolder>${project.basedir}/src/gen/typescript/main</sourceFolder>
						</configOptions>
						<import-mappings>
							<param>Error=ModelError</param>
						</import-mappings>
					</configuration>
				</execution>
			</executions>
		</plugin>

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 with the Maven plugin configuration and compare the generated modelError.ts and responseError.ts files shown in the report. Trace how the typescript-angular generator resolves the Error model name and its references, then regenerate the models to verify that responseError.ts uses the renamed model consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.