Skip to content

Commit 4865902

Browse files
committed
OpenAPI documents support enumeration types
1 parent 9c01884 commit 4865902

File tree

3 files changed

+60
-18
lines changed

3 files changed

+60
-18
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/openapi/OpenAPISerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static String serialize(Object obj) throws IllegalAccessException {
8181
sb.append(",");
8282
}
8383
sb.append("\"");
84-
sb.append(field.getName());
84+
sb.append(field.getName().replace("_enum", "enum"));
8585
sb.append("\" : ");
8686
write(sb, value);
8787
firstField = false;

tests/test-javalin-jsonb/src/main/resources/public/openapi.json

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"openapi" : "3.0.1",
33
"info" : {
4-
"title" : "Example service showing off the Path extension method of controller",
4+
"title" : "Example service",
55
"description" : "Example Javalin controllers with Java and Maven",
66
"version" : ""
77
},
88
"tags" : [
99
{
1010
"name" : "tag1",
11-
"description" : "this is added to openapi tags"
11+
"description" : "it's somethin"
1212
},
1313
{
1414
"name" : "tag1",
15-
"description" : "it's somethin"
15+
"description" : "this is added to openapi tags"
1616
}
1717
],
1818
"paths" : {
@@ -1156,7 +1156,12 @@
11561156
"type" : "string"
11571157
},
11581158
"type" : {
1159-
"$ref" : "#/components/schemas/ServerType"
1159+
"type" : "string",
1160+
"enum" : [
1161+
"PROXY",
1162+
"HIDE_N_SEEK",
1163+
"FFA"
1164+
]
11601165
}
11611166
}
11621167
}
@@ -1195,7 +1200,12 @@
11951200
"type" : "string"
11961201
},
11971202
"type" : {
1198-
"$ref" : "#/components/schemas/ServerType"
1203+
"type" : "string",
1204+
"enum" : [
1205+
"PROXY",
1206+
"HIDE_N_SEEK",
1207+
"FFA"
1208+
]
11991209
}
12001210
}
12011211
}
@@ -1229,7 +1239,12 @@
12291239
"name" : "type",
12301240
"in" : "query",
12311241
"schema" : {
1232-
"$ref" : "#/components/schemas/ServerType"
1242+
"type" : "string",
1243+
"enum" : [
1244+
"PROXY",
1245+
"HIDE_N_SEEK",
1246+
"FFA"
1247+
]
12331248
}
12341249
}
12351250
],
@@ -1261,7 +1276,12 @@
12611276
"schema" : {
12621277
"type" : "array",
12631278
"items" : {
1264-
"$ref" : "#/components/schemas/ServerType"
1279+
"type" : "string",
1280+
"enum" : [
1281+
"PROXY",
1282+
"HIDE_N_SEEK",
1283+
"FFA"
1284+
]
12651285
}
12661286
}
12671287
}
@@ -1299,7 +1319,12 @@
12991319
"name" : "type",
13001320
"in" : "query",
13011321
"schema" : {
1302-
"$ref" : "#/components/schemas/ServerType"
1322+
"type" : "string",
1323+
"enum" : [
1324+
"PROXY",
1325+
"HIDE_N_SEEK",
1326+
"FFA"
1327+
]
13031328
}
13041329
}
13051330
],
@@ -1903,9 +1928,6 @@
19031928
}
19041929
}
19051930
},
1906-
"ServerType" : {
1907-
"type" : "object"
1908-
},
19091931
"byte" : {
19101932
"type" : "object"
19111933
}

tests/test-jex/src/main/resources/public/openapi.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@
190190
"name" : "type",
191191
"in" : "query",
192192
"schema" : {
193-
"$ref" : "#/components/schemas/ServerType"
193+
"type" : "string",
194+
"enum" : [
195+
"PROXY",
196+
"HIDE_N_SEEK",
197+
"FFA"
198+
]
194199
}
195200
}
196201
],
@@ -222,7 +227,12 @@
222227
"schema" : {
223228
"type" : "array",
224229
"items" : {
225-
"$ref" : "#/components/schemas/ServerType"
230+
"type" : "string",
231+
"enum" : [
232+
"PROXY",
233+
"HIDE_N_SEEK",
234+
"FFA"
235+
]
226236
}
227237
}
228238
}
@@ -260,7 +270,12 @@
260270
"name" : "type",
261271
"in" : "query",
262272
"schema" : {
263-
"$ref" : "#/components/schemas/ServerType"
273+
"type" : "string",
274+
"enum" : [
275+
"PROXY",
276+
"HIDE_N_SEEK",
277+
"FFA"
278+
]
264279
}
265280
}
266281
],
@@ -363,11 +378,16 @@
363378
"name" : {
364379
"type" : "string",
365380
"nullable" : false
381+
},
382+
"serverType" : {
383+
"type" : "string",
384+
"enum" : [
385+
"PROXY",
386+
"HIDE_N_SEEK",
387+
"FFA"
388+
]
366389
}
367390
}
368-
},
369-
"ServerType" : {
370-
"type" : "object"
371391
}
372392
}
373393
}

0 commit comments

Comments
 (0)