DDK*_*DDK 9 java swagger openapi openapi-generator
我使用OpenAPI规范来生成 Java POJO。我需要在 Open API yaml 中指定什么才能生成以下 POJO 的等效项?
...
@JsonIgnore
public String ignoredProperty;
...
Run Code Online (Sandbox Code Playgroud)
我的 yaml 规范如下
openapi: 3.0.0
info:
title: Cool API
description: A Cool API spec
version: 0.0.1
servers:
- url: http://api.cool.com/v1
description: Cool server for testing
paths:
/
...
components:
schemas:
MyPojo:
type: object
properties:
id:
type: integer
name:
type: string
# I want the below attribute to be ignored as a part of JSON
ignoreProperty:
type: string
Run Code Online (Sandbox Code Playgroud)
支持openapi generator供应商扩展。具体来说,对于 Java 生成器,截至撰写本文时它支持以下扩展。不过,可以在此处找到最新列表。
| 扩展名 | 描述 | 适用于 | 默认值 |
|---|---|---|---|
| x 鉴别器值 | 与模型继承一起使用来指定标识当前模型的鉴别器的值 | 模型 | |
| x-工具 | 能够指定模型必须实现的接口 | 模型 | 空数组 |
| x-setter-额外注释 | 可以通过 java setter 为特定字段指定自定义注释 | 场地 | 当field为array & uniqueItems时,则使用此扩展来添加@JsonDeserialize(as = LinkedHashSet.class)setter,否则无值 |
| X标签 | 指定多个swagger标签进行操作 | 手术 | 无效的 |
| x-接受 | 为操作指定“Accept”标头的自定义值 | 手术 | 无效的 |
| x-内容类型 | 为操作指定“Content-Type”标头的自定义值 | 手术 | 无效的 |
| x 类额外注释 | 要添加到模型的自定义注释列表 | 模型 | 无效的 |
| x 字段额外注释 | 要添加到属性的自定义注释列表 | 场地 | 无效的 |
| x-webclient-阻止 | 指定特定操作的方法应该是阻塞还是非阻塞(例如:在生成的方法中返回Mono<T>/Flux<T>或return T/List<T>/Set<T>&执行).block() |
手术 | 错误的 |
您可以使用x-field-extra-annotation上面列出的供应商扩展向任何字段添加注释。因此,对于您的示例,您可以添加以下内容:
openapi: 3.0.0
info:
title: Cool API
description: A Cool API spec
version: 0.0.1
servers:
- url: http://api.cool.com/v1
description: Cool server for testing
paths:
/
...
components:
schemas:
MyPojo:
type: object
properties:
id:
type: integer
name:
type: string
# I want the below attribute to be ignored as a part of JSON
ignoreProperty:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonIgnore"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2586 次 |
| 最近记录: |