swagger-api/swagger-codegen

Enum for path type on parameter block causes erroneous code generation

Open

#5,479 opened on Apr 25, 2017

View on GitHub
 (2 comments) (0 reactions) (0 assignees)HTML (12,701 stars) (5,474 forks)batch import
Client: JavaFeature: EnumIssue: Bughelp wanted

Description

Description
Swagger-codegen version

2..2.2

Swagger declaration file content or url

Given the following block:

  /eventinfo/{item}:
    get:
      description: Get a list of event items.
      operationId: getEventInfo
      parameters:
        - name: item
          in: path
          required: true
          type: string
          **enum: [USERNAME, EVENTTYPE, ACTION, MODEL, PUBID, VERSION, CONTENTPID]**
      produces:
        - application/json
      responses:
        '200':
          description: Ok
          schema:
            $ref: '#/definitions/eventInfoList'
        '404':
          description: file not found
          schema:
            $ref: '#/definitions/errorModel'
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/errorModel'

Causes the following erroneous generated Java line: ResponseEntity getEventInfo(@ApiParam(value = "",required=true, allowableValues="{values=[USERNAME, EVENTTYPE, ACTION, MODEL, PUBID, VERSION, CONTENTPID], enumVars=[{name=USERNAME, value="USERNAME"}, {name=EVENTTYPE, value="EVENTTYPE"}, {name=ACTION, value="ACTION"}, {name=MODEL, value="MODEL"}, {name=PUBID, value="PUBID"}, {name=VERSION, value="VERSION"}, {name=CONTENTPID, value="CONTENTPID"}]}" ) @PathVariable("item") String item);

The additional quotes are around the value field are incorrect and cause compilation problems as shown:

[ERROR] src/gen/java/main/io/swagger/api/EventinfoApi.java:[32,208] ')' expected [ERROR] /src/gen/java/main/io/swagger/api/EventinfoApi.java:[32,216] expected [ERROR] src/gen/java/main/io/swagger/api/EventinfoApi.java:[32,244] ';' expected

Language type is "Spring" and I executed this via the maven plugin, so I'm hoping this is the correct area to place this in.

My plugin conf:

				<plugin>
					<groupId>io.swagger</groupId>
					<artifactId>swagger-codegen-maven-plugin</artifactId>
					<version>2.2.2</version>
					<executions>
						<execution>
							<phase>validate</phase>
							<goals>
								<goal>generate</goal>
							</goals>
							<configuration>
								<inputSpec>${project.basedir}/api.yaml</inputSpec>
								<language>spring</language>
								<output>${project.build.directory}/generated-sources</output>
								<configOptions>
									<generateApiTests>false</generateApiTests>
									<dateLibrary>joda</dateLibrary>
									<sourceFolder>src/gen/java/main</sourceFolder>
									<interfaceOnly>false</interfaceOnly>
									<library>spring-mvc</library>
								</configOptions>
							</configuration>
						</execution>
					</executions>
				</plugin>

A workaround is to generate a new type and refer to it there, however that is a little a bit of code clutter. Please advise if there is better workaround or I guess this is probably a bug.

Contributor guide

Enum for path type on parameter block causes erroneous code generation · swagger-api/swagger-codegen#5479 | Good First Issue