Skip to content

Commit c5c2056

Browse files
author
DylanBulmer
committed
remove trailing slash & fix missing .d.ts files
1 parent 6a862f6 commit c5c2056

5 files changed

Lines changed: 57 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"scripts": {
88
"test": "jest --config jest.config.json --passWithNoTests --coverage",
9-
"build": "yarn clean && swc src -d lib && cp package.json lib/",
9+
"build": "yarn clean && swc src -d lib && tsc && cp package.json lib/",
1010
"clean": "rm -rf ./lib",
1111
"format": "prettier --write \"src/**/*.(ts|js)\"",
1212
"lint": "eslint -c .eslintrc.json --ignore-path .eslintignore --ext .ts src",

src/__tests__/DirectoryIndexRoute/DirectoryIndexRoute.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ test("Index routes", () => {
1919
// url: "/docs/elements"
2020
},
2121
}).then(doc => {
22-
// check if the static route exists
23-
expect(Object.keys(doc.paths as OpenAPIV3_1.PathsObject)).toContain(
24-
"/",
22+
// check if the root index route exists
23+
expect(Object.keys(doc.paths as OpenAPIV3_1.PathsObject)).toContain("/");
24+
expect((doc.paths as OpenAPIV3_1.PathsObject)["/"]?.get?.description).toBe(
25+
"Testing index route",
2526
);
2627

27-
// check if static route's GET description is set
28+
// check if the nested index route exists
29+
expect(Object.keys(doc.paths as OpenAPIV3_1.PathsObject)).toContain(
30+
"/test",
31+
);
2832
expect(
29-
(doc.paths as OpenAPIV3_1.PathsObject)["/"]?.get?.description,
30-
).toBe("Testing index route");
33+
(doc.paths as OpenAPIV3_1.PathsObject)["/test"]?.get?.description,
34+
).toBe("Testing nested index route");
3135
});
3236
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Operation } from "../../../../types/Route";
2+
3+
export const GET: Operation =
4+
/* business middleware not expressible by OpenAPI documentation goes here */
5+
(req, res) => {
6+
res.status(200).json({ detail: { message: "OK" } });
7+
};
8+
9+
// 3.0 specification
10+
GET.apiDoc = {
11+
description: "Testing nested index route",
12+
tags: ["TEST"],
13+
responses: {
14+
"200": {
15+
$ref: "#/components/responses/200",
16+
content: {
17+
"application/json": {
18+
schema: {
19+
properties: {
20+
detail: {
21+
type: "object",
22+
properties: {
23+
message: {
24+
type: "string",
25+
examples: ["OK"],
26+
},
27+
},
28+
},
29+
},
30+
},
31+
},
32+
},
33+
},
34+
},
35+
};

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,14 @@ const getFiles = async function* getFiles(
135135
expressUrl = `${basePath}:${routeName}`;
136136
openapiUrl = `${basePath}{${routeName}}`;
137137
} else if (routeName === "index") {
138-
expressUrl = `${basePath}`;
139-
openapiUrl = `${basePath}`;
138+
if (basePath === "/") {
139+
expressUrl = `${basePath}`;
140+
openapiUrl = `${basePath}`;
141+
} else {
142+
const base = basePath.substring(0, basePath.length - 1);
143+
expressUrl = `${base}`;
144+
openapiUrl = `${base}`;
145+
}
140146
} else {
141147
expressUrl = `${basePath}${routeName}`;
142148
openapiUrl = `${basePath}${routeName}`;

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"module": "commonjs", /* Specify what module code is generated. */
2828
// "rootDir": "./", /* Specify the root folder within your source files. */
2929
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
30-
// "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */
30+
"baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */
3131
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3232
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
3333
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
@@ -44,11 +44,11 @@
4444
/* Emit */
4545
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
4646
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
47-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
47+
"emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
4848
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
"outDir": "./lib", /* Specify an output folder for all emitted files. */
51-
"removeComments": true, /* Disable emitting comments. */
51+
"removeComments": true, /* Disable emitting comments. */
5252
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */

0 commit comments

Comments
 (0)