C# 如何在OpenAPI规范3.0中添加allof类型?

C# 如何在OpenAPI规范3.0中添加allof类型?,c#,swagger,api-design,openapi,C#,Swagger,Api Design,Openapi,我们遵循设计优先的方法来创建API 我们想要使用继承的场景之一,我无法为它定义规范 这是它的C类型 public class PublishRequest { [JsonProperty("notificationType")] public string NotificationType { get; set; } [JsonProperty("source")] public string Source { get;

我们遵循设计优先的方法来创建API

我们想要使用继承的场景之一,我无法为它定义规范

这是它的C类型

public class PublishRequest
    {

        [JsonProperty("notificationType")]
        public string NotificationType { get; set; }

        [JsonProperty("source")]
        public string Source { get; set; }

        [JsonProperty("timestamp")]
        public string Timestamp { get; set; }

        [JsonProperty("payload")]
        public List<BaseObject> Payload { get; set; }
    }
所有进一步的类型都继承自此类型,如下所示:

public class Accounts:BaseObject
    {
        [JsonProperty("phone")]
        public string Phone { get; set; }
        [JsonProperty("accountid")]
        public string AccountID { get; set; }
        [JsonProperty("name")]
        public string Name { get; set; }
        [JsonProperty("legalname")]
        public string LegalName { get; set; }
        [JsonProperty("website")]
        public string Website { get; set; }
        [JsonProperty("linkedin")]
        public string LinkedIn { get; set; }
        [JsonProperty("twitter")]
        public string Twitter { get; set; }
    }
使用这些类的规范如下:

/notification/publish:
    post:
      summary: publish notification
      tags:
        - Notification
      requestBody:
        description: publish request body
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublishRequest'
      responses:
        "200":
          description: success message
我面临的问题是如何定义它的模式

架构看起来像这样

PublishRequest:
      required:
        - notificationType
      properties:
        notificationType:
          type: string 
          enum: [account_created, account_updated]
        source:
          type: string 
          enum: [A, B]
        timestamp:
          type: string 
          format: date-time          
        payload: 
          $ref: "#/components/schemas/NotificationPayload"

    NotificationPayload:
      type: array
      items:
        oneOf:
          - $ref: "#/components/schemas/Account"        

    BaseObject:
      properties:
        Id:
          type: string
    Account:
     allOf:    
      $ref: '#/components/schemas/BaseObject'
      type: object
      properties:
        phone:
          type: string
        accountId:
          type: string
        name:
          type: string
        legalname:
          type: string  
        website:
          type: string
        linkedin:
          type: string
        twitter:
          type: string
        facebook:
          type: string
        defaultcurrency:
          type: string 
我一直在大摇大摆地编辑中发现这个错误

Structural error at components.schemas.Account.allOf
should be array
allOf的正确语法如下所示。allOf接受子模式的列表,因此每个子模式必须在YAML中以-作为前缀

账户: 所有: -$ref:'/components/schemas/BaseObject' -类型:对象 特性: 电话: 类型:字符串 ... 还有几件事:

在NotificationPayload中,项不需要其中之一,因为只有一个子模式

通知有效载荷: 类型:数组 项目: $ref:/components/schemas/Account 记住将type:object添加到对象模式中,在本例中为PublishRequest和BaseObject。properties关键字本身不足以指示对象类型,实际上表示任何类型


您是手动编写规范还是使用Swashback/Swagger Net从代码生成规范?@Helen Mannaly
Structural error at components.schemas.Account.allOf
should be array