From 6869846e82e700e757ede229dca8e07de022b480 Mon Sep 17 00:00:00 2001 From: Alfred Fuller Date: Fri, 15 Mar 2024 10:25:53 -0700 Subject: [PATCH] Add 'title', fix wk/int types, and trim description --- internal/protoschema/jsonschema/jsonschema.go | 43 +- .../jsonschema-doc/test.TestAllTypes.yaml | 8 +- ...t.v1.BigQueryWellknownTypeTest.schema.json | 1 + ...oschema.test.v1.CustomBigQuery.schema.json | 1 + ...toschema.test.v1.CustomOptions.schema.json | 1 + ...schema.test.v1.NestedReference.schema.json | 1 + ...ance.proto3.NestedTestAllTypes.schema.json | 1 + ...to3.TestAllTypes.NestedMessage.schema.json | 1 + ...onformance.proto3.TestAllTypes.schema.json | 579 ++++++++++++++---- .../google.protobuf.Any.schema.json | 1 + .../google.protobuf.BoolValue.schema.json | 16 +- .../google.protobuf.BytesValue.schema.json | 19 +- .../google.protobuf.DoubleValue.schema.json | 51 +- .../google.protobuf.Duration.schema.json | 17 +- .../google.protobuf.FloatValue.schema.json | 51 +- .../google.protobuf.Int32Value.schema.json | 22 +- .../google.protobuf.Int64Value.schema.json | 20 +- .../google.protobuf.ListValue.schema.json | 1 + .../google.protobuf.StringValue.schema.json | 16 +- .../google.protobuf.Struct.schema.json | 1 + .../google.protobuf.Timestamp.schema.json | 17 +- .../google.protobuf.UInt32Value.schema.json | 22 +- .../google.protobuf.UInt64Value.schema.json | 22 +- .../google.protobuf.Value.schema.json | 3 +- 24 files changed, 581 insertions(+), 334 deletions(-) diff --git a/internal/protoschema/jsonschema/jsonschema.go b/internal/protoschema/jsonschema/jsonschema.go index 5b87a61..d752fc9 100644 --- a/internal/protoschema/jsonschema/jsonschema.go +++ b/internal/protoschema/jsonschema/jsonschema.go @@ -16,6 +16,8 @@ package jsonschema import ( "math" + "strings" + "unicode" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -57,6 +59,7 @@ func (p *jsonSchemaGenerator) generate(desc protoreflect.MessageDescriptor) { result := make(map[string]interface{}) result["$schema"] = "https://json-schema.org/draft/2020-12/schema" result["$id"] = p.getID(desc) + result["title"] = p.generateTitle(desc.Name()) p.result[desc.FullName()] = result if custom, ok := p.custom[desc.FullName()]; ok { // Custom generator. custom(result, desc) @@ -81,7 +84,7 @@ func (p *jsonSchemaGenerator) generateDefault(result map[string]interface{}, des func (p *jsonSchemaGenerator) setDescription(desc protoreflect.Descriptor, result map[string]interface{}) { src := desc.ParentFile().SourceLocations().ByDescriptor(desc) if src.LeadingComments != "" { - result["description"] = src.LeadingComments + result["description"] = strings.TrimSpace(src.LeadingComments) } } @@ -139,23 +142,44 @@ func (p *jsonSchemaGenerator) generateBoolValidation(_ protoreflect.FieldDescrip entry["type"] = jsBoolean } +func (p *jsonSchemaGenerator) generateTitle(name protoreflect.Name) string { + // Convert camel case to space separated words. + var result strings.Builder + for i, r := range name { + if unicode.IsUpper(r) && i > 0 { + result.WriteRune(' ') + } + result.WriteRune(r) + } + return result.String() +} + func (p *jsonSchemaGenerator) generateEnumValidation(field protoreflect.FieldDescriptor, entry map[string]interface{}) { var enum = make([]interface{}, 0) for i := 0; i < field.Enum().Values().Len(); i++ { enum = append(enum, field.Enum().Values().Get(i).Name()) } anyOf := []map[string]interface{}{ - {"type": jsString, "enum": enum}, + {"type": jsString, "enum": enum, "title": p.generateTitle(field.Enum().Name())}, {"type": jsInteger, "minimum": math.MinInt32, "maximum": math.MaxInt32}, } entry["anyOf"] = anyOf } func (p *jsonSchemaGenerator) generateIntValidation(_ protoreflect.FieldDescriptor, entry map[string]interface{}, bitSize int) { - entry["type"] = jsInteger // Use floats to handle integer overflow. - entry["minimum"] = -math.Pow(2, float64(bitSize-1)) - entry["exclusiveMaximum"] = math.Pow(2, float64(bitSize-1)) + min := -math.Pow(2, float64(bitSize-1)) + max := math.Pow(2, float64(bitSize-1)) + if bitSize <= 53 { + entry["type"] = jsInteger + entry["minimum"] = min + entry["exclusiveMaximum"] = max + } else { + entry["anyOf"] = []map[string]interface{}{ + {"type": jsInteger, "minimum": min, "maximum": max}, + {"type": jsString, "pattern": "^[0-9]+$"}, + } + } } func (p *jsonSchemaGenerator) generateUintValidation(_ protoreflect.FieldDescriptor, entry map[string]interface{}, bitSize int) { @@ -189,12 +213,9 @@ func (p *jsonSchemaGenerator) generateMessageValidation(field protoreflect.Field } func (p *jsonSchemaGenerator) generateWrapperValidation(result map[string]interface{}, desc protoreflect.MessageDescriptor) { - anyOf := []map[string]interface{}{ - make(map[string]interface{}), - p.generateField(desc.Fields().ByName("value")), - } - p.generateDefault(anyOf[0], desc) - result["anyOf"] = anyOf + field := desc.Fields().Get(0) + p.setDescription(field, result) + p.generateValidation(field, result) } func (p *jsonSchemaGenerator) makeWktGenerators() map[protoreflect.FullName]func(map[string]interface{}, protoreflect.MessageDescriptor) { diff --git a/internal/testdata/jsonschema-doc/test.TestAllTypes.yaml b/internal/testdata/jsonschema-doc/test.TestAllTypes.yaml index aeef9f0..acadd04 100644 --- a/internal/testdata/jsonschema-doc/test.TestAllTypes.yaml +++ b/internal/testdata/jsonschema-doc/test.TestAllTypes.yaml @@ -3,19 +3,17 @@ single_nested_enum: BAZ repeated_string: - foo - bar -single_float_wrapper: - value: 1.23 +single_float_wrapper: 1.23 single_int32: 0 single_timestamp: "1970-01-01T00:00:00Z" list_value: - foo - 1.23 repeated_bool_wrapper: - - value: true + - true - false repeated_float_wrapper: - 1.22 - - value: 1.23 - -Infinity - - value: NaN + - NaN single_duration: 1h2m3s 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 9fe4372..5f2ee50 100644 --- a/internal/testdata/jsonschema/buf.protoschema.test.v1.BigQueryWellknownTypeTest.schema.json +++ b/internal/testdata/jsonschema/buf.protoschema.test.v1.BigQueryWellknownTypeTest.schema.json @@ -7,5 +7,6 @@ "$ref": "google.protobuf.Value.schema.json" } }, + "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 4f2c8c4..a23b60c 100644 --- a/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomBigQuery.schema.json +++ b/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomBigQuery.schema.json @@ -15,5 +15,6 @@ "type": "string" } }, + "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 673d68a..240a69b 100644 --- a/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomOptions.schema.json +++ b/internal/testdata/jsonschema/buf.protoschema.test.v1.CustomOptions.schema.json @@ -15,5 +15,6 @@ "type": "string" } }, + "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 8356fa3..f18bcaf 100644 --- a/internal/testdata/jsonschema/buf.protoschema.test.v1.NestedReference.schema.json +++ b/internal/testdata/jsonschema/buf.protoschema.test.v1.NestedReference.schema.json @@ -7,5 +7,6 @@ "$ref": "bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage.schema.json" } }, + "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 5cf887c..8329e25 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 @@ -10,5 +10,6 @@ "$ref": "bufext.cel.expr.conformance.proto3.TestAllTypes.schema.json" } }, + "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 86a15f4..c364a24 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 @@ -9,5 +9,6 @@ "type": "integer" } }, + "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 c811ce7..03bc136 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 @@ -103,6 +103,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -172,9 +173,17 @@ }, "map_bool_int64": { "additionalProperties": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "propertyNames": { "type": "boolean" @@ -215,6 +224,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -427,6 +437,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -506,9 +517,17 @@ }, "map_int32_int64": { "additionalProperties": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "propertyNames": { "exclusiveMaximum": 2147483648, @@ -557,6 +576,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -681,9 +701,17 @@ "$ref": "google.protobuf.Any.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -692,9 +720,17 @@ "type": "boolean" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -703,9 +739,17 @@ "$ref": "google.protobuf.BoolValue.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -715,9 +759,17 @@ "type": "string" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -726,9 +778,17 @@ "$ref": "google.protobuf.BytesValue.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -752,9 +812,17 @@ ] }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -763,9 +831,17 @@ "$ref": "google.protobuf.DoubleValue.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -774,9 +850,17 @@ "$ref": "google.protobuf.Duration.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -789,6 +873,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -799,9 +884,17 @@ ] }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -825,9 +918,17 @@ ] }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -836,9 +937,17 @@ "$ref": "google.protobuf.FloatValue.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -849,9 +958,17 @@ "type": "integer" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -860,22 +977,46 @@ "$ref": "google.protobuf.Int32Value.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, "map_int64_int64": { "additionalProperties": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -884,9 +1025,17 @@ "$ref": "google.protobuf.Int64Value.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -895,9 +1044,17 @@ "$ref": "google.protobuf.ListValue.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -906,9 +1063,17 @@ "$ref": "bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -917,9 +1082,17 @@ "$ref": "bufext.cel.expr.conformance.proto3.NestedTestAllTypes.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -930,6 +1103,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -940,9 +1114,17 @@ ] }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -951,9 +1133,17 @@ "type": "string" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -962,9 +1152,17 @@ "$ref": "google.protobuf.StringValue.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -973,9 +1171,17 @@ "$ref": "google.protobuf.Struct.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -984,9 +1190,17 @@ "$ref": "google.protobuf.Timestamp.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -997,9 +1211,17 @@ "type": "integer" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -1008,9 +1230,17 @@ "$ref": "google.protobuf.UInt32Value.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -1021,9 +1251,17 @@ "type": "integer" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -1032,9 +1270,17 @@ "$ref": "google.protobuf.UInt64Value.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -1043,9 +1289,17 @@ "$ref": "google.protobuf.Value.schema.json" }, "propertyNames": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "object" }, @@ -1146,6 +1400,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -1215,9 +1470,17 @@ }, "map_string_int64": { "additionalProperties": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "propertyNames": { "type": "string" @@ -1258,6 +1521,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -1470,6 +1734,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -1549,9 +1814,17 @@ }, "map_uint32_int64": { "additionalProperties": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "propertyNames": { "exclusiveMaximum": 4294967296, @@ -1600,6 +1873,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -1832,6 +2106,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -1911,9 +2186,17 @@ }, "map_uint64_int64": { "additionalProperties": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "propertyNames": { "exclusiveMaximum": 18446744073709552000, @@ -1962,6 +2245,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -2087,6 +2371,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -2102,6 +2387,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -2240,9 +2526,17 @@ }, "repeated_int64": { "items": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "array" }, @@ -2273,6 +2567,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -2297,6 +2592,7 @@ "enum": [ "NULL_VALUE" ], + "title": "Null Value", "type": "string" }, { @@ -2318,9 +2614,17 @@ }, "repeated_sfixed64": { "items": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "array" }, @@ -2334,9 +2638,17 @@ }, "repeated_sint64": { "items": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "type": "array" }, @@ -2484,9 +2796,17 @@ "$ref": "google.protobuf.Int32Value.schema.json" }, "single_int64": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "single_int64_wrapper": { "$ref": "google.protobuf.Int64Value.schema.json" @@ -2499,6 +2819,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -2517,9 +2838,17 @@ "type": "integer" }, "single_sfixed64": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "single_sint32": { "exclusiveMaximum": 2147483648, @@ -2527,9 +2856,17 @@ "type": "integer" }, "single_sint64": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] }, "single_string": { "type": "string" @@ -2570,6 +2907,7 @@ "BAR", "BAZ" ], + "title": "Nested Enum", "type": "string" }, { @@ -2583,5 +2921,6 @@ "$ref": "bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage.schema.json" } }, + "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 6ec1523..8accc1c 100644 --- a/internal/testdata/jsonschema/google.protobuf.Any.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Any.schema.json @@ -6,5 +6,6 @@ "type": "string" } }, + "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 196ba08..9ae0f0a 100644 --- a/internal/testdata/jsonschema/google.protobuf.BoolValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.BoolValue.schema.json @@ -1,18 +1,6 @@ { "$id": "google.protobuf.BoolValue.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "additionalProperties": false, - "properties": { - "value": { - "type": "boolean" - } - }, - "type": "object" - }, - { - "type": "boolean" - } - ] + "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 3222cbe..50e29be 100644 --- a/internal/testdata/jsonschema/google.protobuf.BytesValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.BytesValue.schema.json @@ -1,20 +1,7 @@ { "$id": "google.protobuf.BytesValue.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "additionalProperties": false, - "properties": { - "value": { - "pattern": "^[A-Za-z0-9+/]*={0,2}$", - "type": "string" - } - }, - "type": "object" - }, - { - "pattern": "^[A-Za-z0-9+/]*={0,2}$", - "type": "string" - } - ] + "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 2877541..fd6fc7b 100644 --- a/internal/testdata/jsonschema/google.protobuf.DoubleValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.DoubleValue.schema.json @@ -3,46 +3,19 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "anyOf": [ { - "additionalProperties": false, - "properties": { - "value": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string" - }, - { - "enum": [ - "NaN", - "Infinity", - "-Infinity" - ], - "type": "string" - } - ] - } - }, - "type": "object" + "type": "number" }, { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string" - }, - { - "enum": [ - "NaN", - "Infinity", - "-Infinity" - ], - "type": "string" - } - ] + "type": "string" + }, + { + "enum": [ + "NaN", + "Infinity", + "-Infinity" + ], + "type": "string" } - ] + ], + "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 0dac4d8..054a273 100644 --- a/internal/testdata/jsonschema/google.protobuf.Duration.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Duration.schema.json @@ -11,9 +11,17 @@ "type": "integer" }, "seconds": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] } }, "type": "object" @@ -22,5 +30,6 @@ "format": "duration", "type": "string" } - ] + ], + "title": "Duration" } \ 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 a099f71..dd1c474 100644 --- a/internal/testdata/jsonschema/google.protobuf.FloatValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.FloatValue.schema.json @@ -3,46 +3,19 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "anyOf": [ { - "additionalProperties": false, - "properties": { - "value": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string" - }, - { - "enum": [ - "NaN", - "Infinity", - "-Infinity" - ], - "type": "string" - } - ] - } - }, - "type": "object" + "type": "number" }, { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string" - }, - { - "enum": [ - "NaN", - "Infinity", - "-Infinity" - ], - "type": "string" - } - ] + "type": "string" + }, + { + "enum": [ + "NaN", + "Infinity", + "-Infinity" + ], + "type": "string" } - ] + ], + "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 b95bddc..f8cf313 100644 --- a/internal/testdata/jsonschema/google.protobuf.Int32Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Int32Value.schema.json @@ -1,22 +1,8 @@ { "$id": "google.protobuf.Int32Value.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "additionalProperties": false, - "properties": { - "value": { - "exclusiveMaximum": 2147483648, - "minimum": -2147483648, - "type": "integer" - } - }, - "type": "object" - }, - { - "exclusiveMaximum": 2147483648, - "minimum": -2147483648, - "type": "integer" - } - ] + "exclusiveMaximum": 2147483648, + "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 463d582..b96c993 100644 --- a/internal/testdata/jsonschema/google.protobuf.Int64Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Int64Value.schema.json @@ -3,20 +3,14 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "anyOf": [ { - "additionalProperties": false, - "properties": { - "value": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" - } - }, - "type": "object" - }, - { - "exclusiveMaximum": 9223372036854776000, + "maximum": 9223372036854776000, "minimum": -9223372036854776000, "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" } - ] + ], + "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 db512a4..aa570ff 100644 --- a/internal/testdata/jsonschema/google.protobuf.ListValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.ListValue.schema.json @@ -1,5 +1,6 @@ { "$id": "google.protobuf.ListValue.schema.json", "$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 b90d959..7de0fbe 100644 --- a/internal/testdata/jsonschema/google.protobuf.StringValue.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.StringValue.schema.json @@ -1,18 +1,6 @@ { "$id": "google.protobuf.StringValue.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "additionalProperties": false, - "properties": { - "value": { - "type": "string" - } - }, - "type": "object" - }, - { - "type": "string" - } - ] + "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 c000176..d2b6db4 100644 --- a/internal/testdata/jsonschema/google.protobuf.Struct.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Struct.schema.json @@ -1,5 +1,6 @@ { "$id": "google.protobuf.Struct.schema.json", "$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 1027588..be47b86 100644 --- a/internal/testdata/jsonschema/google.protobuf.Timestamp.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Timestamp.schema.json @@ -11,9 +11,17 @@ "type": "integer" }, "seconds": { - "exclusiveMaximum": 9223372036854776000, - "minimum": -9223372036854776000, - "type": "integer" + "anyOf": [ + { + "maximum": 9223372036854776000, + "minimum": -9223372036854776000, + "type": "integer" + }, + { + "pattern": "^[0-9]+$", + "type": "string" + } + ] } }, "type": "object" @@ -22,5 +30,6 @@ "format": "date-time", "type": "string" } - ] + ], + "title": "Timestamp" } \ 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 acaf7e1..79c097a 100644 --- a/internal/testdata/jsonschema/google.protobuf.UInt32Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.UInt32Value.schema.json @@ -1,22 +1,8 @@ { "$id": "google.protobuf.UInt32Value.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "additionalProperties": false, - "properties": { - "value": { - "exclusiveMaximum": 4294967296, - "minimum": 0, - "type": "integer" - } - }, - "type": "object" - }, - { - "exclusiveMaximum": 4294967296, - "minimum": 0, - "type": "integer" - } - ] + "exclusiveMaximum": 4294967296, + "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 13776ec..e9f8979 100644 --- a/internal/testdata/jsonschema/google.protobuf.UInt64Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.UInt64Value.schema.json @@ -1,22 +1,8 @@ { "$id": "google.protobuf.UInt64Value.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "additionalProperties": false, - "properties": { - "value": { - "exclusiveMaximum": 18446744073709552000, - "minimum": 0, - "type": "integer" - } - }, - "type": "object" - }, - { - "exclusiveMaximum": 18446744073709552000, - "minimum": 0, - "type": "integer" - } - ] + "exclusiveMaximum": 18446744073709552000, + "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 cc6828c..5a44142 100644 --- a/internal/testdata/jsonschema/google.protobuf.Value.schema.json +++ b/internal/testdata/jsonschema/google.protobuf.Value.schema.json @@ -1,4 +1,5 @@ { "$id": "google.protobuf.Value.schema.json", - "$schema": "https://json-schema.org/draft/2020-12/schema" + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Value" } \ No newline at end of file