Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google.protobuf.Any generated OpenAPI v2 yaml that is potentially incorrect #4724

Open
veqryn opened this issue Sep 15, 2024 · 1 comment
Open

Comments

@veqryn
Copy link

veqryn commented Sep 15, 2024

🐛 Bug Report

I believe the generated OpenAPI v2 yaml for a google.protobuf.Any is incorrect.
This may also occur on other objects that use additionalProperties: {}

To Reproduce

  1. Have a proto file that includes a google.protobuf.Any somewhere
  2. Generate the OpenAPI v2 yaml
  3. Look at the OpenAPI v2 yaml, try generating OpenAPI client sdk's based on it.

Expected behavior

I expect the generated yaml to look like this:

  protobufAny:
    type: object
    properties:
      '@type':
        type: string
    additionalProperties: true

When turned into OpenAPI client sdk for golang, it would become something like this:

type ProtobufAny struct {
	Type *string `json:"@type"`
	AdditionalProperties map[string]any
}

Actual Behavior

  protobufAny:
    type: object
    properties:
      '@type':
        type: string
    additionalProperties: {}

I believe this is wrong, because additionalProperties: {} can either imply a second level map, or an object without fields. It should be additionalProperties: true

When turned into OpenAPI client sdk for golang, it becomes this:

type ProtobufAny struct {
	Type *string `json:"@type"`
	AdditionalProps map[string]struct{}
}

or

type ProtobufAny struct {
	Type *string `json:"@type"`
	AdditionalProperties map[string]map[string]interface{}
}

In both cases, the client fails on trying to unmarshal into this struct.

Your Environment

v2.22.0
Linux and Mac

@johanbrandhorst
Copy link
Collaborator

I don't really understand where the additionalProperties comes from in the first place, the any.proto definition doesn't have that field. In any case, if this is breaking you, I'd be happy to review a PR to fix it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants