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

Fix field order in yaml generated OAS file #3084

Merged
merged 1 commit into from Dec 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions protoc-gen-openapiv2/internal/genopenapi/types.go
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor"
"gopkg.in/yaml.v3"
)

type param struct {
Expand Down Expand Up @@ -259,13 +260,23 @@ type keyVal struct {
type openapiSchemaObjectProperties []keyVal

func (p openapiSchemaObjectProperties) MarshalYAML() (interface{}, error) {
m := make(map[string]interface{}, len(p))

for _, v := range p {
m[v.Key] = v.Value
n := yaml.Node{
Kind: yaml.MappingNode,
Content: make([]*yaml.Node, len(p)*2),
}

return m, nil
for i, v := range p {
keyNode := yaml.Node{}
if err := keyNode.Encode(v.Key); err != nil {
return nil, err
}
valueNode := yaml.Node{}
if err := valueNode.Encode(v.Value); err != nil {
return nil, err
}
n.Content[i*2+0] = &keyNode
n.Content[i*2+1] = &valueNode
}
return n, nil
}

func (op openapiSchemaObjectProperties) MarshalJSON() ([]byte, error) {
Expand Down