openapi:重用简单属性定义

azpvetkf  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(180)

我试图在一个地方定义一些简单的属性,以便在其他一些复杂对象中重用它们。
考虑以下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*` 上课?请帮助我理解我做错了什么。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题