我正在尝试生成一个将枚举作为查询参数的服务,但它一直在生成错误。 这是 yaml 的部分:
name: language
in: query
description: language
schema:
type: string
enum:
- en
- de
我在参数中使用它:
- $ref: '#/components/parameters/language'
我得到的错误是:
[ERROR] .../api/TestApi.java:[110,65] illegal start of type
[ERROR] .../api/TestApi.java:[110,66] ')' expected
[ERROR] .../api/TestApi.java:[110,82] ';' expected
代码如下:
public Response getByLanguage( @PathParam("id") Long id, , allowableValues="en, de" @QueryParam("language") String language
这是我的插件:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.0.1</version>
<configuration>
<inputSpec>${basedir}/src/main/resources/openapi.yaml</inputSpec>
<output>${project.build.directory}/generated-sources/java</output>
<generatorName>jaxrs-resteasy-eap</generatorName>
<modelPackage>com.openapi.example.model</modelPackage>
<apiPackage>com.openapi.example.api</apiPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<sourceFolder>openapi</sourceFolder>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<java8>true</java8>
<serializableModel>true</serializableModel>
<useTags>true</useTags>
<performBeanValidation>true</performBeanValidation>
<useBeanValidation>true</useBeanValidation>
</configOptions>
</configuration>
<executions>
<execution>
<phase>generate-resources</phase>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
我设法让它工作的唯一方法是将它作为一个枚举值数组,但这不是我在这里需要的。
编辑: 我在项目中定义的依赖项:
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-analyzer</artifactId>
<version>1.11.1</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.11.3</version>
</dependency>
答案 0 :(得分:0)
试试下面的演示 yaml。
枚举应定义为枚举:[en, de]。
openapi: 3.0.2
info: {title: Demo Info., description: Demo Description., version: 1.0.0}
servers:
- {url: 'https://something.com', description: Demo Description.}
paths:
/something:
post:
tags: [Something]
requestBody:
required: true
content:
application/json:
schema: {$ref: '#/components/schemas/SomethingRequest'}
parameters:
- {$ref: '#/components/parameters/language'}
responses:
200:
description: OK
content:
application/json:
schema: {$ref: '#/components/schemas/SomethingResponse'}
components:
parameters:
language:
name: language
schema:
type: string
enum: [en, de]
default: en
in: query
schemas:
SomethingRequest:
properties:
demo: {type: string}
SomethingResponse:
properties:
demo: {type: string}