File tree Expand file tree Collapse file tree 9 files changed +22
-13
lines changed
test-endpoints-module/test-app-express-cjs/src
test-endpoints-router-module/test-app-express-cjs/src Expand file tree Collapse file tree 9 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -308,7 +308,7 @@ async function bootstrap() {
308
308
const app = await NestFactory .create (AppModule );
309
309
const { document, changed } = await setupOpenAPI (app , {
310
310
configure : (builder ) => builder .setTitle (' My Api' ),
311
- outputFile: ' openapi.json' ,
311
+ outputFile: process . cwd () + ' / openapi.json' ,
312
312
});
313
313
if (changed ) {
314
314
void import (' orval' ).then (({ generate }) => generate ());
File renamed without changes.
Original file line number Diff line number Diff line change @@ -101,3 +101,15 @@ export const ApiQueries = <T extends z.ZodObject<ZodRawShape>>(
101
101
export function shouldJson ( value : unknown ) {
102
102
return typeof value !== 'string' ;
103
103
}
104
+
105
+ export function getCallsiteFile ( ) {
106
+ const callsite = callsites ( ) [ 2 ] ;
107
+ if ( ! callsite ) {
108
+ throw new Error ( 'Callsite not found' ) ;
109
+ }
110
+ const result = callsite . getFileName ( ) ?. replace ( / ^ f i l e : \/ \/ / , '' ) ;
111
+ if ( ! result ) {
112
+ throw new Error ( 'Callsite file not found' ) ;
113
+ }
114
+ return result ;
115
+ }
Original file line number Diff line number Diff line change 1
1
export { z } from 'zod' ;
2
2
export { EndpointsModule } from './decorators' ;
3
- export { endpoint , decorated , schema } from './fns ' ;
3
+ export { endpoint , decorated , schema } from './endpoint-fn ' ;
4
4
export {
5
5
ZodValidationException ,
6
6
ZodSerializationException ,
Original file line number Diff line number Diff line change 6
6
ModuleMetadata ,
7
7
Type ,
8
8
} from '@nestjs/common' ;
9
- import callsites from 'callsites' ;
10
9
import { endpointFileRegex , settings } from './consts' ;
10
+ import { getCallsiteFile } from './helpers' ;
11
11
12
12
@Module ( { } )
13
13
export class EndpointsRouterModule {
@@ -33,12 +33,7 @@ export class EndpointsRouterModule {
33
33
} ) : Promise < DynamicModule > {
34
34
let rootDirectory = params . rootDirectory ;
35
35
if ( ! path . isAbsolute ( rootDirectory ) ) {
36
- const calledFrom = callsites ( ) [ 1 ]
37
- ?. getFileName ( )
38
- ?. replace ( / ^ f i l e : / , '' ) ;
39
- if ( ! calledFrom ) {
40
- throw new Error ( 'Cannot determine call site' ) ;
41
- }
36
+ const calledFrom = getCallsiteFile ( ) ;
42
37
rootDirectory = path . join ( path . dirname ( calledFrom ) , rootDirectory ) ;
43
38
}
44
39
settings . rootDirectory = rootDirectory ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { Writable } from 'node:stream';
4
4
import { INestApplication } from '@nestjs/common' ;
5
5
import { DocumentBuilder , SwaggerModule } from '@nestjs/swagger' ;
6
6
import { patchNestJsSwagger } from 'nestjs-zod' ;
7
+ import { getCallsiteFile } from './helpers' ;
7
8
8
9
export async function setupOpenAPI (
9
10
app : INestApplication ,
@@ -36,7 +37,7 @@ export async function setupOpenAPI(
36
37
} else {
37
38
const documentFile = path . isAbsolute ( outputFile )
38
39
? outputFile
39
- : path . resolve ( process . cwd ( ) , outputFile ) ;
40
+ : path . resolve ( path . dirname ( getCallsiteFile ( ) ) , outputFile ) ;
40
41
const currentDocument = await readFile ( documentFile , 'utf-8' ) . catch (
41
42
( ) => '' ,
42
43
) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { AppModule } from './app.module';
6
6
async function bootstrap ( ) {
7
7
const app = await NestFactory . create ( AppModule ) ;
8
8
await setupOpenAPI ( app , {
9
- outputFile : ' openapi.json',
9
+ outputFile : process . cwd ( ) + '/ openapi.json',
10
10
} ) ;
11
11
void generate ( ) ;
12
12
}
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { AppModule } from './app.module';
5
5
async function bootstrap ( ) {
6
6
const app = await NestFactory . create ( AppModule ) ;
7
7
await setupOpenAPI ( app , {
8
- outputFile : ' openapi.json',
8
+ outputFile : process . cwd ( ) + '/ openapi.json',
9
9
} ) ;
10
10
const port = process . env . PORT || 3000 ;
11
11
await app . listen ( port , ( ) => {
Original file line number Diff line number Diff line change
1
+ import path from 'node:path' ;
1
2
import { NestFactory } from '@nestjs/core' ;
2
3
import { setupOpenAPI } from 'nestjs-endpoints' ;
3
4
import { AppModule } from './app.module' ;
4
5
5
6
async function bootstrap ( ) {
6
7
const app = await NestFactory . create ( AppModule ) ;
7
8
await setupOpenAPI ( app , {
8
- outputFile : 'openapi.json' ,
9
+ outputFile : path . resolve ( process . cwd ( ) , 'openapi.json' ) ,
9
10
} ) ;
10
11
const port = process . env . PORT || 3000 ;
11
12
await app . listen ( port , ( ) => {
You can’t perform that action at this time.
0 commit comments