Skip to content

Conversation

@rohitlohar45
Copy link
Contributor

Fixes #5799

References to other Issues or PRs

Have you read the Contributing Guidelines?

Yes

Brief description of what is fixed or changed

Prevents unnecessary package prefixes in OpenAPI definition names when using package or simple naming strategies.

Problem: The generator was adding package prefixes (e.g., foo.Foo) even when no actual naming collision existed in the generated spec. This happened because collision detection used ALL messages from the registry, including unreferenced imports.

Solution: Filter the name set before collision detection to only include:

  • All names from the current package
  • Names from other packages that are actually referenced in the spec
  • Standard google.* packages

This ensures only real collisions trigger prefixes while maintaining backward compatibility.

Example:

// foo.proto - references other.Other but NOT other.Foo
message Foo {
  other.Other other = 1;
}

Before: "definitions": { "foo.Foo": {...} }
After: "definitions": { "Foo": {...} }

Other comments

  • All existing tests pass
  • No breaking changes - only affects cases with phantom collisions from unreferenced imports
  • Tested with the reproduction case from the issue

@rohitlohar45
Copy link
Contributor Author

@johanbrandhorst can you have a look at this?

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the delay here, this looks great, thank you! Do you think you could add an example of this scenario happening to one of our existing example protobuf files, so that we can see the change this triggered? Thank you.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, meant to request changes.

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.

protoc-gen-openapiv2: Unnecessary package prefixes in definitions when no actual collision exists

2 participants