[BUG] [SPRING] Generator do not respect reserved words mappings for FormParams
Created by: ahrytsiuk
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
There is an error in mustache template file modules/openapi-generator/src/main/resources/JavaSpring/formParams.mustache
that causes a compilation error if you use a reserved keyword as the name of a form parameter - baseName
is using instead of paramName
openapi-generator version
4.3.1 (latest stable release)
OpenAPI declaration file content or url
openapi: 3.0.2
info:
title: Example
description: Example
version: 1.0.0
paths:
/example/api:
post:
summary: summary
operationId: description
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
super:
type: string
format: binary
package:
type: string
format: binary
responses:
200:
description: response
Generation Details
@ApiOperation(value = "summary", nickname = "description", notes = "", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "response") })
@PostMapping(
value = "/example/api",
consumes = { "multipart/form-data" }
)
default ResponseEntity<Void> description(@ApiParam(value = "") @Valid @RequestPart(value = "super", required = false) MultipartFile super,@ApiParam(value = "") @Valid @RequestPart(value = "package", required = false) MultipartFile package) {
return getDelegate().description(_super, _package);
}
Which leads to a completion error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project open-api-reserved-words-mappings: Compilation failure: Compilation failure:
[ERROR] .../api/ExampleApi.java:[48,110] <identifier> expected
[ERROR] .../api/ExampleApi.java:[48,191] <identifier> expected
[ERROR] .../api/ExampleApi.java:[48,192] = expected
Steps to reproduce
- Generate code using maven plugin with the following configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<executions>
<execution>
<id>generate-sources</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<inputSpec>${project.basedir}/src/main/openapi/spec.yaml</inputSpec>
<generatorName>spring</generatorName>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<library>spring-boot</library>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Suggest a fix
paramName
should be used instead if baseName