如何解决Openapi:重用简单的属性定义
我试图在一个地方定义一些简单的属性,以便在其他一些复杂的对象中重用它们。
考虑遵循 openapi 架构定义:
event:
type: object
properties:
creationTime:
description: The date and time when the event was created.
type: string
format: date-time
example: '2020-03-19T12:16:31.586Z'
id:
allOf:
- $ref: '#/components/x-descriptions/event_id'
- example: '20200301'
self:
allOf:
- $ref: '#/components/x-descriptions/desc_self'
- example: 'https://<TENANT_DOMAIN>/event/events/20200301'
source:
allOf:
- $ref: '#/components/x-descriptions/event_source'
- properties:
id:
allOf:
- $ref: '#/components/x-descriptions/desc_objectId'
- example: '251982'
text:
schema:
type: string
$ref: '#/components/x-descriptions/event_text'
example: Location update.
time:
allOf:
- $ref: '#/components/x-descriptions/event_time'
- example: '2020-03-19T00:00:00.000Z'
type:
allOf:
- $ref: '#/components/x-descriptions/event_type'
- example: k8s_LocationUpdate
和简单类型定义:
event_source:
description: The managed object to which the event is associated.
type: object
event_type:
description: Identifies the type of this event.
type: string
event_text:
description: Description of the event.
type: string
event_id:
description: Unique identifier of the event.
type: string
event_time:
description: The date and time when the event is updated.
type: string
format: date-time
event_creationTime:
description: The date and time when the event was created.
type: string
format: date-time
但它生成如下代码:
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen",date = "2020-12-29T09:41:12.786550+01:00[Europe/Warsaw]")
public class Event {
@JsonProperty("creationTime")
private OffsetDateTime creationTime = null;
@JsonProperty("id")
private AllOfeventId id = null;
@JsonProperty("self")
private AllOfeventSelf self = null;
@JsonProperty("source")
private AllOfeventSource source = null;
@JsonProperty("text")
private ComponentsxDescriptionseventText text = null;
@JsonProperty("time")
private AllOfeventTime time = null;
@JsonProperty("type")
private AllOfeventType type = null;
self
和 type
应该只是字符串,time
应该只是 LocalDateTime
如何避免那些 AllOf*
和 ComponentsxDescriptions*
类?
请帮助我理解我做错了什么。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。