首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在openapi 3.0.2中格式化DELETE方法?

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

Stack Overflow用户
提问于 2019-06-18 05:26:29
回答 1查看 4.7K关注 0票数 1

我想不出一种方法来为我刚刚在API设计中创建的POST方法创建一个DELETE方法。帖子接受GlobalOrderSetupInfo的requestBody,在该对象中有另一个对象,它将是我想要添加GlobalOrderSetupInfo信息的不同会话的数组,在delete方法中,我需要删除相同的信息,但您不能使用带有requestBody的delete方法。我该如何创建它?

下面是我的post方法:

代码语言:javascript
运行
复制
'/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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-18 05:56:35

通常,POST方法会创建一个新实体,并返回该实体的id。然后,您可能有额外的路由来通过ID获取该实体,更新(修补)或删除它。

因此,在您的示例中,DELETE条目可能如下所示:

代码语言:javascript
运行
复制
'/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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56639119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档