swagger-tools icon indicating copy to clipboard operation
swagger-tools copied to clipboard

Parameters with the same name but different types are valid.

Open mohsen1 opened this issue 9 years ago • 16 comments

This specs is valid:


---
swagger: '2.0'
info:
  version: 0.0.0
  title: Simple API
paths:
  /{email}:
    parameters:
      - name: email
        in: path
        type: string
    get:
      parameters:
        - name: email
          in: query
          type: string
      responses:
        200:
          description: OK

From https://github.com/swagger-api/swagger-ui/issues/828#issuecomment-83150803

mohsen1 avatar Mar 18 '15 23:03 mohsen1

I assume it's being flagged as not valid? I agree it should be valid although I wonder how we'll handle this on the middleware side of things. req.swagger.params can only have one email entry.

whitlockjc avatar Mar 19 '15 00:03 whitlockjc

Again, I'd love to hear from @webron. I do think technically this is valid but from a tooling perspective, it would not be easy to support.

whitlockjc avatar May 21 '15 15:05 whitlockjc

Unfortunately, for 2.0, this is valid.

webron avatar May 26 '15 19:05 webron

I can work with it. I'll likely do a first come, first served approach and print warnings as there is no way I'm sure to handle this that doesn't end up with a crappy user experience.

whitlockjc avatar May 26 '15 19:05 whitlockjc

In which case is this validation error correct?

mortias avatar Jul 02 '15 17:07 mortias

I never said the validation error was correct, that's why this bug is still open. :)

whitlockjc avatar Jul 02 '15 18:07 whitlockjc

But as I said above, from a tooling perspective things are a little more tricky. Right now, we use req.swagger.params.{paramName} to get access to a parameter's schema, raw value and processed value. If you have two different parameters with the same name, this no longer works. That's why this issue is still open is because it should be valid but the fix for this is not simply just turning off the validation as it changes the interface.

whitlockjc avatar Jul 02 '15 18:07 whitlockjc

@whitlockjc Thanks for explaining the problem. I dont know much about the code, but how about using req.swagger.params.{paramName+paramType} instead of req.swagger.params.{paramName}? How big a change will that be?

nikhiljindal avatar Nov 30 '15 23:11 nikhiljindal

For 1.0.0, that's likely what will happen.

whitlockjc avatar Dec 01 '15 00:12 whitlockjc

@whitlockjc Whats the timeline for 1.0.0?

nikhiljindal avatar Dec 01 '15 19:12 nikhiljindal

Not sure, this project isn't getting the same attention these days due to my involvement in other things. I'd love any help I can get but this project is by no means dead...just a little slower than it use to be.

whitlockjc avatar Dec 01 '15 21:12 whitlockjc

I just ran into this as well. For backwards-compatibility I'm accepting the same parameter as query or as form parameter. Is there a fix and/or workaround for this at the moment?

theigl avatar Apr 13 '16 08:04 theigl

I don't see me fixing this in swagger-tools. This would be a huge rewrite of everything and we're already in the process of splitting swagger-tools into smaller, specific projects (#335). Sway already supports this but the middleware isn't completed yet.

whitlockjc avatar Apr 13 '16 15:04 whitlockjc

Any updates on this? i have a large codebase where swagger tools never complained about this and all of a sudden it started throwing errors.

Is there a workaround or any tips to avoid this issue?

sido420 avatar Feb 16 '18 02:02 sido420

I'm not getting any errors in 0.10.1. However, 0.10.2/3 throw following errors. However, I dont have any name conflicts.

#/paths/~1list/put/parameters/1/name: Parameter already defined: undefined
#/paths/~1list/put/parameters/2/name: Parameter already defined: undefined
#/paths/~1list/post/parameters/1/name: Parameter already defined: undefined

sido420 avatar Feb 16 '18 03:02 sido420

The error message is suspect, as in undefined, shouldn't be there. Do you have a reproduction recipe?

whitlockjc avatar Feb 16 '18 19:02 whitlockjc