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

Support reserved chars in path params

Open derSascha opened this issue 3 years ago • 3 comments

Description

Add allowReserved to path parameter to support reserved characters like the query parameter already does. Default stays the same.

See allowReserved in the parameter documentation: https://swagger.io/specification/#parameter-object

Motivation and Context

We are using URL's with reserved characters like an asterix in the path: http://example.com/items/*1234abcd Swagger always encode this characters.

How Has This Been Tested?

New test case added.

Screenshots (if appropriate):

Types of changes

  • [ ] No code changes (changes to documentation, CI, metadata, etc)
  • [ ] Dependency changes (any modification to dependencies in package.json)
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x] My code follows the code style of this project.
  • [x] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I have added tests to cover my changes.
  • [x] All new and existing tests passed.

derSascha avatar Jun 30 '22 12:06 derSascha

The OpenAPI Specification contains a line that needs an update: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md?plain=1#L1036 Is this the documentation file that needs to be updated?

derSascha avatar Jun 30 '22 12:06 derSascha

Hi @derSascha,

THanks for contributing. We're looking into your PR now.

The OpenAPI Specification contains a line that needs an update: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md?plain=1#L1036 Is this the documentation file that needs to be updated?

Nope, this repo is just one of the implementations of client library for the OpenAPI 3.0.x. You have to submit your specification change in https://github.com/OAI/OpenAPI-Specification.

char0n avatar Aug 05 '22 07:08 char0n

According to the OpenAPI 3.0.3 specification, the allowReserver says following:

This property only applies to parameters with an `in` value of `query`. The default value is `false`.

image

This means that when in value is path, this parameter get's always encoded. IMHO behavior of swagger-js is now compliant with the spec and your PR is going outside of the spec and introducing behavior that is unspecified.


Getting back to your example: http://example.com/items/*1234abcd

Swagger-js turns your url into: http://example.com/items/%2A1234abcd. Can you do url decoding at you server code? You should probably do it anyway as people may request your url in encoded fashion.

char0n avatar Aug 05 '22 08:08 char0n

I'm closing this for now as there's been no follow up from the @derSascha.

char0n avatar Sep 19 '22 11:09 char0n