Skip to content

Commit

Permalink
fix: fix ext sort (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kooksee authored Dec 27, 2024
1 parent b7fecae commit 485adad
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,6 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr
op, path2 := g.buildOperationV3(
d, operationID, service.GoName, comment, defaultHost, path, body, inputMessage, outputMessage)

// Merge any `Operation` annotations with the current
extOperation := proto.GetExtension(method.Desc.Options(), v3.E_Operation)
if extOperation != nil {
proto.Merge(op, extOperation.(*v3.Operation))
}

// Merge any `Service` annotations with the current
if extService != nil {
op.Parameters = append(op.Parameters, extService.Parameters...)
Expand All @@ -778,6 +772,12 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr
proto.Merge(op.ExternalDocs, extService.ExternalDocs)
}
}

// Merge any `Operation` annotations with the current
extOperation := proto.GetExtension(method.Desc.Options(), v3.E_Operation)
if extOperation != nil {
proto.Merge(op, extOperation.(*v3.Operation))
}

for _, v := range op.Parameters {
if v.Oneof == nil {
Expand Down Expand Up @@ -811,6 +811,16 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr
tags = append(tags, v)
}

var extMap = make(map[string]*v3.NamedAny)
for _, v := range op.SpecificationExtension {
extMap[v.Name] = v
}

op.SpecificationExtension = op.SpecificationExtension[:0]
for _, v := range extMap {
op.SpecificationExtension = append(op.SpecificationExtension, v)
}

op.Tags = tags
g.addOperationToDocumentV3(d, op, path2, methodName)
}
Expand Down

0 comments on commit 485adad

Please sign in to comment.