Skip to content

Commit

Permalink
fix: test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ccheers committed Mar 4, 2025
1 parent 0cea4b2 commit 3602bc2
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 52 deletions.
16 changes: 16 additions & 0 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,13 +849,29 @@ func schemaOfField(f *descriptor.Field, reg *descriptor.Registry, refs refMap) o
}
}

ret.Required = arrayUniq(ret.Required)

if reg.GetProto3OptionalNullable() && f.GetProto3Optional() {
ret.XNullable = true
}

return ret
}

func arrayUniq[T comparable](array []T) []T {
seen := make(map[T]struct{})
j := 0
for _, v := range array {
if _, ok := seen[v]; ok {
continue
}
seen[v] = struct{}{}
array[j] = v
j++
}
return array[:j]
}

// primitiveSchema returns a pair of "Type" and "Format" in JSON Schema for
// the given primitive field type.
// The last return parameter is true iff the field type is actually primitive.
Expand Down
Loading

0 comments on commit 3602bc2

Please sign in to comment.