首页 > 解决方案 > 我的 oppproduct 中的 Swagger-YAML 错误映射条目

问题描述

我的路径有问题。我得到的错误是下面的检查图像。我尝试了社区成员@Helen Paths指出的链接,但没有运气。请帮帮我。谢谢,达科

  /opportunity/{opportunityid}/oppproduct/{oppproductid}:
get:
  tags:
  - "Opportunity"
  summary: "Get opp product id for certain opportunity"
  description: "This endpoint displays opp product details"
  produces:
  - "application/json"
  parameters:
  - name: "opportunityid"
    in: "path"
    description: "This is unique identifier of specific opportunity"
    required: true
    type: "string"
  - name: "oppproductid"
    in: "path"
    description: "This is unique identifier of specific opp product in specific opportunity "
    required: true
    type: "string"
  responses:
    200:
      description: "successful operation"
      schema:
        type: "array"
        items:
          $ref: "#/definitions/opportunity"
    400:
      description: "Invalid status value"
put:
  tags:
  - "Opportunity"
  summary: "Update opportunity product from specific opportunity"
  description: "Update this opportunity product."
  operationId: "updateOppProduct"
  produces:
  - "application/json"
  parameters:
  - name: "opportunityid"
    in: "path"
    description: "Opportunity product with id that need to be updated"
    required: true
    type: "string"
  responses:
    400:
      description: "Invalid Opportunity product supplied"
    404:
      description: "Opportunity product not found"

我得到的错误。 在此处输入图像描述

标签: apiyamlswagger

解决方案


1)“重复的映射键”错误表明您在其中一个参数中有重复的键,特别是两个name键。你只需要一个name

      parameters:
      - name: "opportunityid"  # <---------
        in: "path"
        description: "Opportunity product with id that need to be updated"
        required: true
        type: "string"
        name: "oppproductid"  # <---------

2)另一个错误是由schema路径参数中的关键字引起的:

  - in: "path"
    description: "Updated Opp product object"
    type: "string"   # <--- This is the correct way to specify the param type in OAS 2.0
    required: true
    schema:    # <--------- Remove this
        type: integer

你不需要schema这里。在 OpenAPI 2.0 中,路径、查询和标头参数type直接使用,无需schema关键字。


推荐阅读