@scalar/nextjs-openapi 0.2.13 → 0.2.14
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 +9 -0
- package/dist/path.d.ts.map +1 -1
- package/dist/path.js +1 -1
- package/dist/path.js.map +2 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/path.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,UAAU,EAOhB,MAAM,YAAY,CAAA;AAoDnB;;GAEG;AACH,eAAO,MAAM,aAAa,eAAgB,UAAU,WAAW,OAAO,
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,UAAU,EAOhB,MAAM,YAAY,CAAA;AAoDnB;;GAEG;AACH,eAAO,MAAM,aAAa,eAAgB,UAAU,WAAW,OAAO,oCAuCrE,CAAA"}
|
package/dist/path.js
CHANGED
|
@@ -52,7 +52,7 @@ const getPathSchema = (sourceFile, program) => {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
} else if (isVariableStatement(statement)) {
|
|
55
|
-
const method = checkForMethod(statement.declarationList.declarations[0]
|
|
55
|
+
const method = checkForMethod(statement.declarationList.declarations[0]?.name);
|
|
56
56
|
if (method) {
|
|
57
57
|
const { title, description } = getJSDocFromNode(statement);
|
|
58
58
|
const responses = generateResponses(statement, typeChecker);
|
package/dist/path.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/path.ts"],
|
|
4
|
-
"sourcesContent": ["import { generateResponses, getJSDocFromNode, getSchemaFromTypeNode } from '@scalar/ts-to-openapi'\nimport type { OpenAPIV3_1 } from 'openapi-types'\nimport { extname, join } from 'node:path'\nimport {\n type Identifier,\n type ParameterDeclaration,\n type Program,\n type SourceFile,\n isFunctionDeclaration,\n isIdentifier,\n isParameter,\n isPropertySignature,\n isTypeLiteralNode,\n isVariableStatement,\n} from 'typescript'\n\n/** Check if identifier is a supported http method */\nconst checkForMethod = (identifier: Identifier) => {\n const method = identifier?.escapedText?.toLowerCase()\n\n return method?.match(/^(get|post|put|patch|delete|head|options)$/) ? (method as OpenAPIV3_1.HttpMethods) : null\n}\n\nconst fileNameResolver = (source: string, target: string) => {\n const sourceExt = extname(source)\n const targetExt = extname(target)\n\n const targetRelative = target + (targetExt ? '' : sourceExt)\n const targetPath = join(source.replace(/\\/([^/]+)$/, ''), targetRelative)\n\n return targetPath\n}\n\n/**\n * Takes a parameter node and returns a path parameter schema\n */\nconst extractPathParams = (node: ParameterDeclaration, program: Program): OpenAPIV3_1.ParameterObject[] => {\n // Traverse to the params with type guards\n if (\n node &&\n isParameter(node) &&\n node.type &&\n isTypeLiteralNode(node.type) &&\n node.type.members[0] &&\n isPropertySignature(node.type.members[0]) &&\n isIdentifier(node.type.members[0].name) &&\n node.type.members[0].name.escapedText === 'params' &&\n node.type.members[0].type &&\n isTypeLiteralNode(node.type.members[0].type)\n ) {\n return node.type.members[0].type?.members.flatMap((member) => {\n if (!isPropertySignature(member) || !member.type) {\n return []\n }\n\n return {\n name: member.name?.getText(),\n schema: getSchemaFromTypeNode(member.type, program, fileNameResolver),\n in: 'path',\n } as OpenAPIV3_1.ParameterObject\n })\n }\n\n return []\n}\n\n/**\n * Traverse the typescript file and extract as much info as we can for the openapi spec\n */\nexport const getPathSchema = (sourceFile: SourceFile, program: Program) => {\n const path: OpenAPIV3_1.PathsObject = {}\n const typeChecker = program.getTypeChecker()\n\n sourceFile.statements.forEach((statement) => {\n // Function\n if (isFunctionDeclaration(statement) && statement.name) {\n const method = checkForMethod(statement.name)\n if (method) {\n const { title, description } = getJSDocFromNode(statement)\n const parameters = extractPathParams(statement.parameters[1], program)\n const responses = generateResponses(statement.body, typeChecker)\n\n path[method] = {\n summary: title,\n description,\n parameters,\n responses,\n } as OpenAPIV3_1.OperationObject\n }\n }\n\n // TODO: variables\n else if (isVariableStatement(statement)) {\n const method = checkForMethod(statement.declarationList.declarations[0]
|
|
5
|
-
"mappings": "AAAA,SAAS,mBAAmB,kBAAkB,6BAA6B;AAE3E,SAAS,SAAS,YAAY;AAC9B;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,MAAM,iBAAiB,CAAC,
|
|
4
|
+
"sourcesContent": ["import { generateResponses, getJSDocFromNode, getSchemaFromTypeNode } from '@scalar/ts-to-openapi'\nimport type { OpenAPIV3_1 } from 'openapi-types'\nimport { extname, join } from 'node:path'\nimport {\n type Identifier,\n type ParameterDeclaration,\n type Program,\n type SourceFile,\n isFunctionDeclaration,\n isIdentifier,\n isParameter,\n isPropertySignature,\n isTypeLiteralNode,\n isVariableStatement,\n} from 'typescript'\n\n/** Check if identifier is a supported http method */\nconst checkForMethod = (identifier: Pick<Identifier, 'escapedText'> | undefined) => {\n const method = identifier?.escapedText?.toLowerCase()\n\n return method?.match(/^(get|post|put|patch|delete|head|options)$/) ? (method as OpenAPIV3_1.HttpMethods) : null\n}\n\nconst fileNameResolver = (source: string, target: string) => {\n const sourceExt = extname(source)\n const targetExt = extname(target)\n\n const targetRelative = target + (targetExt ? '' : sourceExt)\n const targetPath = join(source.replace(/\\/([^/]+)$/, ''), targetRelative)\n\n return targetPath\n}\n\n/**\n * Takes a parameter node and returns a path parameter schema\n */\nconst extractPathParams = (node: ParameterDeclaration | undefined, program: Program): OpenAPIV3_1.ParameterObject[] => {\n // Traverse to the params with type guards\n if (\n node &&\n isParameter(node) &&\n node.type &&\n isTypeLiteralNode(node.type) &&\n node.type.members[0] &&\n isPropertySignature(node.type.members[0]) &&\n isIdentifier(node.type.members[0].name) &&\n node.type.members[0].name.escapedText === 'params' &&\n node.type.members[0].type &&\n isTypeLiteralNode(node.type.members[0].type)\n ) {\n return node.type.members[0].type?.members.flatMap((member) => {\n if (!isPropertySignature(member) || !member.type) {\n return []\n }\n\n return {\n name: member.name?.getText(),\n schema: getSchemaFromTypeNode(member.type, program, fileNameResolver),\n in: 'path',\n } as OpenAPIV3_1.ParameterObject\n })\n }\n\n return []\n}\n\n/**\n * Traverse the typescript file and extract as much info as we can for the openapi spec\n */\nexport const getPathSchema = (sourceFile: SourceFile, program: Program) => {\n const path: OpenAPIV3_1.PathsObject = {}\n const typeChecker = program.getTypeChecker()\n\n sourceFile.statements.forEach((statement) => {\n // Function\n if (isFunctionDeclaration(statement) && statement.name) {\n const method = checkForMethod(statement.name)\n if (method) {\n const { title, description } = getJSDocFromNode(statement)\n const parameters = extractPathParams(statement.parameters[1], program)\n const responses = generateResponses(statement.body, typeChecker)\n\n path[method] = {\n summary: title,\n description,\n parameters,\n responses,\n } as OpenAPIV3_1.OperationObject\n }\n }\n\n // TODO: variables\n else if (isVariableStatement(statement)) {\n // TODO: Remove this typecast. It looks totally incompatible\n const method = checkForMethod(statement.declarationList.declarations[0]?.name as Identifier)\n if (method) {\n const { title, description } = getJSDocFromNode(statement)\n const responses = generateResponses(statement, typeChecker)\n path[method] = {\n summary: title,\n description,\n responses,\n } as OpenAPIV3_1.OperationObject\n }\n }\n })\n\n return path\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB,kBAAkB,6BAA6B;AAE3E,SAAS,SAAS,YAAY;AAC9B;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,MAAM,iBAAiB,CAAC,eAA4D;AAClF,QAAM,SAAS,YAAY,aAAa,YAAY;AAEpD,SAAO,Q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,cAAM,EAAE,OAAO,YAAY,IAAI,iBAAiB,SAAS;AACzD,cAAM,aAAa,kBAAkB,UAAU,WAAW,CAAC,GAAG,OAAO;AACrE,cAAM,YAAY,kBAAkB,UAAU,MAAM,WAAW;AAE/D,aAAK,MAAM,IAAI;AAAA,UACb,SAAS;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,WAGS,oBAAoB,SAAS,GAAG;AAEvC,YAAM,SAAS,eAAe,UAAU,gBAAgB,aAAa,CAAC,GAAG,IAAkB;AAC3F,UAAI,QAAQ;AACV,cAAM,EAAE,OAAO,YAAY,IAAI,iBAAiB,SAAS;AACzD,cAAM,YAAY,kBAAkB,WAAW,WAAW;AAC1D,aAAK,MAAM,IAAI;AAAA,UACb,SAAS;AAAA,UACT;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"scalar",
|
|
17
17
|
"references"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.14",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"fast-glob": "^3.3.2",
|
|
37
|
+
"@scalar/nextjs-api-reference": "0.8.14",
|
|
37
38
|
"@scalar/ts-to-openapi": "0.1.0",
|
|
38
|
-
"@scalar/
|
|
39
|
-
"@scalar/types": "0.2.10"
|
|
39
|
+
"@scalar/types": "0.2.11"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^22.9.0",
|