Skip to content

Commit 12d89ac

Browse files
authored
feat(core): make swagger tool run in project directory (#758)
1 parent 24eb831 commit 12d89ac

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

packages/core/src/executors/update-swagger/executor.spec.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ const mockCSProj = `<Project>
2020
</ItemGroup>
2121
</Project>`;
2222

23-
const options: UpdateSwaggerJsonExecutorSchema = {
24-
output: '',
25-
startupAssembly: '',
26-
swaggerDoc: '',
27-
skipInstall: false,
23+
const options: Partial<UpdateSwaggerJsonExecutorSchema> = {
24+
output: 'libs/generated/my-app-swagger/swagger.json',
2825
};
2926

3027
const root = '/virtual';
@@ -36,6 +33,20 @@ jest.mock('@nrwl/devkit', () => ({
3633

3734
jest.mock('../../../../dotnet/src/lib/core/dotnet.client');
3835

36+
jest.mock('fs-extra');
37+
38+
jest.mock('../../generators/utils/get-path-to-startup-assembly', () => ({
39+
buildStartupAssemblyPath: (
40+
projectName: string,
41+
_project: devkit.ProjectConfiguration,
42+
csProjFilePath: string,
43+
) =>
44+
`${root}/dist/apps/${projectName}/${csProjFilePath.replace(
45+
'csproj',
46+
'dll',
47+
)}`,
48+
}));
49+
3950
describe('Update-Swagger Executor', () => {
4051
let context: ExecutorContext;
4152
let dotnetClient: DotNetClient;
@@ -91,7 +102,14 @@ describe('Update-Swagger Executor', () => {
91102
const res = await executor(options, context, dotnetClient);
92103
expect(
93104
(dotnetClient as jest.Mocked<DotNetClient>).runTool,
94-
).toHaveBeenCalled();
105+
).toHaveBeenCalledWith('swagger', [
106+
'tofile',
107+
'--output',
108+
`${root}/libs/generated/my-app-swagger/swagger.json`,
109+
`${root}/dist/apps/my-app/1.dll`,
110+
'v1',
111+
]);
112+
expect(dotnetClient.cwd).toEqual(`${root}/apps/my-app`);
95113
expect(res.success).toBeTruthy();
96114
});
97115

packages/core/src/executors/update-swagger/executor.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ function normalizeOptions(
3131
projectName: string,
3232
): UpdateSwaggerJsonExecutorSchema {
3333
return {
34-
output: opts.output ?? `dist/swagger/${project.root}/swagger.json`,
35-
startupAssembly:
36-
opts.startupAssembly ??
37-
buildStartupAssemblyPath(projectName, project, csProjFilePath),
34+
output: resolve(
35+
workspaceRoot,
36+
opts.output ?? `dist/swagger/${project.root}/swagger.json`,
37+
),
38+
startupAssembly: opts.startupAssembly
39+
? resolve(workspaceRoot, opts.startupAssembly)
40+
: resolve(buildStartupAssemblyPath(projectName, project, csProjFilePath)),
41+
3842
swaggerDoc: opts.swaggerDoc ?? 'v1',
3943
skipInstall: opts.skipInstall ?? false,
4044
};
@@ -77,7 +81,8 @@ export default async function runExecutor(
7781
const csProjFilePath = await getProjectFileForNxProject(
7882
nxProjectConfiguration,
7983
);
80-
84+
const projectDirectory = resolve(workspaceRoot, nxProjectConfiguration.root);
85+
dotnetClient.cwd = projectDirectory;
8186
const options = normalizeOptions(
8287
schema,
8388
nxProjectConfiguration,
@@ -99,7 +104,7 @@ export default async function runExecutor(
99104
'tofile',
100105
'--output',
101106
options.output,
102-
resolve(options.startupAssembly),
107+
options.startupAssembly,
103108
options.swaggerDoc,
104109
]);
105110

0 commit comments

Comments
 (0)