@scalar/nextjs-openapi 0.3.39 → 0.3.40

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scalar/nextjs-openapi
2
2
 
3
+ ## 0.3.40
4
+
5
+ ### Patch Changes
6
+
7
+ - [#10135](https://github.com/scalar/scalar/pull/10135): Extract parameters and JSON responses from variable handlers, including concise arrows and multiple declarations. Safely read declaration names and JSDoc.
8
+
3
9
  ## 0.3.39
4
10
 
5
11
  ## 0.3.38
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,UAAU,EAOhB,MAAM,YAAY,CAAA;AAoDnB;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,YAAY,UAAU,EAAE,SAAS,OAAO,KAAG,WAAW,CAAC,WAuCpF,CAAA"}
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,UAAU,EAShB,MAAM,YAAY,CAAA;AAoDnB;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,YAAY,UAAU,EAAE,SAAS,OAAO,KAAG,WAAW,CAAC,WA8CpF,CAAA"}
package/dist/path.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { extname, join } from 'node:path';
2
2
  import { generateResponses, getJSDocFromNode, getSchemaFromTypeNode } from '@scalar/ts-to-openapi';
3
- import { isFunctionDeclaration, isIdentifier, isParameter, isPropertySignature, isTypeLiteralNode, isVariableStatement, } from 'typescript';
3
+ import { isArrowFunction, isFunctionDeclaration, isFunctionExpression, isIdentifier, isParameter, isPropertySignature, isTypeLiteralNode, isVariableStatement, } from 'typescript';
4
4
  /** Check if identifier is a supported http method */
5
5
  const checkForMethod = (identifier) => {
6
6
  const method = identifier?.escapedText?.toLowerCase();
@@ -63,17 +63,21 @@ export const getPathSchema = (sourceFile, program) => {
63
63
  };
64
64
  }
65
65
  }
66
- // TODO: variables
66
+ // A statement can declare several route handlers alongside other variables.
67
67
  else if (isVariableStatement(statement)) {
68
- // TODO: Remove this typecast. It looks totally incompatible
69
- const method = checkForMethod(statement.declarationList.declarations[0]?.name);
70
- if (method) {
68
+ for (const declaration of statement.declarationList.declarations) {
69
+ const method = isIdentifier(declaration.name) ? checkForMethod(declaration.name) : null;
70
+ if (!method) {
71
+ continue;
72
+ }
71
73
  const { title, description } = getJSDocFromNode(statement);
72
- const responses = generateResponses(statement, typeChecker);
74
+ const initializer = declaration.initializer;
75
+ const handler = initializer && (isArrowFunction(initializer) || isFunctionExpression(initializer)) ? initializer : undefined;
73
76
  path[method] = {
74
77
  summary: title,
75
78
  description,
76
- responses,
79
+ ...(handler ? { parameters: extractPathParams(handler.parameters[1], program) } : {}),
80
+ responses: generateResponses(handler, typeChecker),
77
81
  };
78
82
  }
79
83
  }
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "scalar",
17
17
  "references"
18
18
  ],
19
- "version": "0.3.39",
19
+ "version": "0.3.40",
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
@@ -34,9 +34,9 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "fast-glob": "^3.3.3",
37
- "@scalar/nextjs-api-reference": "0.11.18",
38
- "@scalar/types": "0.19.0",
39
- "@scalar/ts-to-openapi": "0.2.4"
37
+ "@scalar/nextjs-api-reference": "0.12.0",
38
+ "@scalar/ts-to-openapi": "0.2.5",
39
+ "@scalar/types": "0.20.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "^24.1.0",