[英]Generate code from OpenAPI spec including examples and descriptions
Suppose I have an OpenAPI spec .yaml
file with the following properties:假设我有一个具有以下属性的 OpenAPI 规范.yaml
文件:
....
My_Model:
description: 'Model to do some work'
type: object
....
When I generate it to Kotlin code, using openapi-generator , it is adding the description into Javadoc part:当我使用openapi-generator将其生成为 Kotlin 代码时,它会将描述添加到 Javadoc 部分:
/**
* Model to do some work
*/
data class MyModel(
....
What I want from generator is to add the description into swagger annotation also (or only ):我想从生成器中将描述添加到 swagger 注释中(或仅):
....
@Schema(description = "Model to do some work")
data class MyModel(
....
Is there any setting or another generator library/software supporting this?是否有任何设置或其他生成器库/软件支持此功能? The same case is true not only for description, but also for examples.相同的情况不仅适用于描述,而且适用于示例。 Need to work for fields too.也需要为领域工作。
Yes, you can use @Schema
annotation in a class level and a property level:是的,您可以在 class 级别和属性级别中使用@Schema
注释:
@Schema(name = "MyDto", description = "MyDto Model")
class MyDto {
@Schema(description = "Prop Description", example = "Prop Example")
var prop: String? = null
@Schema(description = "Text Description", example = "Text Example")
var text: String? = null
@Schema(description = "Something Description", example = "Something Example")
var something: String? = null
}
springdoc-openapi-kotlin
: springdoc-openapi-kotlin
依赖关系:Using Gradle:使用 Gradle:
implementation("org.springdoc:springdoc-openapi-kotlin:1.5.9")
Using Maven:使用 Maven:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-kotlin</artifactId>
<version>1.5.9</version>
</dependency>
How to document a Kotlin/Spring application with Springdoc and OpenAI:如何使用 Springdoc 和 OpenAI 记录 Kotlin/Spring 应用程序:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.