Skip to content

Commit 5b1f065

Browse files
committed
refactor(model-server): deduplicate problem types in OpenAPI specs
Use a file $ref instead of duplicating the type to prevent potentially diverging definitions. This does not yet prevent the duplication of generated code.
1 parent a6e9ec8 commit 5b1f065

File tree

6 files changed

+64
-155
lines changed

6 files changed

+64
-155
lines changed

model-server-openapi/specifications/model-server-operative.yaml

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -77,56 +77,9 @@ components:
7777
content:
7878
application/problem+json:
7979
schema:
80-
$ref: '#/components/schemas/Problem'
80+
$ref: 'problem.yaml#/Problem'
8181

8282
schemas:
83-
# From https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml
84-
Problem:
85-
type: object
86-
properties:
87-
type:
88-
type: string
89-
format: uri-reference
90-
description: >
91-
A URI reference that uniquely identifies the problem type only in the
92-
context of the provided API. Opposed to the specification in RFC-9457,
93-
it is neither recommended to be dereferenceable and point to a
94-
human-readable documentation nor globally unique for the problem type.
95-
default: 'about:blank'
96-
example: '/some/uri-reference'
97-
title:
98-
type: string
99-
description: >
100-
A short summary of the problem type. Written in English and readable
101-
for engineers, usually not suited for non technical stakeholders and
102-
not localized.
103-
example: some title for the error situation
104-
status:
105-
type: integer
106-
format: int32
107-
description: >
108-
The HTTP status code generated by the origin server for this occurrence
109-
of the problem.
110-
minimum: 100
111-
maximum: 600
112-
exclusiveMaximum: true
113-
detail:
114-
type: string
115-
description: >
116-
A human readable explanation specific to this occurrence of the
117-
problem that is helpful to locate the problem and give advice on how
118-
to proceed. Written in English and readable for engineers, usually not
119-
suited for non technical stakeholders and not localized.
120-
example: some description for the error situation
121-
instance:
122-
type: string
123-
format: uri-reference
124-
description: >
125-
A URI reference that identifies the specific occurrence of the problem,
126-
e.g. by adding a fragment identifier or sub-path to the problem type.
127-
May be used to locate the root of this problem in the source code.
128-
example: '/some/uri-reference#specific-occurrence-context'
129-
13083
AboutV1:
13184
x-modelix-media-type: 'application/x.modelix.about+json;version=1'
13285
description: Information about the model server

model-server-openapi/specifications/model-server-v1.yaml

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -185,76 +185,28 @@ components:
185185
content:
186186
application/problem+json:
187187
schema:
188-
$ref: '#/components/schemas/Problem'
188+
$ref: 'problem.yaml#/Problem'
189189
"401":
190190
description: "Unauthorized"
191191
content:
192192
application/problem+json:
193193
schema:
194-
$ref: '#/components/schemas/Problem'
194+
$ref: 'problem.yaml#/Problem'
195195
"403":
196196
description: "Forbidden"
197197
content:
198198
application/problem+json:
199199
schema:
200-
$ref: '#/components/schemas/Problem'
200+
$ref: 'problem.yaml#/Problem'
201201
"404":
202202
description: "Not Found"
203203
content:
204204
application/problem+json:
205205
schema:
206-
$ref: '#/components/schemas/Problem'
206+
$ref: 'problem.yaml#/Problem'
207207
GeneralError:
208208
description: Unexpected error
209209
content:
210210
application/problem+json:
211211
schema:
212-
$ref: '#/components/schemas/Problem'
213-
214-
schemas:
215-
# From https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml
216-
Problem:
217-
type: object
218-
properties:
219-
type:
220-
type: string
221-
format: uri-reference
222-
description: >
223-
A URI reference that uniquely identifies the problem type only in the
224-
context of the provided API. Opposed to the specification in RFC-9457,
225-
it is neither recommended to be dereferenceable and point to a
226-
human-readable documentation nor globally unique for the problem type.
227-
default: 'about:blank'
228-
example: '/some/uri-reference'
229-
title:
230-
type: string
231-
description: >
232-
A short summary of the problem type. Written in English and readable
233-
for engineers, usually not suited for non technical stakeholders and
234-
not localized.
235-
example: some title for the error situation
236-
status:
237-
type: integer
238-
format: int32
239-
description: >
240-
The HTTP status code generated by the origin server for this occurrence
241-
of the problem.
242-
minimum: 100
243-
maximum: 600
244-
exclusiveMaximum: true
245-
detail:
246-
type: string
247-
description: >
248-
A human readable explanation specific to this occurrence of the
249-
problem that is helpful to locate the problem and give advice on how
250-
to proceed. Written in English and readable for engineers, usually not
251-
suited for non technical stakeholders and not localized.
252-
example: some description for the error situation
253-
instance:
254-
type: string
255-
format: uri-reference
256-
description: >
257-
A URI reference that identifies the specific occurrence of the problem,
258-
e.g. by adding a fragment identifier or sub-path to the problem type.
259-
May be used to locate the root of this problem in the source code.
260-
example: '/some/uri-reference#specific-occurrence-context'
212+
$ref: 'problem.yaml#/Problem'

model-server-openapi/specifications/model-server-v2.yaml

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -447,31 +447,31 @@ components:
447447
content:
448448
application/problem+json:
449449
schema:
450-
$ref: '#/components/schemas/Problem'
450+
$ref: 'problem.yaml#/Problem'
451451
"401":
452452
description: "Unauthorized"
453453
content:
454454
application/problem+json:
455455
schema:
456-
$ref: '#/components/schemas/Problem'
456+
$ref: 'problem.yaml#/Problem'
457457
"403":
458458
description: "Forbidden"
459459
content:
460460
application/problem+json:
461461
schema:
462-
$ref: '#/components/schemas/Problem'
462+
$ref: 'problem.yaml#/Problem'
463463
"404":
464464
description: "Not Found"
465465
content:
466466
application/problem+json:
467467
schema:
468-
$ref: '#/components/schemas/Problem'
468+
$ref: 'problem.yaml#/Problem'
469469
GeneralError:
470470
description: Unexpected error
471471
content:
472472
application/problem+json:
473473
schema:
474-
$ref: '#/components/schemas/Problem'
474+
$ref: 'problem.yaml#/Problem'
475475

476476
"versionDelta":
477477
description: OK
@@ -490,53 +490,6 @@ components:
490490
type: string
491491

492492
schemas:
493-
# From https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml
494-
Problem:
495-
type: object
496-
properties:
497-
type:
498-
type: string
499-
format: uri-reference
500-
description: >
501-
A URI reference that uniquely identifies the problem type only in the
502-
context of the provided API. Opposed to the specification in RFC-9457,
503-
it is neither recommended to be dereferenceable and point to a
504-
human-readable documentation nor globally unique for the problem type.
505-
default: 'about:blank'
506-
example: '/some/uri-reference'
507-
title:
508-
type: string
509-
description: >
510-
A short summary of the problem type. Written in English and readable
511-
for engineers, usually not suited for non technical stakeholders and
512-
not localized.
513-
example: some title for the error situation
514-
status:
515-
type: integer
516-
format: int32
517-
description: >
518-
The HTTP status code generated by the origin server for this occurrence
519-
of the problem.
520-
minimum: 100
521-
maximum: 600
522-
exclusiveMaximum: true
523-
detail:
524-
type: string
525-
description: >
526-
A human readable explanation specific to this occurrence of the
527-
problem that is helpful to locate the problem and give advice on how
528-
to proceed. Written in English and readable for engineers, usually not
529-
suited for non technical stakeholders and not localized.
530-
example: some description for the error situation
531-
instance:
532-
type: string
533-
format: uri-reference
534-
description: >
535-
A URI reference that identifies the specific occurrence of the problem,
536-
e.g. by adding a fragment identifier or sub-path to the problem type.
537-
May be used to locate the root of this problem in the source code.
538-
example: '/some/uri-reference#specific-occurrence-context'
539-
540493
VersionDelta:
541494
title: VersionDelta
542495
type: object
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# From https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml
2+
Problem:
3+
type: object
4+
properties:
5+
type:
6+
type: string
7+
format: uri-reference
8+
description: >
9+
A URI reference that uniquely identifies the problem type only in the
10+
context of the provided API. Opposed to the specification in RFC-9457,
11+
it is neither recommended to be dereferenceable and point to a
12+
human-readable documentation nor globally unique for the problem type.
13+
default: 'about:blank'
14+
example: '/some/uri-reference'
15+
title:
16+
type: string
17+
description: >
18+
A short summary of the problem type. Written in English and readable
19+
for engineers, usually not suited for non technical stakeholders and
20+
not localized.
21+
example: some title for the error situation
22+
status:
23+
type: integer
24+
format: int32
25+
description: >
26+
The HTTP status code generated by the origin server for this occurrence
27+
of the problem.
28+
minimum: 100
29+
maximum: 600
30+
exclusiveMaximum: true
31+
detail:
32+
type: string
33+
description: >
34+
A human readable explanation specific to this occurrence of the
35+
problem that is helpful to locate the problem and give advice on how
36+
to proceed. Written in English and readable for engineers, usually not
37+
suited for non technical stakeholders and not localized.
38+
example: some description for the error situation
39+
instance:
40+
type: string
41+
format: uri-reference
42+
description: >
43+
A URI reference that identifies the specific occurrence of the problem,
44+
e.g. by adding a fragment identifier or sub-path to the problem type.
45+
May be used to locate the root of this problem in the source code.
46+
example: '/some/uri-reference#specific-occurrence-context'

model-server/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ spotless {
201201

202202
// OpenAPI integration
203203
val basePackage = project.group.toString()
204-
val openAPIgenerationPath = "${project.layout.buildDirectory.get()}/generated/openapi"
204+
val openApiGenerationPath = project.layout.buildDirectory.get().dir("generated").dir("openapi")
205205

206206
// Pairs of the different OpenAPI files we use. Each pair must have its own 'category' as first argument as these
207207
// are used to generate corresponding packages
@@ -215,7 +215,7 @@ val openApiFiles = listOf(
215215
openApiFiles.forEach {
216216
val targetTaskName = "openApiGenerate-${it.second}"
217217
val targetPackageName = "$basePackage.api.${it.first}"
218-
val outputPath = "$openAPIgenerationPath/${it.first}"
218+
val outputPath = "$openApiGenerationPath/${it.first}"
219219
tasks.register<GenerateTask>(targetTaskName) {
220220
// we let the Gradle OpenAPI generator plugin build data classes and API interfaces based on the provided
221221
// OpenAPI specification. That way, the code is forced to stay in sync with the API specification.

model-server/src/main/kotlin/org/modelix/model/server/Main.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ object Main {
240240
get("swagger") {
241241
call.respondRedirect("swagger/v2", false)
242242
}
243+
// The swagger UI plugin automatically serves the configured OpenAPI specification. However,
244+
// it does not include potentially linked files. Therefore, we need to serve those on
245+
// appropriate paths on our own to not break the Swagger UI.
246+
staticResources("swagger/v2", "api")
247+
staticResources("swagger/v1", "api")
243248
}
244249
}
245250
}

0 commit comments

Comments
 (0)