Skip to content

Cannot have multiple operations with the same operationId #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
indrekots opened this issue Jan 2, 2017 · 2 comments
Closed

Cannot have multiple operations with the same operationId #1146

indrekots opened this issue Jan 2, 2017 · 2 comments

Comments

@indrekots
Copy link

Swagger File

swagger: "2.0"
info:
  version: "0.0.1"
  title: Test API
host: localhost:3000
basePath: /api
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /users:
    x-swagger-router-controller: users
    post:
      operationId: create
      parameters:
        - name: body
          in: body
          required: true
          schema:
            $ref: '#/definitions/User'
      responses:
        "200":
          description: Success
          schema:
            $ref: "#/definitions/User"
  /posts:
    x-swagger-router-controller: posts
    post:
      operationId: create
      parameters:
        - name: body
          in: body
          required: true
          schema:
            $ref: '#/definitions/Post'
      responses:
        "200":
          description: Success
          schema:
            $ref: "#/definitions/Post"
definitions:
  User:
    title: User
    type: object
    properties:
      username:
        type: string
      email:
        type: string
  Post:
    title: Post
    type: object
    properties:
      title:
        type: string
      content:
        type: string
  • Browser/OS: Chromium 53.0.2785.143 and FF50 on Ubuntu 14.04

Issue

Came across the following issue. I have defined two paths and post operations for both of them. Although the operationIds are identical, x-swagger-router-controller values are different. Swagger Editor tells me that I have an error on line 31 Cannot have multiple operations with the same operationId: create. The swagger file above can be used to reproduce the issue.

code: "DUPLICATE_OPERATIONID"
message: "Cannot have multiple operations with the same operationId: create"
path: Array [4]
level: 900
type: "Swagger Error"
description: "Cannot have multiple operations with the same operationId: create"
lineNumber: 31 

When I run swagger project verify from the command-line, everything seems to be fine.

Please feel free to correct me (since I might be missing some important details) but shouldn't this swagger file be valid in the editor? These operations are handled by different controllers and there cannot be a name collision.

@fehguy
Copy link
Contributor

fehguy commented Jan 2, 2017

The error message you're getting is per the swagger specification, not the implementation. See here, the operationId is expected to be unique across the document.

@indrekots
Copy link
Author

Thank you for the quick answer. I should better follow the specification then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants