Skip to content

Commit 778e7dd

Browse files
Making the linter happy
Ran `make lint` and resolved warnings/errors.
1 parent b68a614 commit 778e7dd

4 files changed

Lines changed: 22 additions & 12 deletions

File tree

internal/proto/buf/protoschema/test/v1/constraints.proto

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ message ConstraintTest {
4141

4242
message OneOfRequired {
4343
option (buf.validate.message).oneof = {
44-
fields: ["id", "name"],
44+
fields: [
45+
"id",
46+
"name"
47+
]
4548
required: true
4649
};
4750
string id = 1;
@@ -50,7 +53,10 @@ message ConstraintTest {
5053

5154
message OneOfOptional {
5255
option (buf.validate.message).oneof = {
53-
fields: ["id", "name"]
56+
fields: [
57+
"id",
58+
"name"
59+
]
5460
};
5561
string id = 1;
5662
string name = 2;

internal/protoschema/jsonschema/jsonschema.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package jsonschema
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"maps"
2021
"math"
@@ -270,7 +271,7 @@ func (p *Generator) generateMessage(entry *msgSchema) error {
270271
return err
271272
}
272273
if rules != nil {
273-
oneOfRules = append(oneOfRules, rules.Oneof...)
274+
oneOfRules = append(oneOfRules, rules.GetOneof()...)
274275
}
275276

276277
var required []string
@@ -349,7 +350,7 @@ func (p *Generator) fieldOneOfToMessageRule(field protoreflect.FieldDescriptor)
349350

350351
rule := validate.MessageOneofRule_builder{}
351352
rule.Fields = make([]string, fields.Len())
352-
for i := 0; i < fields.Len(); i++ {
353+
for i := range fields.Len() {
353354
rule.Fields[i] = string(fields.Get(i).Name())
354355
}
355356

@@ -372,12 +373,12 @@ func (p *Generator) addOneOfConstraintsToSchema(schema map[string]any, fieldProp
372373
if r, found := schema["required"]; found {
373374
rs, ok := r.([]string)
374375
if !ok {
375-
return fmt.Errorf("invalid required field in schema")
376+
return errors.New("invalid required field in schema")
376377
}
377378
required = rs
378379
}
379380

380-
var allOf []any
381+
allOf := make([]any, 0, len(rules))
381382
for _, rule := range rules {
382383
fields := rule.GetFields()
383384
properties := make([]string, 0, len(fields))
@@ -447,7 +448,11 @@ func (p *Generator) addOneOfConstraintsToSchema(schema map[string]any, fieldProp
447448
func (p *Generator) getFieldPropertyNames(
448449
field protoreflect.FieldDescriptor,
449450
hide bool,
450-
) (name string, aliases []string) {
451+
) (string, []string) {
452+
var (
453+
name string
454+
aliases []string
455+
)
451456
// TODO: Add an option to include custom alias.
452457
aliases = make([]string, 0, 1)
453458
if p.useJSONNames {
@@ -461,7 +466,7 @@ func (p *Generator) getFieldPropertyNames(
461466
if field.JSONName() != string(field.Name()) {
462467
aliases = append(aliases, string(field.Name()))
463468
}
464-
return
469+
return name, aliases
465470
}
466471

467472
// Add the proto name as the primary name.
@@ -474,7 +479,7 @@ func (p *Generator) getFieldPropertyNames(
474479
if field.JSONName() != string(field.Name()) {
475480
aliases = append(aliases, field.JSONName())
476481
}
477-
return
482+
return name, aliases
478483
}
479484

480485
func (p *Generator) setDescription(desc protoreflect.Descriptor, schema map[string]any) {

internal/protoschema/plugin/pluginjsonschema/pluginjsonschema_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ import (
2626
imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1"
2727
"github.com/bufbuild/buf/private/pkg/protoencoding"
2828
"github.com/bufbuild/protoplugin"
29+
_ "github.com/bufbuild/protoschema-plugins/internal/gen/proto/buf/protoschema/test/v1"
2930
"github.com/stretchr/testify/require"
3031
"google.golang.org/protobuf/encoding/protojson"
3132
"google.golang.org/protobuf/types/pluginpb"
32-
33-
_ "github.com/bufbuild/protoschema-plugins/internal/gen/proto/buf/protoschema/test/v1"
3433
)
3534

3635
func TestJSONSchemaHandler(t *testing.T) {

internal/testdata/codegenrequest/input.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)