如何在openapi 3.0.2中格式化DELETE方法?

时间:2019-06-17 21:26:28

标签: api swagger openapi

我在想办法为API设计中刚创建的POST方法创建DELETE方法时遇到了麻烦。该帖子采用了GlobalOrderSetupInfo的requestBody,在该对象中有另一个对象,该对象将是我要将GlobalOrderSetupInfo信息添加到其中的不同会话的数组,在delete方法中,我需要删除相同的信息,但是不能带有requestBody的delete方法。我该如何创建它?

这是我的发布方法:

'/api/globalorderdays':
post:
  tags:
    - Setup Global Order Days
  summary: Allows user to add orderdays to multiple sessions
  requestBody:
    required: true
    description: put text here
    content:
      application/json:
        schema:
          type: object
          items:
            $ref: '#/components/schemas/GlobalOrderSetupInfo'
  responses:
    '201':
      description: Created
    '400':
      description: Bad request
    '401':
      description: Unauthorized
components:
schemas:
GlobalOrderSetupInfo:
  description: 'Put Text Here'
  type: object
  properties:
    Id:
      type: integer
    AvailableHolidayList:
      type: string
    SelectedOrderHolidays:
      type: string
      example: "New Year's Day, President's Day, Memorial Day, Labor Day, Veterans Day, Thanksgiving Day, Chistmas Day"
    SelectedHolidays:
      type: string
      example: "New Year's Day, President's Day, Memorial Day, Labor Day, Veterans Day, Thanksgiving Day, Chistmas Day"
    OrderDays:
      type: string
      example: "01/01/2000"
    NoOrderDays:
      type: string
      example: "01/01/2000"
    AllSessionList:
      uniqueItems: false
      type: array
      items:
        $ref: '#/components/schemas/SessionInfoList'
    SessionIdString:
      type: string
      example: "15"

SessionInfoList:
  description: 'Put Text Here'
  type: object
  properties:
    Id:
      type: integer
    SessionID:
      type: integer
    Name:
      type: string
      example: "Harbor"
    Type:
      type: string
    GroupName:
      type: string
      example: "PHACTS"
    IsChecked:
      type: boolean
      default: false
      example: true/false
    SetupID:
      type: string

1 个答案:

答案 0 :(得分:1)

通常,您的POST方法创建一个新实体,并返回该实体的ID。然后,您可能还有其他路由,可以通过ID获取,更新(PATCH)或删除该实体。

因此在您的示例中,DELETE的条目可能类似于:

'/api/globalorderdays/{id}':
  parameters:
    - in: path
      name: id
      required: true
      schema:
        type: integer
  get:
    summary: Get orderdays by id
    responses:
      '200':
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GlobalOrderSetupInfo'
  delete:
    summary: Delete orderdays by id
    responses:
      '204':
        description: Deleted
      '404':
        description: id not found
      '401':
        description: Unauthorized