Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ npx swagger-typescript-api -p ./swagger.json -o ./src -n myApi.ts
You can use this package from nodejs:

```js
const { generateApi, generateTemplates } = require("swagger-typescript-api");
const path = require("path");
const fs = require("fs");
import fs from "node:fs";
import path from "node:path";
import { generateApi, generateTemplates } from "swagger-typescript-api";

/* NOTE: all fields are optional expect one of `input`, `url`, `spec` */
generateApi({
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ interface GenerateApiParamsBase {
*
* @example
* ```ts
* const { Translator } = require("swagger-typescript-api/src/translators/translator");
* import { Translator } from "swagger-typescript-api/src/translators/translator";
*
* class MyTranslator extends Translator {
*
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const main = async () => {
try {
const customConfigPath = resolve(process.cwd(), options.customConfig);
console.log(`✨ found custom config at: ${customConfigPath}`);
customConfig = require(customConfigPath);
customConfig = await import(customConfigPath);
} catch (e) {
/* empty */
}
Expand Down
8 changes: 4 additions & 4 deletions src/templates-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ class TemplatesWorker {
);
};

requireFnFromTemplate = (packageOrPath) => {
requireFnFromTemplate = async (packageOrPath) => {
const isPath =
_.startsWith(packageOrPath, "./") || _.startsWith(packageOrPath, "../");

if (isPath) {
return require(
return await import(
path.resolve(
this.config.templatePaths.custom ||
this.config.templatePaths.original,
packageOrPath,
),
)
);
}

return require(packageOrPath);
return await import(packageOrPath);
};

getTemplate = ({ fileName, name, path }) => {
Expand Down