Skip to content

Commit b7fc466

Browse files
authored
chore(openapi): split openapi spec file (#1012)
Split the OpenAPI spec file into smaller pieces and merge them before generating code. The existing checks validate that the generated spec is up-to-date. Signed-off-by: Paul Boyd <[email protected]>
1 parent 46d4c02 commit b7fc466

File tree

4 files changed

+2431
-9
lines changed

4 files changed

+2431
-9
lines changed

Makefile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,14 @@ internal/converter/generated/converter.go: internal/converter/*.go
9494
.PHONY: gen/converter
9595
gen/converter: gen/grpc internal/converter/generated/converter.go
9696

97-
YQ_EXPR := 'sort_keys(.components.schemas) | sort_keys(.paths) | sort_keys(.components.responses)'
98-
99-
.PHONY: fmt/openapi
100-
fmt/openapi: api/openapi/model-registry.yaml bin/yq
101-
@$(YQ) -i $(YQ_EXPR) $<
97+
api/openapi/model-registry.yaml: api/openapi/src/model-registry.yaml api/openapi/src/lib/*.yaml bin/yq
98+
scripts/merge_openapi.sh model-registry.yaml
10299

103100
# validate the openapi schema
104101
.PHONY: openapi/validate
105-
openapi/validate: api/openapi/model-registry.yaml bin/openapi-generator-cli bin/yq
106-
@$(YQ) $(YQ_EXPR) $< | diff -u $< - || (echo "$< is incorrectly formatted. Run 'make fmt/openapi' to fix it."; exit 1)
107-
$(OPENAPI_GENERATOR) validate -i $<
102+
openapi/validate: bin/openapi-generator-cli bin/yq
103+
@scripts/merge_openapi.sh --check model-registry.yaml || (echo "api/openapi/model-registry.yaml is incorrectly formatted. Run 'make api/openapi/model-registry.yaml' to fix it."; exit 1)
104+
$(OPENAPI_GENERATOR) validate -i api/openapi/model-registry.yaml
108105

109106
# generate the openapi server implementation
110107
.PHONY: gen/openapi-server
@@ -115,7 +112,7 @@ internal/server/openapi/api_model_registry_service.go: bin/openapi-generator-cli
115112

116113
# generate the openapi schema model and client
117114
.PHONY: gen/openapi
118-
gen/openapi: bin/openapi-generator-cli openapi/validate pkg/openapi/client.go
115+
gen/openapi: api/openapi/model-registry.yaml bin/openapi-generator-cli openapi/validate pkg/openapi/client.go
119116

120117
pkg/openapi/client.go: bin/openapi-generator-cli api/openapi/model-registry.yaml clean-pkg-openapi
121118
${OPENAPI_GENERATOR} generate \

api/openapi/src/lib/common.yaml

Lines changed: 362 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,362 @@
1+
components:
2+
schemas:
3+
BaseResource:
4+
type: object
5+
properties:
6+
customProperties:
7+
description: User provided custom properties which are not defined by its type.
8+
type: object
9+
additionalProperties:
10+
$ref: "#/components/schemas/MetadataValue"
11+
description:
12+
description: |-
13+
An optional description about the resource.
14+
type: string
15+
externalId:
16+
description: |-
17+
The external id that come from the clients’ system. This field is optional.
18+
If set, it must be unique among all resources within a database instance.
19+
type: string
20+
name:
21+
description: |-
22+
The client provided name of the artifact. This field is optional. If set,
23+
it must be unique among all the artifacts of the same artifact type within
24+
a database instance and cannot be changed once set.
25+
type: string
26+
id:
27+
format: int64
28+
description: The unique server generated id of the resource.
29+
type: string
30+
createTimeSinceEpoch:
31+
format: int64
32+
description: Output only. Create time of the resource in millisecond since epoch.
33+
type: string
34+
readOnly: true
35+
lastUpdateTimeSinceEpoch:
36+
format: int64
37+
description: |-
38+
Output only. Last update time of the resource since epoch in millisecond
39+
since epoch.
40+
type: string
41+
readOnly: true
42+
BaseResourceCreate:
43+
type: object
44+
properties:
45+
customProperties:
46+
description: User provided custom properties which are not defined by its type.
47+
type: object
48+
additionalProperties:
49+
$ref: "#/components/schemas/MetadataValue"
50+
description:
51+
description: |-
52+
An optional description about the resource.
53+
type: string
54+
externalId:
55+
description: |-
56+
The external id that come from the clients’ system. This field is optional.
57+
If set, it must be unique among all resources within a database instance.
58+
type: string
59+
name:
60+
description: |-
61+
The client provided name of the artifact. This field is optional. If set,
62+
it must be unique among all the artifacts of the same artifact type within
63+
a database instance and cannot be changed once set.
64+
type: string
65+
BaseResourceList:
66+
required:
67+
- nextPageToken
68+
- pageSize
69+
- size
70+
type: object
71+
properties:
72+
nextPageToken:
73+
description: Token to use to retrieve next page of results.
74+
type: string
75+
pageSize:
76+
format: int32
77+
description: Maximum number of resources to return in the result.
78+
type: integer
79+
size:
80+
format: int32
81+
description: Number of items in result list.
82+
type: integer
83+
BaseResourceUpdate:
84+
type: object
85+
properties:
86+
customProperties:
87+
description: User provided custom properties which are not defined by its type.
88+
type: object
89+
additionalProperties:
90+
$ref: "#/components/schemas/MetadataValue"
91+
description:
92+
description: |-
93+
An optional description about the resource.
94+
type: string
95+
externalId:
96+
description: |-
97+
The external id that come from the clients’ system. This field is optional.
98+
If set, it must be unique among all resources within a database instance.
99+
type: string
100+
Error:
101+
description: Error code and message.
102+
required:
103+
- code
104+
- message
105+
type: object
106+
properties:
107+
code:
108+
description: Error code
109+
type: string
110+
message:
111+
description: Error message
112+
type: string
113+
MetadataBoolValue:
114+
description: A bool property value.
115+
type: object
116+
required:
117+
- metadataType
118+
- bool_value
119+
properties:
120+
bool_value:
121+
type: boolean
122+
metadataType:
123+
type: string
124+
example: MetadataBoolValue
125+
default: MetadataBoolValue
126+
MetadataDoubleValue:
127+
description: A double property value.
128+
type: object
129+
required:
130+
- metadataType
131+
- double_value
132+
properties:
133+
double_value:
134+
format: double
135+
type: number
136+
metadataType:
137+
type: string
138+
example: MetadataDoubleValue
139+
default: MetadataDoubleValue
140+
MetadataIntValue:
141+
description: An integer (int64) property value.
142+
type: object
143+
required:
144+
- metadataType
145+
- int_value
146+
properties:
147+
int_value:
148+
format: int64
149+
type: string
150+
metadataType:
151+
type: string
152+
example: MetadataIntValue
153+
default: MetadataIntValue
154+
MetadataProtoValue:
155+
description: A proto property value.
156+
type: object
157+
required:
158+
- metadataType
159+
- type
160+
- proto_value
161+
properties:
162+
type:
163+
description: url describing proto value
164+
type: string
165+
proto_value:
166+
description: Base64 encoded bytes for proto value
167+
type: string
168+
metadataType:
169+
type: string
170+
example: MetadataProtoValue
171+
default: MetadataProtoValue
172+
MetadataStringValue:
173+
description: A string property value.
174+
type: object
175+
required:
176+
- metadataType
177+
- string_value
178+
properties:
179+
string_value:
180+
type: string
181+
metadataType:
182+
type: string
183+
example: MetadataStringValue
184+
default: MetadataStringValue
185+
MetadataStructValue:
186+
description: A struct property value.
187+
type: object
188+
required:
189+
- metadataType
190+
- struct_value
191+
properties:
192+
struct_value:
193+
description: Base64 encoded bytes for struct value
194+
type: string
195+
metadataType:
196+
type: string
197+
example: MetadataStructValue
198+
default: MetadataStructValue
199+
MetadataValue:
200+
oneOf:
201+
- $ref: "#/components/schemas/MetadataIntValue"
202+
- $ref: "#/components/schemas/MetadataDoubleValue"
203+
- $ref: "#/components/schemas/MetadataStringValue"
204+
- $ref: "#/components/schemas/MetadataStructValue"
205+
- $ref: "#/components/schemas/MetadataProtoValue"
206+
- $ref: "#/components/schemas/MetadataBoolValue"
207+
discriminator:
208+
propertyName: metadataType
209+
mapping:
210+
MetadataBoolValue: "#/components/schemas/MetadataBoolValue"
211+
MetadataDoubleValue: "#/components/schemas/MetadataDoubleValue"
212+
MetadataIntValue: "#/components/schemas/MetadataIntValue"
213+
MetadataProtoValue: "#/components/schemas/MetadataProtoValue"
214+
MetadataStringValue: "#/components/schemas/MetadataStringValue"
215+
MetadataStructValue: "#/components/schemas/MetadataStructValue"
216+
description: A value in properties.
217+
example:
218+
string_value: my_value
219+
metadataType: MetadataStringValue
220+
OrderByField:
221+
description: Supported fields for ordering result entities.
222+
enum:
223+
- CREATE_TIME
224+
- LAST_UPDATE_TIME
225+
- ID
226+
type: string
227+
SortOrder:
228+
description: Supported sort direction for ordering result entities.
229+
enum:
230+
- ASC
231+
- DESC
232+
type: string
233+
responses:
234+
BadRequest:
235+
content:
236+
application/json:
237+
schema:
238+
$ref: "#/components/schemas/Error"
239+
description: Bad Request parameters
240+
Conflict:
241+
content:
242+
application/json:
243+
schema:
244+
$ref: "#/components/schemas/Error"
245+
description: Conflict with current state of target resource
246+
InternalServerError:
247+
content:
248+
application/json:
249+
schema:
250+
$ref: "#/components/schemas/Error"
251+
description: Unexpected internal server error
252+
NotFound:
253+
content:
254+
application/json:
255+
schema:
256+
$ref: "#/components/schemas/Error"
257+
description: The specified resource was not found
258+
ServiceUnavailable:
259+
content:
260+
application/json:
261+
schema:
262+
$ref: "#/components/schemas/Error"
263+
description: Service is unavailable
264+
Unauthorized:
265+
content:
266+
application/json:
267+
schema:
268+
$ref: "#/components/schemas/Error"
269+
description: Unauthorized
270+
UnprocessableEntity:
271+
content:
272+
application/json:
273+
schema:
274+
$ref: "#/components/schemas/Error"
275+
description: Unprocessable Entity error
276+
parameters:
277+
id:
278+
name: id
279+
description: The ID of resource.
280+
schema:
281+
type: string
282+
in: path
283+
required: true
284+
name:
285+
examples:
286+
name:
287+
value: entity-name
288+
name: name
289+
description: Name of entity to search.
290+
schema:
291+
type: string
292+
in: query
293+
required: false
294+
externalId:
295+
examples:
296+
externalId:
297+
value: "10"
298+
name: externalId
299+
description: External ID of entity to search.
300+
schema:
301+
type: string
302+
in: query
303+
required: false
304+
parentResourceId:
305+
examples:
306+
parentResourceId:
307+
value: "10"
308+
name: parentResourceId
309+
description: ID of the parent resource to use for search.
310+
schema:
311+
type: string
312+
in: query
313+
required: false
314+
pageSize:
315+
examples:
316+
pageSize:
317+
value: "100"
318+
name: pageSize
319+
description: Number of entities in each page.
320+
schema:
321+
type: string
322+
in: query
323+
required: false
324+
nextPageToken:
325+
name: nextPageToken
326+
description: Token to use to retrieve next page of results.
327+
schema:
328+
type: string
329+
in: query
330+
required: false
331+
orderBy:
332+
style: form
333+
explode: true
334+
examples:
335+
orderBy:
336+
value: ID
337+
name: orderBy
338+
description: Specifies the order by criteria for listing entities.
339+
schema:
340+
$ref: "#/components/schemas/OrderByField"
341+
in: query
342+
required: false
343+
sortOrder:
344+
style: form
345+
explode: true
346+
examples:
347+
sortOrder:
348+
value: DESC
349+
name: sortOrder
350+
description: "Specifies the sort order for listing entities, defaults to ASC."
351+
schema:
352+
$ref: "#/components/schemas/SortOrder"
353+
in: query
354+
required: false
355+
securitySchemes:
356+
Bearer:
357+
scheme: bearer
358+
bearerFormat: JWT
359+
type: http
360+
description: Bearer JWT scheme
361+
security:
362+
- Bearer: []

0 commit comments

Comments
 (0)