@scalar/nextjs-openapi 0.2.13 → 0.2.16

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,31 @@
1
1
  # @scalar/nextjs-openapi
2
2
 
3
+ ## 0.2.16
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [6a88108]
8
+ - @scalar/types@0.2.12
9
+ - @scalar/nextjs-api-reference@0.8.16
10
+ - @scalar/ts-to-openapi@0.1.0
11
+
12
+ ## 0.2.15
13
+
14
+ ### Patch Changes
15
+
16
+ - @scalar/nextjs-api-reference@0.8.15
17
+ - @scalar/ts-to-openapi@0.1.0
18
+ - @scalar/types@0.2.11
19
+
20
+ ## 0.2.14
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [ccf875a]
25
+ - Updated dependencies [94d6d0c]
26
+ - @scalar/types@0.2.11
27
+ - @scalar/nextjs-api-reference@0.8.14
28
+
3
29
  ## 0.2.13
4
30
 
5
31
  ### Patch Changes
package/README.md CHANGED
@@ -31,5 +31,5 @@ You just need to drop this file into the `app/api/openapi/[[...openapi]]` folder
31
31
  // app/api/openapi/[[...slug]]/route.ts
32
32
  import { OpenAPI } from '@scalar/nextjs-openapi'
33
33
 
34
- export const GET = OpenAPI()
34
+ export const GET = OpenAPI().GET
35
35
  ```
@@ -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,oCAsCrE,CAAA"}
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].name);
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].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,eAA2B;AACjD,QAAM,SAAS,YAAY,aAAa,YAAY;AAEpD,SAAO,QAAQ,MAAM,4CAA4C,IAAK,SAAqC;AAC7G;A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AAS;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;AACvC,YAAM,SAAS,eAAe,UAAU,gBAAgB,aAAa,CAAC,EAAE,IAAkB;AAC1F,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;",
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,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U,IAAI;AAC5C,UAAI,QAAQ;AACV,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.13",
19
+ "version": "0.2.16",
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/ts-to-openapi": "0.1.0",
38
- "@scalar/nextjs-api-reference": "0.8.13",
39
- "@scalar/types": "0.2.10"
37
+ "@scalar/nextjs-api-reference": "0.8.16",
38
+ "@scalar/types": "0.2.12",
39
+ "@scalar/ts-to-openapi": "0.1.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "^22.9.0",
@@ -44,7 +44,7 @@
44
44
  "@types/react-dom": "^19.1.6",
45
45
  "next": "^15.3.3",
46
46
  "openapi-types": "^12.1.3",
47
- "@scalar/build-tooling": "0.2.4"
47
+ "@scalar/build-tooling": "0.2.6"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "scalar-build-esbuild",