File tree Expand file tree Collapse file tree 4 files changed +9
-9
lines changed Expand file tree Collapse file tree 4 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -80,9 +80,9 @@ npx swagger-typescript-api -p ./swagger.json -o ./src -n myApi.ts
8080You can use this package from nodejs:
8181
8282``` js
83- const { generateApi , generateTemplates } = require ( " swagger-typescript-api " ) ;
84- const path = require ( " path" ) ;
85- const fs = require ( " fs " ) ;
83+ import fs from " node:fs " ;
84+ import path from " node: path" ;
85+ import { generateApi , generateTemplates } from " swagger-typescript-api " ;
8686
8787/* NOTE: all fields are optional expect one of `input`, `url`, `spec` */
8888generateApi ({
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ interface GenerateApiParamsBase {
192192 *
193193 * @example
194194 * ```ts
195- * const { Translator } = require( "swagger-typescript-api/src/translators/translator") ;
195+ * import { Translator } from "swagger-typescript-api/src/translators/translator";
196196 *
197197 * class MyTranslator extends Translator {
198198 *
Original file line number Diff line number Diff line change @@ -301,7 +301,7 @@ const main = async () => {
301301 try {
302302 const customConfigPath = resolve ( process . cwd ( ) , options . customConfig ) ;
303303 console . log ( `✨ found custom config at: ${ customConfigPath } ` ) ;
304- customConfig = require ( customConfigPath ) ;
304+ customConfig = await import ( customConfigPath ) ;
305305 } catch ( e ) {
306306 /* empty */
307307 }
Original file line number Diff line number Diff line change @@ -76,21 +76,21 @@ class TemplatesWorker {
7676 ) ;
7777 } ;
7878
79- requireFnFromTemplate = ( packageOrPath ) => {
79+ requireFnFromTemplate = async ( packageOrPath ) => {
8080 const isPath =
8181 _ . startsWith ( packageOrPath , "./" ) || _ . startsWith ( packageOrPath , "../" ) ;
8282
8383 if ( isPath ) {
84- return require (
84+ return await import (
8585 path . resolve (
8686 this . config . templatePaths . custom ||
8787 this . config . templatePaths . original ,
8888 packageOrPath ,
89- ) ,
89+ )
9090 ) ;
9191 }
9292
93- return require ( packageOrPath ) ;
93+ return await import ( packageOrPath ) ;
9494 } ;
9595
9696 getTemplate = ( { fileName, name, path } ) => {
You can’t perform that action at this time.
0 commit comments