我举个例子:
openapi: 3.0.3
info:
title: My App
version: 1.0.0
tags:
- name: Order
description: "Order endpoints"
paths:
/api/v0/order:
post:
tags:
- Order
summary: 'Create Order'
operationId: createOrder
requestBody:
content:
'application/json':
schema:
$ref: '#/components/schemas/Order'
required: true
responses:
200:
description: OK
content:
'application/json':
schema:
$ref: '#/components/schemas/SuccessMessage'
400:
description: Error
content:
'application/json':
schema:
$ref: '#/components/schemas/ErrorMessage'
components:
schemas:
Order:
type: object
properties:
name:
type: string
description:
type: string
type:
type: string
SuccessMessage:
type: object
properties:
code:
type: string
message:
type: string
ErrorMessage:
type: object
properties:
code:
type: string
message:
type: array
items:
type: string
我正在使用Open API Generator来生成代码,但这一个生成的代码如下所示:
@Operation(
operationId = "createOrder",
summary = "Create Order",
tags = { "Order" },
responses = {
@ApiResponse(responseCode = "200", description = "OK", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = SuccessMessage.class))
}),
@ApiResponse(responseCode = "400", description = "Error", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorMessage.class))
})
}
)
@RequestMapping(
method = RequestMethod.POST,
value = "/api/v0/order",
produces = { "application/json" },
consumes = { "application/json" }
)
default ResponseEntity<SuccessMessage> createOrder(
@Parameter(name = "Order", description = "", required = true) @Valid @RequestBody Order order
) {
return getDelegate().createOrder(order);
}
正如你所看到的,我有这个default ResponseEntity<SuccessMessage> createOrder
,但我的目标是使用泛型类型,而不是像这样:
default ResponseEntity<?> createOrder
有没有办法告诉OpenApiGenerator生成ResponseEntity<?>
而不是ResponseEntity<SuccessMessage>
,我知道有一个解决方案是使用mustache,但也许有其他的解决方案。
插件
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.0.0-beta</version>
<configuration>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<configOptions>
<dateLibrary>java8</dateLibrary>
<serializableModel>true</serializableModel>
<openApiNullable>false</openApiNullable>
</configOptions>
</configuration>
<executions>
<execution>
<id>catalog_api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/specs/order_api_v1.yml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-boot</library>
<apiPackage>com.order.api</apiPackage>
<modelPackage>com.order.model</modelPackage>
<supportingFilesToGenerate>
ApiUtil.java
</supportingFilesToGenerate>
<configOptions>
<useTags>true</useTags>
<useBeanValidation>true</useBeanValidation>
<returnSuccessCode>true</returnSuccessCode>
<delegatePattern>true</delegatePattern>
<implicitHeaders>true</implicitHeaders>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
1条答案
按热度按时间bz4sfanl1#
我正在使用这个版本的开放API,它对我来说很好,你想实现什么,希望这个帮助-
Pom.xml
控制器代码-
把这个给予-