Skip to content

Whole-file $refs result in incorrect model names #3939

@matthewjamesadam

Description

@matthewjamesadam

Description

Summary

When an OpenAPI spec uses whole-file $refs (no URL fragment) to pull in external schemas, the bundler was naming them root, <Filename>_root, <Filename>_root_2, … instead of using the source filename. Downstream PascalCase turned these into Root, <Filename>Root, etc.

lastToken(entry.hash) returned the literal string "root" for empty hashes, and the bundling loop only consulted the filename-derived proposedBase as a collision suffix — so the bare name root always won. URL-fragment refs (./file.yml#/components/schemas/Foo) were unaffected.

Example

# root.yml
paths:
  /agents:
    get:
      responses:
        '200':
          content:
            application/json:
              schema: { $ref: './AgentType.yml' }   # whole-file ref
  /users:
    get:
      responses:
        '200':
          content:
            application/json:
              schema: { $ref: './UserType.yml' }    # whole-file ref

Before:

components:
  schemas:
    root:          { ... }   // AgentType
    UserType_root: { ... }   // UserType

After:

components:
  schemas:
    AgentType: { ... }
    UserType:  { ... }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions