next-openapi-gen 0.6.8 → 0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -444,6 +444,12 @@ export async function PUT() {}
444
444
 
445
445
  ```json
446
446
  {
447
+ "defaultResponseSet": "common",
448
+ "responseSets": {
449
+ "common": ["400", "500"],
450
+ "auth": ["400", "401", "403", "500"],
451
+ "public": ["400", "500"]
452
+ },
447
453
  "errorConfig": {
448
454
  "template": {
449
455
  "type": "object",
@@ -451,13 +457,48 @@ export async function PUT() {}
451
457
  "error": {
452
458
  "type": "string",
453
459
  "example": "{{ERROR_MESSAGE}}"
460
+ },
461
+ "code": {
462
+ "type": "string",
463
+ "example": "{{ERROR_CODE}}"
454
464
  }
455
465
  }
456
466
  },
457
467
  "codes": {
458
- "invalid_request": {
459
- "description": "Invalid request",
460
- "variables": { "ERROR_MESSAGE": "Validation failed" }
468
+ "400": {
469
+ "description": "Bad Request",
470
+ "variables": {
471
+ "ERROR_MESSAGE": "Invalid request parameters",
472
+ "ERROR_CODE": "BAD_REQUEST"
473
+ }
474
+ },
475
+ "401": {
476
+ "description": "Unauthorized",
477
+ "variables": {
478
+ "ERROR_MESSAGE": "Authentication required",
479
+ "ERROR_CODE": "UNAUTHORIZED"
480
+ }
481
+ },
482
+ "403": {
483
+ "description": "Forbidden",
484
+ "variables": {
485
+ "ERROR_MESSAGE": "Access denied",
486
+ "ERROR_CODE": "FORBIDDEN"
487
+ }
488
+ },
489
+ "404": {
490
+ "description": "Not Found",
491
+ "variables": {
492
+ "ERROR_MESSAGE": "Resource not found",
493
+ "ERROR_CODE": "NOT_FOUND"
494
+ }
495
+ },
496
+ "500": {
497
+ "description": "Internal Server Error",
498
+ "variables": {
499
+ "ERROR_MESSAGE": "An unexpected error occurred",
500
+ "ERROR_CODE": "INTERNAL_ERROR"
501
+ }
461
502
  }
462
503
  }
463
504
  }
@@ -92,15 +92,15 @@ async function installDependencies(ui) {
92
92
  function extendOpenApiTemplate(spec, options) {
93
93
  spec.ui = options.ui ?? spec.ui;
94
94
  spec.docsUrl = options.docsUrl ?? spec.docsUrl;
95
- spec.schemaType = options.schemaType ?? spec.schemaType;
95
+ spec.schemaType = options.schema ?? spec.schemaType;
96
96
  }
97
97
  export async function init(options) {
98
- const { ui, docsUrl, schemaType } = options;
98
+ const { ui } = options;
99
99
  spinner.start();
100
100
  try {
101
101
  const outputPath = path.join(process.cwd(), "next.openapi.json");
102
102
  const template = { ...openapiTemplate };
103
- extendOpenApiTemplate(template, { docsUrl, ui, schemaType });
103
+ extendOpenApiTemplate(template, options);
104
104
  await fse.writeJson(outputPath, template, { spaces: 2 });
105
105
  spinner.succeed(`Created OpenAPI template in next.openapi.json`);
106
106
  createDocsPage(ui, template.outputFile);
package/dist/index.js CHANGED
@@ -13,7 +13,9 @@ program
13
13
  .choices(["scalar", "swagger", "redoc", "stoplight", "rapidoc"])
14
14
  .default("swagger"))
15
15
  .option("-u, --docs-url <url>", "Specify the docs URL", "api-docs")
16
- .option("-s, --schema <schemaType>", "Specify the schema type", "zod")
16
+ .addOption(new Option("-s, --schema <schemaType>", "Specify the schema tool")
17
+ .choices(["zod", "typescript"])
18
+ .default("zod"))
17
19
  .description("Initialize a openapi specification")
18
20
  .action(init);
19
21
  program
@@ -126,6 +126,10 @@ export class OpenApiGenerator {
126
126
  return JSON.parse(result);
127
127
  }
128
128
  guessHttpStatus(errorCode) {
129
+ const numericCode = parseInt(errorCode);
130
+ if (numericCode >= 100 && numericCode < 600) {
131
+ return numericCode;
132
+ }
129
133
  const statusMap = {
130
134
  bad: 400,
131
135
  invalid: 400,
@@ -23,42 +23,64 @@ export default {
23
23
  defaultResponseSet: "common",
24
24
  responseSets: {
25
25
  common: ["400", "500"],
26
- auth: ["401"],
26
+ auth: ["400", "401", "403", "500"],
27
+ public: ["400", "500"],
27
28
  },
28
29
  errorConfig: {
29
30
  template: {
30
31
  type: "object",
31
32
  properties: {
32
- success: {
33
- type: "boolean",
34
- example: false,
35
- },
36
33
  error: {
37
34
  type: "string",
38
35
  example: "{{ERROR_MESSAGE}}",
39
36
  },
37
+ code: {
38
+ type: "string",
39
+ example: "{{ERROR_CODE}}",
40
+ },
40
41
  },
41
42
  },
42
43
  codes: {
43
- invalid: {
44
- description: "Bad request",
45
- httpStatus: 400,
44
+ "400": {
45
+ description: "Bad Request",
46
46
  variables: {
47
- ERROR_MESSAGE: "Validation error",
47
+ ERROR_MESSAGE: "Invalid request parameters",
48
+ ERROR_CODE: "BAD_REQUEST",
48
49
  },
49
50
  },
50
- auth: {
51
+ "401": {
51
52
  description: "Unauthorized",
52
- httpStatus: 401,
53
53
  variables: {
54
- ERROR_MESSAGE: "Unathorized",
54
+ ERROR_MESSAGE: "Authentication required",
55
+ ERROR_CODE: "UNAUTHORIZED",
56
+ },
57
+ },
58
+ "403": {
59
+ description: "Forbidden",
60
+ variables: {
61
+ ERROR_MESSAGE: "Access denied",
62
+ ERROR_CODE: "FORBIDDEN",
63
+ },
64
+ },
65
+ "404": {
66
+ description: "Not Found",
67
+ variables: {
68
+ ERROR_MESSAGE: "Resource not found",
69
+ ERROR_CODE: "NOT_FOUND",
70
+ },
71
+ },
72
+ "409": {
73
+ description: "Conflict",
74
+ variables: {
75
+ ERROR_MESSAGE: "Resource already exists",
76
+ ERROR_CODE: "CONFLICT",
55
77
  },
56
78
  },
57
- server_error: {
58
- description: "Internal server error",
59
- httpStatus: 500,
79
+ "500": {
80
+ description: "Internal Server Error",
60
81
  variables: {
61
- ERROR_MESSAGE: "Something went wrong",
82
+ ERROR_MESSAGE: "An unexpected error occurred",
83
+ ERROR_CODE: "INTERNAL_ERROR",
62
84
  },
63
85
  },
64
86
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-openapi-gen",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "Automatically generate OpenAPI 3.0 documentation from Next.js projects, with support for Zod schemas and TypeScript types.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",