Skip to content

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

@lanej

Description

@lanej

Problem

When an OpenAPI spec contains paths that normalize to the same structure but have different parameter names and different HTTP methods, ogen errors with "duplicate path":

paths:
  /pets/{petId}:
    get:
      # no operationId
  /pets/{id}:
    post:
      # no operationId

Per OpenAPI spec, templated paths with the same hierarchy but different parameter names are technically invalid. However, these specs exist in the wild and could be handled gracefully when the HTTP methods differ.

Proposed Solution

Add a parser setting AllowDuplicatePathsWithDifferentMethods (enabled by default) that:

  1. Relaxes the duplicate path check when paths have different HTTP methods
  2. Allows the generator's existing naming logic to disambiguate operations using path.String() (which includes parameter names) + method

Example generated names:

  • GET /pets/{petId}GetPetsPetId
  • POST /pets/{id}PostPetsId

Behavior

  • Default (enabled): Duplicate paths with different methods are allowed; operations are disambiguated by path + params + method
  • Disabled: Current strict behavior; duplicate paths always error

Notes

  • Same method on duplicate paths remains an error (true conflict)
  • This is a parsing-level change with minimal generator impact

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions