Skip to content

Commit 440e0c5

Browse files
committed
Add js docs to queries and mutations & Add status code checks
1 parent 4130709 commit 440e0c5

17 files changed

Lines changed: 207 additions & 14 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@povio/openapi-codegen-cli",
3-
"version": "0.4.6",
3+
"version": "0.4.7",
44
"main": "./dist/index.js",
55
"bin": {
66
"openapi-codegen": "./dist/sh.js"

src/generators/const/validation.const.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export const VALIDATION_ERROR_TYPE_TITLE: Record<ValidationErrorType, string> =
66
"missing-path-parameter": "Missing Path Parameters",
77
"not-allowed-inline-enum": "Not Allowed Inline Enums",
88
"not-allowed-circular-schema": "Not Allowed Circular Schemas",
9-
"missing-acl-condition-property": "Missing x-acl Condition Property",
9+
"missing-acl-condition-property": "Missing x-acl Condition Properties",
10+
"missing-status-code": "Missing Status Codes",
1011
};

src/generators/core/endpoints/getEndpointAcl.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export function getEndpointAcl({
2222
const conditionsTypes = Object.keys(item.conditions ?? {}).reduce((acc, name) => {
2323
const propertyType = getEndpointAclConditionPropertyType({ resolver, endpoint, acl, name });
2424
if (!propertyType) {
25-
resolver.validationErrors.push(
26-
getMissingAclConditionPropertyError(name, operation.operationId ?? `${endpoint.method} ${endpoint.path}`),
27-
);
25+
resolver.validationErrors.push(getMissingAclConditionPropertyError(name, operation, endpoint));
2826
return acc;
2927
}
3028
return [...acc, propertyType];

src/generators/core/endpoints/getEndpointsFromOpenAPIDoc.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
124124
expect(endpoints).toEqual([
125125
{
126126
description: "Place a new order in the store",
127+
summary: "Place an order for a pet",
127128
errors: [
128129
{
129130
description: "Invalid input",
@@ -157,6 +158,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
157158
description: "successful operation",
158159
},
159160
tags: ["store"],
161+
responseStatusCodes: ["200", "405"],
160162
},
161163
]);
162164
expect(resolver.getZodSchemas()).toStrictEqual({
@@ -235,6 +237,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
235237
expect(endpoints).toEqual([
236238
{
237239
description: "Update an existing pet by Id",
240+
summary: "Update an existing pet",
238241
errors: [
239242
{
240243
description: "Invalid ID supplied",
@@ -284,9 +287,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
284287
description: "Successful operation",
285288
},
286289
tags: ["pet"],
290+
responseStatusCodes: ["200", "400", "404", "405"],
287291
},
288292
{
289293
description: "Add a new pet to the store",
294+
summary: "Add a new pet to the store",
290295
errors: [
291296
{
292297
description: "Invalid input",
@@ -325,6 +330,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
325330
description: "Successful operation",
326331
},
327332
tags: ["pet"],
333+
responseStatusCodes: ["200", "405"],
328334
},
329335
]);
330336
expect(resolver.getZodSchemas()).toStrictEqual({
@@ -393,6 +399,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
393399
expect(endpoints).toEqual([
394400
{
395401
description: "Update an existing pet by Id",
402+
summary: "Update an existing pet",
396403
errors: [
397404
{
398405
description: "Invalid ID supplied",
@@ -444,6 +451,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
444451
description: "Successful operation",
445452
},
446453
tags: ["pet"],
454+
responseStatusCodes: ["200", "400", "404", "405"],
447455
},
448456
]);
449457
expect(resolver.getZodSchemas()).toStrictEqual({
@@ -589,6 +597,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
589597
expect(endpoints).toEqual([
590598
{
591599
description: "Multiple status values can be provided with comma separated strings",
600+
summary: "Finds Pets by status",
592601
errors: [
593602
{
594603
description: "Invalid status value",
@@ -629,9 +638,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
629638
description: "successful operation",
630639
},
631640
tags: ["pet"],
641+
responseStatusCodes: ["200", "400"],
632642
},
633643
{
634644
description: "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
645+
summary: "Finds Pets by tags",
635646
errors: [
636647
{
637648
description: "Invalid tag value",
@@ -673,6 +684,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
673684
description: "successful operation",
674685
},
675686
tags: ["pet"],
687+
responseStatusCodes: ["200", "400"],
676688
},
677689
]);
678690
expect(resolver.getZodSchemas()).toStrictEqual({
@@ -737,6 +749,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
737749
expect(endpoints).toEqual([
738750
{
739751
description: "Update an existing pet by Id",
752+
summary: "Update an existing pet",
740753
errors: [
741754
{
742755
description: "Invalid ID supplied",
@@ -785,9 +798,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
785798
description: "Successful operation",
786799
},
787800
tags: ["pet"],
801+
responseStatusCodes: ["200", "400", "404", "405"],
788802
},
789803
{
790804
description: "Add a new pet to the store",
805+
summary: "Add a new pet to the store",
791806
errors: [
792807
{
793808
description: "Invalid input",
@@ -826,9 +841,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
826841
description: "Successful operation",
827842
},
828843
tags: ["pet"],
844+
responseStatusCodes: ["200", "405"],
829845
},
830846
{
831847
description: "Multiple status values can be provided with comma separated strings",
848+
summary: "Finds Pets by status",
832849
errors: [
833850
{
834851
description: "Invalid status value",
@@ -883,9 +900,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
883900
description: "successful operation",
884901
},
885902
tags: ["pet"],
903+
responseStatusCodes: ["200", "400"],
886904
},
887905
{
888906
description: "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
907+
summary: "Finds Pets by tags",
889908
errors: [
890909
{
891910
description: "Invalid tag value",
@@ -927,9 +946,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
927946
description: "successful operation",
928947
},
929948
tags: ["pet"],
949+
responseStatusCodes: ["200", "400"],
930950
},
931951
{
932952
description: "Returns a single pet",
953+
summary: "Find pet by ID",
933954
errors: [
934955
{
935956
description: "Invalid ID supplied",
@@ -973,9 +994,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
973994
description: "successful operation",
974995
},
975996
tags: ["pet"],
997+
responseStatusCodes: ["200", "400", "404"],
976998
},
977999
{
9781000
description: "",
1001+
summary: "Updates a pet in the store with form data",
9791002
errors: [
9801003
{
9811004
description: "Invalid input",
@@ -1032,9 +1055,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
10321055
requestFormat: "application/json",
10331056
response: "z.void()",
10341057
tags: ["pet"],
1058+
responseStatusCodes: ["405"],
10351059
},
10361060
{
10371061
description: "delete a pet",
1062+
summary: "Deletes a pet",
10381063
errors: [
10391064
{
10401065
description: "Invalid pet value",
@@ -1079,9 +1104,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
10791104
requestFormat: "application/json",
10801105
response: "z.void()",
10811106
tags: ["pet"],
1107+
responseStatusCodes: ["400"],
10821108
},
10831109
{
10841110
description: "",
1111+
summary: "uploads an image",
10851112
errors: [],
10861113
method: "post",
10871114
operationName: "uploadFile",
@@ -1136,9 +1163,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
11361163
description: "successful operation",
11371164
},
11381165
tags: ["pet"],
1166+
responseStatusCodes: ["200"],
11391167
},
11401168
{
11411169
description: "Returns a map of status codes to quantities",
1170+
summary: "Returns pet inventories by status",
11421171
errors: [],
11431172
method: "get",
11441173
operationName: "getInventory",
@@ -1162,9 +1191,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
11621191
description: "successful operation",
11631192
},
11641193
tags: ["store"],
1194+
responseStatusCodes: ["200"],
11651195
},
11661196
{
11671197
description: "Place a new order in the store",
1198+
summary: "Place an order for a pet",
11681199
errors: [
11691200
{
11701201
description: "Invalid input",
@@ -1200,10 +1231,12 @@ describe("getEndpointsFromOpenAPIDoc", () => {
12001231
description: "successful operation",
12011232
},
12021233
tags: ["store"],
1234+
responseStatusCodes: ["200", "405"],
12031235
},
12041236
{
12051237
description:
12061238
"For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.",
1239+
summary: "Find purchase order by ID",
12071240
errors: [
12081241
{
12091242
description: "Invalid ID supplied",
@@ -1247,10 +1280,12 @@ describe("getEndpointsFromOpenAPIDoc", () => {
12471280
description: "successful operation",
12481281
},
12491282
tags: ["store"],
1283+
responseStatusCodes: ["200", "400", "404"],
12501284
},
12511285
{
12521286
description:
12531287
"For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
1288+
summary: "Delete purchase order by ID",
12541289
errors: [
12551290
{
12561291
description: "Invalid ID supplied",
@@ -1286,9 +1321,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
12861321
requestFormat: "application/json",
12871322
response: "z.void()",
12881323
tags: ["store"],
1324+
responseStatusCodes: ["400", "404"],
12891325
},
12901326
{
12911327
description: "This can only be done by the logged in user.",
1328+
summary: "Create user",
12921329
errors: [],
12931330
method: "post",
12941331
operationName: "createUser",
@@ -1313,9 +1350,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
13131350
response: "z.void()",
13141351
responseFormat: "application/json",
13151352
tags: ["user"],
1353+
responseStatusCodes: ["default"],
13161354
},
13171355
{
13181356
description: "Creates list of users with given input array",
1357+
summary: "Creates list of users with given input array",
13191358
errors: [],
13201359
method: "post",
13211360
operationName: "createUsersWithListInput",
@@ -1344,9 +1383,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
13441383
description: "Successful operation",
13451384
},
13461385
tags: ["user"],
1386+
responseStatusCodes: ["200", "default"],
13471387
},
13481388
{
13491389
description: "",
1390+
summary: "Logs user into the system",
13501391
errors: [
13511392
{
13521393
description: "Invalid username/password supplied",
@@ -1414,9 +1455,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
14141455
},
14151456
},
14161457
tags: ["user"],
1458+
responseStatusCodes: ["200", "400"],
14171459
},
14181460
{
14191461
description: "",
1462+
summary: "Logs out current logged in user session",
14201463
errors: [],
14211464
method: "get",
14221465
operationName: "logoutUser",
@@ -1425,9 +1468,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
14251468
requestFormat: "application/json",
14261469
response: "z.void()",
14271470
tags: ["user"],
1471+
responseStatusCodes: ["default"],
14281472
},
14291473
{
14301474
description: "",
1475+
summary: "Get user by user name",
14311476
errors: [
14321477
{
14331478
description: "Invalid username supplied",
@@ -1470,9 +1515,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
14701515
description: "successful operation",
14711516
},
14721517
tags: ["user"],
1518+
responseStatusCodes: ["200", "400", "404"],
14731519
},
14741520
{
14751521
description: "This can only be done by the logged in user.",
1522+
summary: "Update user",
14761523
errors: [],
14771524
method: "put",
14781525
operationName: "updateUser",
@@ -1522,9 +1569,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
15221569
requestFormat: "application/json",
15231570
response: "z.void()",
15241571
tags: ["user"],
1572+
responseStatusCodes: ["default"],
15251573
},
15261574
{
15271575
description: "This can only be done by the logged in user.",
1576+
summary: "Delete user",
15281577
errors: [
15291578
{
15301579
description: "Invalid username supplied",
@@ -1559,6 +1608,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
15591608
requestFormat: "application/json",
15601609
response: "z.void()",
15611610
tags: ["user"],
1611+
responseStatusCodes: ["400", "404"],
15621612
},
15631613
]);
15641614
expect(resolver.getZodSchemas()).toStrictEqual({
@@ -1690,6 +1740,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
16901740
expect(endpoints).toEqual([
16911741
{
16921742
description: "Multiple status values can be provided with comma separated strings",
1743+
summary: "Finds Pets by status",
16931744
errors: [
16941745
{
16951746
description: "Invalid status value",
@@ -1716,9 +1767,11 @@ describe("getEndpointsFromOpenAPIDoc", () => {
17161767
description: "successful operation",
17171768
},
17181769
tags: ["pet"],
1770+
responseStatusCodes: ["200", "400", "500"],
17191771
},
17201772
{
17211773
description: "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
1774+
summary: "Finds Pets by tags",
17221775
errors: [
17231776
{
17241777
description: "Invalid tag value",
@@ -1740,6 +1793,7 @@ describe("getEndpointsFromOpenAPIDoc", () => {
17401793
},
17411794
description: "successful operation",
17421795
},
1796+
responseStatusCodes: ["200", "400"],
17431797
},
17441798
]);
17451799
expect(resolver.getZodSchemas()).toStrictEqual({

0 commit comments

Comments
 (0)