Skip to content

feat(parser): allow duplicate paths with different HTTP methods#1592

Merged
ernado merged 1 commit intoogen-go:mainfrom
lanej:feature/allow-duplicate-paths-different-methods-clean
Nov 30, 2025
Merged

feat(parser): allow duplicate paths with different HTTP methods#1592
ernado merged 1 commit intoogen-go:mainfrom
lanej:feature/allow-duplicate-paths-different-methods-clean

Conversation

@lanej
Copy link
Contributor

@lanej lanej commented Nov 29, 2025

Summary

Adds a new parser setting to allow duplicate normalized paths when they use different HTTP methods, resolving issues with real-world OpenAPI specs that technically violate the specification but can be safely handled.

Fixes #1590

Changes

  • Add DisallowDuplicateMethodPaths setting (default: false for lenient mode)
  • Allow duplicate paths when HTTP methods don't overlap
  • Always reject same-method conflicts (e.g., two GETs on same path)
  • Expose setting via gen.ParseOptions for YAML/JSON configuration

API Example

# Previously errored, now allowed by default:
paths:
  /pets/{petId}:
    get: ...      # GET /pets/:param
  /pets/{id}:
    post: ...     # POST /pets/:param (different method, different param name)

# Still rejected (same method conflict):
paths:
  /pets/{petId}:
    get: ...
  /pets/{id}:
    get: ...      # ERROR: duplicate GET

# Strict mode (opt-in):
parser_settings:
  disallow_duplicate_method_paths: true  # Rejects all duplicates

Testing

  • 3 parser unit tests: allow different methods, reject same method, strict mode
  • 1 generator integration test validating end-to-end behavior
  • All existing tests pass

Notes

Breaking Change: None - default behavior is lenient (allows different-method duplicates). Users wanting strict validation can opt-in via configuration.

Add DisallowDuplicateMethodPaths setting to control path duplication
behavior. When false (default), paths that normalize identically are
allowed if they use different HTTP methods. This enables specs with
paths like /pets/{petId} GET and /pets/{id} POST to coexist.

When true, the parser maintains strict mode and rejects all duplicate
normalized paths regardless of HTTP method. Paths with overlapping
methods (e.g., /pets/{petId} GET and /pets/{id} GET) are always
rejected to prevent routing ambiguity.

Implementation adds method tracking to parsePathItems() with helpers
getPathMethods() and methodsOverlap(). The setting is exposed through
gen.ParseOptions for YAML/JSON configuration.

Fixes ogen-go#1590
@ernado ernado merged commit 0cbd33b into ogen-go:main Nov 30, 2025
15 checks passed
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

Successfully merging this pull request may close these issues.

feat(parser): allow duplicate paths when HTTP methods differ

2 participants