diff --git a/internal/cmd/jsonschema-generate-testdata/main.go b/internal/cmd/jsonschema-generate-testdata/main.go index 402eb43..d009dee 100644 --- a/internal/cmd/jsonschema-generate-testdata/main.go +++ b/internal/cmd/jsonschema-generate-testdata/main.go @@ -64,7 +64,7 @@ func run() error { return errors.New("expected $id to be non-empty") } filePath := filepath.Join(outputDir, identifier) - if err := golden.GenerateGolden(filePath, string(data)); err != nil { + if err := golden.GenerateGolden(filePath, string(data)+"\n"); err != nil { return err } } diff --git a/internal/protoschema/jsonschema/jsonschema.go b/internal/protoschema/jsonschema/jsonschema.go index 2dd77bc..ef32ba2 100644 --- a/internal/protoschema/jsonschema/jsonschema.go +++ b/internal/protoschema/jsonschema/jsonschema.go @@ -147,7 +147,7 @@ func generateTitle(name protoreflect.Name) string { var result strings.Builder for i, chr := range name { isUpper := unicode.IsUpper(chr) - nextIsUpper := i+1 < len(name) && unicode.IsUpper(rune(name[i+1])) + nextIsUpper := i+1 >= len(name) || unicode.IsUpper(rune(name[i+1])) if i > 0 && isUpper && !nextIsUpper { result.WriteRune(' ') } diff --git a/internal/protoschema/jsonschema/jsonschema_test.go b/internal/protoschema/jsonschema/jsonschema_test.go index d06a9aa..cf81f49 100644 --- a/internal/protoschema/jsonschema/jsonschema_test.go +++ b/internal/protoschema/jsonschema/jsonschema_test.go @@ -37,7 +37,7 @@ func TestJSONSchemaGolden(t *testing.T) { require.NotEmpty(t, identifier) filePath := filepath.Join(dirPath, identifier) - err = golden.CheckGolden(filePath, string(data)) + err = golden.CheckGolden(filePath, string(data)+"\n") require.NoError(t, err) } } @@ -52,4 +52,5 @@ func TestTitle(t *testing.T) { require.Equal(t, "FOO Bar", generateTitle("FOOBar")) require.Equal(t, "U Int64 Value", generateTitle("UInt64Value")) require.Equal(t, "Uint64 Value", generateTitle("Uint64Value")) + require.Equal(t, "FOO", generateTitle("FOO")) } diff --git a/internal/protoschema/plugin/pluginjsonschema/pluginjsonschema.go b/internal/protoschema/plugin/pluginjsonschema/pluginjsonschema.go index 9f77fa1..bdefc0c 100644 --- a/internal/protoschema/plugin/pluginjsonschema/pluginjsonschema.go +++ b/internal/protoschema/plugin/pluginjsonschema/pluginjsonschema.go @@ -56,7 +56,7 @@ func Handle( } responseWriter.AddFile( identifier, - string(data), + string(data)+"\n", ) seenIdentifiers[identifier] = true } diff --git a/internal/testdata/jsonschema/buf.protoschema.test.v1.BigQueryWellknownTypeTest.schema.json b/internal/testdata/jsonschema/buf.protoschema.test.v1.BigQueryWellknownTypeTest.schema.json index 5f2ee50..a7c2c4d 100644 --- a/internal/testdata/jsonschema/buf.protoschema.test.v1.BigQueryWellknownTypeTest.schema.json +++ b/internal/testdata/jsonschema/buf.protoschema.test.v1.BigQueryWellknownTypeTest.schema.json @@ -9,4 +9,4 @@ }, "title": "Big Query Wellknown Type Test", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomBigQuery.schema.json b/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomBigQuery.schema.json index a23b60c..64d27e0 100644 --- a/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomBigQuery.schema.json +++ b/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomBigQuery.schema.json @@ -17,4 +17,4 @@ }, "title": "Custom Big Query", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomOptions.schema.json b/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomOptions.schema.json index 240a69b..936ad50 100644 --- a/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomOptions.schema.json +++ b/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomOptions.schema.json @@ -17,4 +17,4 @@ }, "title": "Custom Options", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/buf.protoschema.test.v1.NestedReference.schema.json b/internal/testdata/jsonschema/buf.protoschema.test.v1.NestedReference.schema.json index f18bcaf..d6dc6bd 100644 --- a/internal/testdata/jsonschema/buf.protoschema.test.v1.NestedReference.schema.json +++ b/internal/testdata/jsonschema/buf.protoschema.test.v1.NestedReference.schema.json @@ -9,4 +9,4 @@ }, "title": "Nested Reference", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.NestedTestAllTypes.schema.json b/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.NestedTestAllTypes.schema.json index 8329e25..70ac376 100644 --- a/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.NestedTestAllTypes.schema.json +++ b/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.NestedTestAllTypes.schema.json @@ -12,4 +12,4 @@ }, "title": "Nested Test All Types", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage.schema.json b/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage.schema.json index c364a24..26ef65a 100644 --- a/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage.schema.json +++ b/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage.schema.json @@ -11,4 +11,4 @@ }, "title": "Nested Message", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.TestAllTypes.schema.json b/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.TestAllTypes.schema.json index 03bc136..637d30f 100644 --- a/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.TestAllTypes.schema.json +++ b/internal/testdata/jsonschema/bufext.cel.expr.conformance.proto3.TestAllTypes.schema.json @@ -2923,4 +2923,4 @@ }, "title": "Test All Types", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.Any.schema.json b/internal/testdata/jsonschema/google.protobuf.Any.schema.json index 8accc1c..3a9b284 100644 --- a/internal/testdata/jsonschema/google.protobuf.Any.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Any.schema.json @@ -8,4 +8,4 @@ }, "title": "Any", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.BoolValue.schema.json b/internal/testdata/jsonschema/google.protobuf.BoolValue.schema.json index 9ae0f0a..1536e27 100644 --- a/internal/testdata/jsonschema/google.protobuf.BoolValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.BoolValue.schema.json @@ -3,4 +3,4 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Bool Value", "type": "boolean" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.BytesValue.schema.json b/internal/testdata/jsonschema/google.protobuf.BytesValue.schema.json index 50e29be..e240460 100644 --- a/internal/testdata/jsonschema/google.protobuf.BytesValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.BytesValue.schema.json @@ -4,4 +4,4 @@ "pattern": "^[A-Za-z0-9+/]*={0,2}$", "title": "Bytes Value", "type": "string" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.DoubleValue.schema.json b/internal/testdata/jsonschema/google.protobuf.DoubleValue.schema.json index fd6fc7b..0498254 100644 --- a/internal/testdata/jsonschema/google.protobuf.DoubleValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.DoubleValue.schema.json @@ -18,4 +18,4 @@ } ], "title": "Double Value" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.Duration.schema.json b/internal/testdata/jsonschema/google.protobuf.Duration.schema.json index 85b8fd3..28dcefb 100644 --- a/internal/testdata/jsonschema/google.protobuf.Duration.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Duration.schema.json @@ -4,4 +4,4 @@ "format": "duration", "title": "Duration", "type": "string" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.FloatValue.schema.json b/internal/testdata/jsonschema/google.protobuf.FloatValue.schema.json index dd1c474..8f71f3f 100644 --- a/internal/testdata/jsonschema/google.protobuf.FloatValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.FloatValue.schema.json @@ -18,4 +18,4 @@ } ], "title": "Float Value" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.Int32Value.schema.json b/internal/testdata/jsonschema/google.protobuf.Int32Value.schema.json index f8cf313..6a9274d 100644 --- a/internal/testdata/jsonschema/google.protobuf.Int32Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Int32Value.schema.json @@ -5,4 +5,4 @@ "minimum": -2147483648, "title": "Int32 Value", "type": "integer" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.Int64Value.schema.json b/internal/testdata/jsonschema/google.protobuf.Int64Value.schema.json index b96c993..9e96427 100644 --- a/internal/testdata/jsonschema/google.protobuf.Int64Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Int64Value.schema.json @@ -13,4 +13,4 @@ } ], "title": "Int64 Value" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.ListValue.schema.json b/internal/testdata/jsonschema/google.protobuf.ListValue.schema.json index aa570ff..a8c23d7 100644 --- a/internal/testdata/jsonschema/google.protobuf.ListValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.ListValue.schema.json @@ -3,4 +3,4 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "List Value", "type": "array" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.StringValue.schema.json b/internal/testdata/jsonschema/google.protobuf.StringValue.schema.json index 7de0fbe..ab61bf6 100644 --- a/internal/testdata/jsonschema/google.protobuf.StringValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.StringValue.schema.json @@ -3,4 +3,4 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "String Value", "type": "string" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.Struct.schema.json b/internal/testdata/jsonschema/google.protobuf.Struct.schema.json index d2b6db4..ff4eb65 100644 --- a/internal/testdata/jsonschema/google.protobuf.Struct.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Struct.schema.json @@ -3,4 +3,4 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Struct", "type": "object" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.Timestamp.schema.json b/internal/testdata/jsonschema/google.protobuf.Timestamp.schema.json index 51e3e77..b6e2b6d 100644 --- a/internal/testdata/jsonschema/google.protobuf.Timestamp.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Timestamp.schema.json @@ -4,4 +4,4 @@ "format": "date-time", "title": "Timestamp", "type": "string" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.UInt32Value.schema.json b/internal/testdata/jsonschema/google.protobuf.UInt32Value.schema.json index 79c097a..15c97cf 100644 --- a/internal/testdata/jsonschema/google.protobuf.UInt32Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.UInt32Value.schema.json @@ -5,4 +5,4 @@ "minimum": 0, "title": "U Int32 Value", "type": "integer" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.UInt64Value.schema.json b/internal/testdata/jsonschema/google.protobuf.UInt64Value.schema.json index e9f8979..07baa2d 100644 --- a/internal/testdata/jsonschema/google.protobuf.UInt64Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.UInt64Value.schema.json @@ -5,4 +5,4 @@ "minimum": 0, "title": "U Int64 Value", "type": "integer" -} \ No newline at end of file +} diff --git a/internal/testdata/jsonschema/google.protobuf.Value.schema.json b/internal/testdata/jsonschema/google.protobuf.Value.schema.json index 5a44142..508ddd6 100644 --- a/internal/testdata/jsonschema/google.protobuf.Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Value.schema.json @@ -2,4 +2,4 @@ "$id": "google.protobuf.Value.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Value" -} \ No newline at end of file +}