POST 方法是否在 openapi 3.0.2 中创建了一个新实体,并且 return 该实体的 ID?

Does a POST method create a new entity, and return the id of that entity, in openapi 3.0.2?

我知道 openapi 3.0.2 中的 POST 方法应该创建一个新实体,return 该实体的 ID。当我添加额外的路由以通过 ID 获取或删除该实体时,我收到 404 错误。我不太清楚为什么会这样。

这是我的 post 和获取方法:

/api/globalorderdays:
post:
  tags:
    - Setup Global Order Days
  summary: Allows user to add order days and holidays to multiple 
           sessions.
  requestBody:
    required: true
    description: put text here
    content:
      application/json:
        schema:
            $ref: '#/components/schemas/GlobalOrderSetupInfo'
  responses:
    201:
      description: Created
    400:
      description: Bad request
    401:
      description: Unauthorized

/api/globalorderdays/{Id}:
get:
  tags:
    - Setup Global Order Days
  summary: put text here
  parameters:
    - in: path
      name: Id
      required: true
      description: put text here
      schema:
        type: integer
        example:
  responses:
    200:
      description: Success
      content:
        application/json:
          schema:
              $ref: '#/components/schemas/GlobalOrderSetupInfo'
    400:
      description: Bad request
    401:
      description: Unauthorized

/api/globalorderdays/{Id}:
delete:
  tags:
    - Setup Global Order Days
  summary: Allows user to delete added order days
  parameters:
    - in: path
      name: Id
      required: true
      description: put text here
      schema:
        type: integer
        example:
  responses:
    204:
      description: Deleted
    400:
      description: Bad request
    401:
      description: Unauthorized

组件如下:

GlobalOrderSetupInfo:
  description: 'Put Text Here'
  type: object
  properties:
    Id:
      type: integer
      nullable: true
    AvailableHolidayList:
      type: string
      nullable: true
    SelectedOrderHolidays:
      type: string
      nullable: true
    SelectedHolidays:
      type: string
      nullable: true
    OrderDays:
      type: string
      nullable: true
    NoOrderDays:
      type: string
      nullable: true
    AllSessionList:
      uniqueItems: false
      type: array
      items:
        $ref: '#/components/schemas/SessionInfoList'
    SessionIdString:
      type: string
      nullable: true

SessionInfoList:
  description: 'Put Text Here'
  type: object
  properties:
    Id:
      type: integer
      nullable: true
    SessionID:
      type: integer
      nullable: true
    Name:
      type: string
      nullable: true
    Type:
      type: string
    GroupName:
      type: string
    IsChecked:
      type: boolean
      default: false
    SetupID:
      type: string
      nullable: true

我希望能够通过 Id retrieve/delete 实体,但我 return 404 错误

您的规格有几个问题。

  1. /api/globalorderdays/{Id}路径重复了几次。这是无效的。

    # Incorrect
    
    /api/globalorderdays/{Id}:
      get:
        ...
    
    /api/globalorderdays/{Id}:
      delete:
        ...
    

    相反,指定一次路径并在其下方列出其所有 HTTP 方法,如下所示:

    /api/globalorderdays/{Id}:
      get:
        ...
      delete:
        ...
    
  2. 参数示例缺少值:

    schema:
      type: integer
      example:   # <-----
    

    YAML 中的缺失值相当于 null,但 null 不是整数模式的有效示例。添加适当的整数示例,例如 example: 1,或从这些模式中删除 example 关键字。

解决这些问题后,GET 和 DELETE 的模拟将正常工作。