我有以下OpenApi规范:
paths:
/student:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Student"
responses:
204:
components:
schemas:
Student:
type: object
properties:
name:
type: string
school:
type: string
通过org.openapitools.generator,它生成了一个具有功能的控制器,类似下方的
void addStudent(@RequestBody Student student) {
}
有没有任何方法可以将生成器配置为将@RequestBody生成为String?
void addStudent(@RequestBody String student) {
}
我认为您需要在OpenAPI中将响应设置为text/plain
和schema: type: string
。
除此之外,您可以在OpenAPI中保留Student
模式,生成器应该将其生成为java类。
paths:
/ping:
get:
responses:
'200':
description: OK
content:
text/plain:
schema:
type: string
example: pong
请阅读此处的官方文档。