Redocly / redocly-cli

⚒️ Redocly CLI makes OpenAPI easy. Lint/validate to any standard, generate beautiful docs, and more.
https://redocly.com/docs/cli/
MIT License
934 stars 146 forks source link

Ambiguity Validation #1767

Open Kousik1612 opened 1 month ago

Kousik1612 commented 1 month ago

Describe the bug A clear and concise description of what the bug is. I have defined two paths which gets differed by HTTP Method and path parameter. /xyz/{id}/features - POST and /xyz/{id_or_wildcard}/features - GET

Expected behavior A clear and concise description of what you expected to happen. There should not be any error reported as both these API(s) is intended to perform different behaviour as one is POST and other one is GET.

Minimal reproducible OpenAPI snippet(if possible)

'/xyz/{id}/features':
    $merge:
    - $exposure: [public, internal]
      $merge:
      - $ref: '#/components/x-abstract-paths/base'
      - $ref: '#/components/x-abstract-paths/collectionsPost'
'/xyz/{id_or_wildcard}/features':
    $merge:
    - $exposure: [public, internal]
      $merge:
      - $ref: '#/components/x-abstract-paths/base'
      - $ref: '#/components/x-abstract-paths/collectionsGet'

Screenshots If applicable, add screenshots to help explain your problem.

Validating build (redocly lint) ...

    ╔═══════════════════════════════════════════════════════╗
    ║                                                       ║
    ║  A new version of Redocly CLI (1.23.1) is available.  ║
    ║  Update now: `npm i -g @redocly/cli@latest`.          ║
    ║  Changelog: https://redocly.com/docs/cli/changelog/   ║
    ║                                                       ║
    ╚═══════════════════════════════════════════════════════╝

(node:3126) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
validating s/spec/openapi.json...
[1] ../builds/spec/openapi.json:57273:5 at #/paths/~1xyz~1{id}~1features

The path already exists which differs only by path parameter name(s): `/xyz/{id_or_wildcard}/features` and `/xyz/{id}/features`.

57271 |   }
57272 | },
57273 | "/xyz/{id}/features": {
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57274 |   "parameters": [
57275 |     {

Error was generated by the no-identical-paths rule.

[2] ../builds/spec/openapi.json:57273:5 at #/paths/~1xyz~1{id}~1features

Paths should resolve unambiguously. Found two ambiguous paths: `/xyz/{id_or_wildcard}/features` and `/xyz/{id}/features`.

57271 |   }
57272 | },
57273 | "/xyz/{id}/features": {
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57274 |   "parameters": [
57275 |     {

Error was generated by the no-ambiguous-paths rule.

s/spec/openapi.json: validated in 393ms

❌ Validation failed with 2 errors.
run `redocly lint --generate-ignore-file` to add all problems to the ignore file.

/bin/sh: npm: command not found
ERROR: Failed to validate spec

Additional context Add any other context about the problem here.

tatomyr commented 2 weeks ago

There should not be any error reported as both these API(s) is intended to perform different behaviour as one is POST and other one is GET.

Are you trying to run the lint command? As the linter tells, both paths are the same, so their operations should be grouped under one of them (and the second should be removed). If you still want your description to remain the same, you can turn off the no-ambiguous-paths rule in the Redocly config file.