Skip to content

Commit 7164e5b

Browse files
authored
Merge pull request #9 from solo-io/add-UInt64Value
Adding support for UInt64Value
2 parents 34a2606 + 4eea904 commit 7164e5b

File tree

9 files changed

+120
-21
lines changed

9 files changed

+120
-21
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ _output/
2323
**/doc-gen-test-*
2424

2525
# Local binary produced by make build
26-
protoc-gen-openapi
26+
protoc-gen-openapi
27+
out/

changelog/v0.1.1/add-uint64value.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
changelog:
2+
- type: FIX
3+
description: Support custom solo type `UInt64Value` and `Int64Value`.
4+
issueLink: https://github.com/solo-io/protoc-gen-openapi/issues/10
5+
resolvesIssue: true

openapiGenerator.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ var specialSoloTypes = map[string]openapi3.Schema{
7171
"google.protobuf.StringValue": *openapi3.NewStringSchema().WithNullable(),
7272
"google.protobuf.DoubleValue": *openapi3.NewFloat64Schema().WithNullable(),
7373
"google.protobuf.Int32Value": *openapi3.NewIntegerSchema().WithNullable().WithMin(math.MinInt32).WithMax(math.MaxInt32),
74+
"google.protobuf.Int64Value": *openapi3.NewIntegerSchema().WithNullable().WithMin(math.MinInt64).WithMax(math.MaxInt64),
7475
"google.protobuf.UInt32Value": *openapi3.NewIntegerSchema().WithNullable().WithMin(0).WithMax(math.MaxUint32),
76+
"google.protobuf.UInt64Value": *openapi3.NewIntegerSchema().WithNullable().WithMin(0).WithMax(math.MaxUint64),
7577
"google.protobuf.FloatValue": *openapi3.NewFloat64Schema().WithNullable(),
7678
"google.protobuf.Duration": *openapi3.NewStringSchema(),
7779
"google.protobuf.Empty": *openapi3.NewObjectSchema().WithMaxProperties(0),
@@ -132,9 +134,9 @@ func newOpenAPIGenerator(
132134

133135
// buildCustomSchemasByMessageName name returns a mapping of message name to a pre-defined openapi schema
134136
// It includes:
135-
// 1. `specialSoloTypes`, a set of pre-defined schemas
137+
// 1. `specialSoloTypes`, a set of pre-defined schemas
136138
// 2. `messagesWithEmptySchema`, a list of messages that are injected at runtime that should contain
137-
// and empty schema which accepts and preserves all fields
139+
// and empty schema which accepts and preserves all fields
138140
func buildCustomSchemasByMessageName(messagesWithEmptySchema []string) map[string]openapi3.Schema {
139141
schemasByMessageName := make(map[string]openapi3.Schema)
140142

testdata/golden/openapiv3.json

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"openapi": "3.0.1",
3-
"info": {
4-
"title": "OpenAPI Spec for Solo APIs."
5-
},
63
"components": {
74
"schemas": {
85
"testpkg.Days": {
@@ -44,6 +41,11 @@
4441
"format": "int32",
4542
"type": "integer"
4643
},
44+
"field10": {
45+
"format": "int64",
46+
"type": "integer",
47+
"x-kubernetes-int-or-string": true
48+
},
4749
"field3": {
4850
"type": "number"
4951
},
@@ -66,6 +68,11 @@
6668
"format": "int32",
6769
"type": "integer"
6870
},
71+
"field9": {
72+
"format": "int64",
73+
"type": "integer",
74+
"x-kubernetes-int-or-string": true
75+
},
6976
"str": {
7077
"description": "an array of strings",
7178
"items": {
@@ -86,6 +93,11 @@
8693
"format": "int32",
8794
"type": "integer"
8895
},
96+
"field10": {
97+
"format": "int64",
98+
"type": "integer",
99+
"x-kubernetes-int-or-string": true
100+
},
89101
"field3": {
90102
"type": "number"
91103
},
@@ -108,6 +120,11 @@
108120
"format": "int32",
109121
"type": "integer"
110122
},
123+
"field9": {
124+
"format": "int64",
125+
"type": "integer",
126+
"x-kubernetes-int-or-string": true
127+
},
111128
"str": {
112129
"description": "an array of strings",
113130
"items": {
@@ -169,6 +186,16 @@
169186
"format": "int32",
170187
"type": "integer"
171188
},
189+
"field17": {
190+
"format": "int64",
191+
"type": "integer",
192+
"x-kubernetes-int-or-string": true
193+
},
194+
"field18": {
195+
"format": "int64",
196+
"type": "integer",
197+
"x-kubernetes-int-or-string": true
198+
},
172199
"field3": {
173200
"type": "number"
174201
},
@@ -261,5 +288,10 @@
261288
"type": "object"
262289
}
263290
}
264-
}
291+
},
292+
"info": {
293+
"title": "OpenAPI Spec for Solo APIs.",
294+
"version": ""
295+
},
296+
"paths": null
265297
}

testdata/golden/testRef/openapiv3.json

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"openapi": "3.0.1",
3-
"info": {
4-
"title": "OpenAPI Spec for Solo APIs."
5-
},
63
"components": {
74
"schemas": {
85
"testpkg.Days": {
@@ -44,6 +41,11 @@
4441
"format": "int32",
4542
"type": "integer"
4643
},
44+
"field10": {
45+
"format": "int64",
46+
"type": "integer",
47+
"x-kubernetes-int-or-string": true
48+
},
4749
"field3": {
4850
"type": "number"
4951
},
@@ -66,6 +68,11 @@
6668
"format": "int32",
6769
"type": "integer"
6870
},
71+
"field9": {
72+
"format": "int64",
73+
"type": "integer",
74+
"x-kubernetes-int-or-string": true
75+
},
6976
"str": {
7077
"description": "an array of strings",
7178
"items": {
@@ -86,6 +93,11 @@
8693
"format": "int32",
8794
"type": "integer"
8895
},
96+
"field10": {
97+
"format": "int64",
98+
"type": "integer",
99+
"x-kubernetes-int-or-string": true
100+
},
89101
"field3": {
90102
"type": "number"
91103
},
@@ -108,6 +120,11 @@
108120
"format": "int32",
109121
"type": "integer"
110122
},
123+
"field9": {
124+
"format": "int64",
125+
"type": "integer",
126+
"x-kubernetes-int-or-string": true
127+
},
111128
"str": {
112129
"description": "an array of strings",
113130
"items": {
@@ -169,6 +186,16 @@
169186
"format": "int32",
170187
"type": "integer"
171188
},
189+
"field17": {
190+
"format": "int64",
191+
"type": "integer",
192+
"x-kubernetes-int-or-string": true
193+
},
194+
"field18": {
195+
"format": "int64",
196+
"type": "integer",
197+
"x-kubernetes-int-or-string": true
198+
},
172199
"field3": {
173200
"type": "number"
174201
},
@@ -252,5 +279,10 @@
252279
"type": "object"
253280
}
254281
}
255-
}
282+
},
283+
"info": {
284+
"title": "OpenAPI Spec for Solo APIs.",
285+
"version": ""
286+
},
287+
"paths": null
256288
}

testdata/golden/testpkg.json

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
22
"openapi": "3.0.1",
3-
"info": {
4-
"title": "My Overview",
5-
"version": "testpkg"
6-
},
73
"components": {
84
"schemas": {
95
"testpkg.Days": {
@@ -45,6 +41,11 @@
4541
"format": "int32",
4642
"type": "integer"
4743
},
44+
"field10": {
45+
"format": "int64",
46+
"type": "integer",
47+
"x-kubernetes-int-or-string": true
48+
},
4849
"field3": {
4950
"type": "number"
5051
},
@@ -67,6 +68,11 @@
6768
"format": "int32",
6869
"type": "integer"
6970
},
71+
"field9": {
72+
"format": "int64",
73+
"type": "integer",
74+
"x-kubernetes-int-or-string": true
75+
},
7076
"str": {
7177
"description": "an array of strings",
7278
"items": {
@@ -87,6 +93,11 @@
8793
"format": "int32",
8894
"type": "integer"
8995
},
96+
"field10": {
97+
"format": "int64",
98+
"type": "integer",
99+
"x-kubernetes-int-or-string": true
100+
},
90101
"field3": {
91102
"type": "number"
92103
},
@@ -109,6 +120,11 @@
109120
"format": "int32",
110121
"type": "integer"
111122
},
123+
"field9": {
124+
"format": "int64",
125+
"type": "integer",
126+
"x-kubernetes-int-or-string": true
127+
},
112128
"str": {
113129
"description": "an array of strings",
114130
"items": {
@@ -131,5 +147,10 @@
131147
"type": "object"
132148
}
133149
}
134-
}
150+
},
151+
"info": {
152+
"title": "My Overview",
153+
"version": "testpkg"
154+
},
155+
"paths": null
135156
}

testdata/golden/testpkg2.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
22
"openapi": "3.0.1",
3-
"info": {
4-
"title": "OpenAPI Spec for Istio APIs.",
5-
"version": "testpkg2"
6-
},
73
"components": {
84
"schemas": {
95
"testpkg2.AEnum": {
@@ -151,5 +147,10 @@
151147
"type": "object"
152148
}
153149
}
154-
}
150+
},
151+
"info": {
152+
"title": "OpenAPI Spec for Solo APIs.",
153+
"version": ""
154+
},
155+
"paths": null
155156
}

testdata/testpkg/test2.proto

+2
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ message Test2 {
1515
sfixed32 field6 = 6;
1616
sint32 field7 = 7;
1717
uint32 field8 = 8;
18+
int64 field9 = 9;
19+
uint64 field10 = 10;
1820
}

testdata/testpkg2/test3.proto

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ message Test3 {
5050

5151
// messageoneof comment
5252
MessageOneOf messageOneOfField = 16;
53+
54+
int64 field17 = 17;
55+
uint64 field18 = 18;
5356
}
5457

5558
message Test3_Value {

0 commit comments

Comments
 (0)