请告诉我这是我第一次编写 openApi 文档并从中生成代码。 几乎一切都按我的计划进行,但我可以在响应中替换一个示例,该示例返回字符串类型。 这是我的端点描述的示例:
/getDictionaries:
get:
tags:
- Dictionaries
description: extrep_mdm.spk_get_rf_mrf_citizens
operationId: getSpkDictionary
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: string
examples:
someExample:
$ref: '#/components/examples/myExample'
这是示例的一个组成部分:
components:
examples:
myExample:
summary: Test
value: 'test'
如果我查看 swageer-editor,那么一切看起来都是正确的,并且示例已填写: 但是当我在应用程序中生成代码时,示例不会受到阻碍: 因此,swagger 界面没有任何变化:
由此我得出结论,我没有正确配置 openapi-generator-maven-plugin,以下是我的配置方式:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.6.0</version>
<executions>
<execution>
<id>generate-rest-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatorName>spring</generatorName>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<apiPackage>org.example.swagger.controller</apiPackage>
<modelPackage>org.example.swagger.model</modelPackage>
<generateSupportingFiles>true</generateSupportingFiles>
<generateApiDocumentation>true</generateApiDocumentation>
<generateApis>true</generateApis>
<generateModels>true</generateModels>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8-localdatetime</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
但我就是不知道错误在哪里,请告诉我
OpenAPI 生成器不支持响应中的
examples
(复数):
https://github.com/OpenAPITools/openapi-generator/issues/16051
一个可能的解决方法是更新您的响应定义以使用单个
example
。注意这个example
必须是内联值并且不能使用$refs。
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: string
example: 'test' # Response-level example
或
# schema-level example
content:
application/json:
schema:
type: string
example: 'test'
根据OpenAPI - 描述响应文档,该示例属于响应模式:
paths:
/ping:
get:
responses:
'200':
description: OK
content:
text/plain:
schema:
type: string
example: pong
据此,您的情况应该如下:
get:
tags:
- Dictionaries
description: extrep_mdm.spk_get_rf_mrf_citizens
operationId: getSpkDictionary
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: string
example:
"$ref": '#/components/examples/myExample'