3

I want to represent 2 paths in my OpenAPI / Swagger definition:

  • /resourceA/{id} where id is an integer
  • /resourceA/{name} where name is a string

Both paths leads to the same result: retrieve a resourceA instance but using a different primary key.

With the following Swagger definition: swagger: '2.0'

info:
  version: 1.0.0
  title: Template  API
  description: Template management

paths:
  /resourceA/{id}:
    get:
      parameters:
        - name: id
          in: path
          type: integer
          required: true
      responses:
        200:
          description: OK
  /resourceA/{name}:
    get:
      parameters:
        - name: name
          in: path
          type: string
          required: true
      responses:
        200:
          description: OK

There is a lot of repetition between the two definitions, since they represent the same endpoint, just with a different path parameter name/type.

Also, swagger editor is not happy with this definition and I get the following error:

 Swagger Error
Equivalent path already exists: /resourceA/{name}
Jump to line 19
Details
 Object
code:  "EQUIVALENT_PATH"
message:  "Equivalent path already exists: /resourceA/{name}"
 path: Array [2]
level: 900
type:  "Swagger Error"
description:  "Equivalent path already exists: /resourceA/{name}"
lineNumber: 19

How could I represent this to reduce the repetition to the minimum?

arnaud.breton
  • 2,054
  • 1
  • 24
  • 39

0 Answers0