最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to reproduce the inheritance behavior of allOf in Swagger using the OpenAPI 3.1 spec? - Stack Overflow

programmeradmin5浏览0评论

The Swagger documentation gives an example of how to implement model inheritance in OpenAPI:

components:
  schemas:
    BasicErrorModel:
      type: object
      required:
        - message
        - code
      properties:
        message:
          type: string
        code:
          type: integer
          minimum: 100
          maximum: 600
    ExtendedErrorModel:
      allOf: # Combines the BasicErrorModel and the inline model
        - $ref: "#/components/schemas/BasicErrorModel"
        - type: object
          required:
            - rootCause
          properties:
            rootCause:
              type: string

When using the 3.0 version of the OpenAPI specification, this works as intended, and the ExtendedErrorModel has all properties of both the base and derived object:

Switching to the 3.1 version of the specification (supported in the "next" web editor), however, breaks this example, treating the siblings as separate and leaving the ref as text:

Is this expected behavior given the semantic changes in the 3.1 spec? If so, is there a replacement for the mechanism?

发布评论

评论列表(0)

  1. 暂无评论