@scalar/nextjs-openapi 0.1.19 → 0.2.3
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 +37 -0
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +1 -1
- package/dist/openapi.js.map +2 -2
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @scalar/nextjs-openapi
|
|
2
2
|
|
|
3
|
+
## 0.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 66e2768: Removed app router route group from url
|
|
8
|
+
- @scalar/nextjs-api-reference@0.8.3
|
|
9
|
+
- @scalar/ts-to-openapi@0.1.0
|
|
10
|
+
- @scalar/types@0.2.1
|
|
11
|
+
|
|
12
|
+
## 0.2.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [e660779]
|
|
17
|
+
- @scalar/nextjs-api-reference@0.8.3
|
|
18
|
+
|
|
19
|
+
## 0.2.1
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [4440949]
|
|
24
|
+
- @scalar/types@0.2.1
|
|
25
|
+
- @scalar/nextjs-api-reference@0.8.1
|
|
26
|
+
|
|
27
|
+
## 0.2.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 483ca93: chore: require Node 20 (or above)
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Updated dependencies [483ca93]
|
|
36
|
+
- @scalar/ts-to-openapi@0.1.0
|
|
37
|
+
- @scalar/nextjs-api-reference@0.8.0
|
|
38
|
+
- @scalar/types@0.2.0
|
|
39
|
+
|
|
3
40
|
## 0.1.19
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/dist/openapi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAE5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAa9C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;AA+BtC;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,YAAY,aAAa;
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAE5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAa9C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;AA+BtC;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,YAAY,aAAa;eAoCxB,WAAW;CAe/B,CAAA"}
|
package/dist/openapi.js
CHANGED
|
@@ -46,7 +46,7 @@ const OpenAPI = (config = {}) => {
|
|
|
46
46
|
const sourceFile = program.getSourceFile(fileName);
|
|
47
47
|
if (sourceFile) {
|
|
48
48
|
const resp = getPathSchema(sourceFile, program);
|
|
49
|
-
const rawPath = fileName.replace(/^(?:src\/)?app|\/route\.ts$/g, "").replace(/\[/g, "{").replace(/]/g, "}");
|
|
49
|
+
const rawPath = fileName.replace(/^(?:src\/)?app|\/route\.ts$/g, "").replace(/\[/g, "{").replace(/\/\(\w+\)/g, "").replace(/]/g, "}");
|
|
50
50
|
const path = rawPath.startsWith("/") ? rawPath : "/" + rawPath;
|
|
51
51
|
spec.paths[path] = resp;
|
|
52
52
|
}
|
package/dist/openapi.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/openapi.ts"],
|
|
4
|
-
"sourcesContent": ["import { readFileSync } from 'node:fs'\nimport { ApiReference } from '@scalar/nextjs-api-reference'\nimport type { ApiReferenceConfiguration } from '@scalar/types/api-reference'\nimport { sync } from 'fast-glob'\nimport type { NextRequest } from 'next/server'\nimport type { OpenAPIV3_1 } from 'openapi-types'\nimport {\n type CompilerHost,\n JSDocParsingMode,\n ScriptKind,\n ScriptTarget,\n createProgram,\n createSourceFile,\n} from 'typescript'\n\nimport { getPathSchema } from './path'\n\n/**\n * Scalar OpenAPI config\n */\nexport type OpenAPIConfig = {\n /**\n * The base directory for your API files\n * @default 'app/api'\n */\n apiDirectory?: string\n} & Partial<ApiReferenceConfiguration>\n\n// TODO switch to watcher\n// @see https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#writing-an-incremental-program-watcher\nconst compilerHost: CompilerHost = {\n fileExists: () => true,\n getCanonicalFileName: (filename) => filename,\n getCurrentDirectory: () => '',\n getDefaultLibFileName: () => '',\n getNewLine: () => '\\n',\n getSourceFile: (filename) =>\n createSourceFile(filename, readFileSync(filename).toString(), ScriptTarget.Latest, false, ScriptKind.TS),\n jsDocParsingMode: JSDocParsingMode.ParseAll,\n readFile: () => undefined,\n useCaseSensitiveFileNames: () => true,\n writeFile: () => null,\n}\n\n/** OpenAPI 3.1.0 Spec */\nconst spec: OpenAPIV3_1.Document = {\n openapi: '3.1.0',\n info: {\n title: `${process.env.npm_package_name} - Next.js OpenAPI Spec by Scalar`,\n description:\n process.env.npm_package_description ||\n 'This file has been autogenerated, check out the docs to see how to customize these options',\n version: process.env.npm_package_version || '0.0.0',\n },\n paths: {},\n}\n\n/**\n * Scalar Next.js OpenAPI schema generation\n *\n * Handles both the schema generation as well as the references\n *\n * TODO:\n * - Docs\n * - file watcher\n * - caching\n */\nexport const OpenAPI = (config: OpenAPIConfig = {}) => {\n const apiDirectory = config.apiDirectory ?? 'app/api'\n /** All ts files required for the schema */\n const programFileNames = sync(apiDirectory + '/**/*.ts')\n /** Specific route files to generate paths */\n const routeFileNames = sync(apiDirectory + '/**/route.ts')\n\n const program = createProgram(\n programFileNames,\n {\n noResolve: true,\n target: ScriptTarget.Latest,\n },\n compilerHost,\n )\n\n // Loop over all non scalar files to extract openapi data using AST\n routeFileNames.forEach((fileName) => {\n const sourceFile = program.getSourceFile(fileName)\n\n if (sourceFile) {\n const resp = getPathSchema(sourceFile, program)\n\n // Grab the path from the fileName\n const rawPath = fileName\n .replace(/^(?:src\\/)?app|\\/route\\.ts$/g, '')\n .replace(/\\[/g, '{')\n .replace(/]/g, '}')\n const path = rawPath.startsWith('/') ? rawPath : '/' + rawPath\n\n spec.paths[path] = resp\n }\n })\n\n return {\n GET: async (req: NextRequest) => {\n // OpenAPI Schema JSON\n if (req.nextUrl.pathname.endsWith('.json')) {\n // Just grabbing the origin here but we can be smarter and look for the greatest common few segments\n spec.servers = [{ url: req.nextUrl.origin }]\n\n return Response.json(spec)\n }\n // References\n\n return await ApiReference({\n url: req.nextUrl.pathname + '/schema.json',\n })()\n },\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAE7B,SAAS,YAAY;AAGrB;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB;AAe9B,MAAM,eAA6B;AAAA,EACjC,YAAY,MAAM;AAAA,EAClB,sBAAsB,CAAC,aAAa;AAAA,EACpC,qBAAqB,MAAM;AAAA,EAC3B,uBAAuB,MAAM;AAAA,EAC7B,YAAY,MAAM;AAAA,EAClB,eAAe,CAAC,aACd,iBAAiB,UAAU,aAAa,QAAQ,EAAE,SAAS,GAAG,aAAa,QAAQ,OAA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E;AAAA,IACL;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import { readFileSync } from 'node:fs'\nimport { ApiReference } from '@scalar/nextjs-api-reference'\nimport type { ApiReferenceConfiguration } from '@scalar/types/api-reference'\nimport { sync } from 'fast-glob'\nimport type { NextRequest } from 'next/server'\nimport type { OpenAPIV3_1 } from 'openapi-types'\nimport {\n type CompilerHost,\n JSDocParsingMode,\n ScriptKind,\n ScriptTarget,\n createProgram,\n createSourceFile,\n} from 'typescript'\n\nimport { getPathSchema } from './path'\n\n/**\n * Scalar OpenAPI config\n */\nexport type OpenAPIConfig = {\n /**\n * The base directory for your API files\n * @default 'app/api'\n */\n apiDirectory?: string\n} & Partial<ApiReferenceConfiguration>\n\n// TODO switch to watcher\n// @see https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#writing-an-incremental-program-watcher\nconst compilerHost: CompilerHost = {\n fileExists: () => true,\n getCanonicalFileName: (filename) => filename,\n getCurrentDirectory: () => '',\n getDefaultLibFileName: () => '',\n getNewLine: () => '\\n',\n getSourceFile: (filename) =>\n createSourceFile(filename, readFileSync(filename).toString(), ScriptTarget.Latest, false, ScriptKind.TS),\n jsDocParsingMode: JSDocParsingMode.ParseAll,\n readFile: () => undefined,\n useCaseSensitiveFileNames: () => true,\n writeFile: () => null,\n}\n\n/** OpenAPI 3.1.0 Spec */\nconst spec: OpenAPIV3_1.Document = {\n openapi: '3.1.0',\n info: {\n title: `${process.env.npm_package_name} - Next.js OpenAPI Spec by Scalar`,\n description:\n process.env.npm_package_description ||\n 'This file has been autogenerated, check out the docs to see how to customize these options',\n version: process.env.npm_package_version || '0.0.0',\n },\n paths: {},\n}\n\n/**\n * Scalar Next.js OpenAPI schema generation\n *\n * Handles both the schema generation as well as the references\n *\n * TODO:\n * - Docs\n * - file watcher\n * - caching\n */\nexport const OpenAPI = (config: OpenAPIConfig = {}) => {\n const apiDirectory = config.apiDirectory ?? 'app/api'\n /** All ts files required for the schema */\n const programFileNames = sync(apiDirectory + '/**/*.ts')\n /** Specific route files to generate paths */\n const routeFileNames = sync(apiDirectory + '/**/route.ts')\n\n const program = createProgram(\n programFileNames,\n {\n noResolve: true,\n target: ScriptTarget.Latest,\n },\n compilerHost,\n )\n\n // Loop over all non scalar files to extract openapi data using AST\n routeFileNames.forEach((fileName) => {\n const sourceFile = program.getSourceFile(fileName)\n\n if (sourceFile) {\n const resp = getPathSchema(sourceFile, program)\n\n // Grab the path from the fileName\n const rawPath = fileName\n .replace(/^(?:src\\/)?app|\\/route\\.ts$/g, '')\n .replace(/\\[/g, '{')\n .replace(/\\/\\(\\w+\\)/g, '')\n .replace(/]/g, '}')\n const path = rawPath.startsWith('/') ? rawPath : '/' + rawPath\n\n spec.paths[path] = resp\n }\n })\n\n return {\n GET: async (req: NextRequest) => {\n // OpenAPI Schema JSON\n if (req.nextUrl.pathname.endsWith('.json')) {\n // Just grabbing the origin here but we can be smarter and look for the greatest common few segments\n spec.servers = [{ url: req.nextUrl.origin }]\n\n return Response.json(spec)\n }\n // References\n\n return await ApiReference({\n url: req.nextUrl.pathname + '/schema.json',\n })()\n },\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAE7B,SAAS,YAAY;AAGrB;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB;AAe9B,MAAM,eAA6B;AAAA,EACjC,YAAY,MAAM;AAAA,EAClB,sBAAsB,CAAC,aAAa;AAAA,EACpC,qBAAqB,MAAM;AAAA,EAC3B,uBAAuB,MAAM;AAAA,EAC7B,YAAY,MAAM;AAAA,EAClB,eAAe,CAAC,aACd,iBAAiB,UAAU,aAAa,QAAQ,EAAE,SAAS,GAAG,aAAa,QAAQ,OAAO,WAAW,EAAE;AAAA,EACzG,kBAAkB,iBAAiB;AAAA,EACnC,UAAU,MAAM;AAAA,EAChB,2BAA2B,MAAM;AAAA,E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ANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"scalar",
|
|
17
17
|
"references"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.
|
|
19
|
+
"version": "0.2.3",
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=20"
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"fast-glob": "^3.3.2",
|
|
37
|
-
"@scalar/nextjs-api-reference": "0.
|
|
38
|
-
"@scalar/ts-to-openapi": "0.0
|
|
39
|
-
"@scalar/types": "0.1
|
|
37
|
+
"@scalar/nextjs-api-reference": "0.8.3",
|
|
38
|
+
"@scalar/ts-to-openapi": "0.1.0",
|
|
39
|
+
"@scalar/types": "0.2.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^20.17.10",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@types/react-dom": "^19.0.2",
|
|
45
45
|
"next": "^15.2.3",
|
|
46
46
|
"openapi-types": "^12.1.3",
|
|
47
|
-
"@scalar/build-tooling": "0.1
|
|
47
|
+
"@scalar/build-tooling": "0.2.1"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "scalar-build-esbuild",
|