Skip to content

Commit

Permalink
feat(core): make swagger tool run in project directory (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
EchelonFour committed Sep 19, 2023
1 parent 24eb831 commit 12d89ac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
30 changes: 24 additions & 6 deletions packages/core/src/executors/update-swagger/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ const mockCSProj = `<Project>
</ItemGroup>
</Project>`;

const options: UpdateSwaggerJsonExecutorSchema = {
output: '',
startupAssembly: '',
swaggerDoc: '',
skipInstall: false,
const options: Partial<UpdateSwaggerJsonExecutorSchema> = {
output: 'libs/generated/my-app-swagger/swagger.json',
};

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

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

jest.mock('fs-extra');

jest.mock('../../generators/utils/get-path-to-startup-assembly', () => ({
buildStartupAssemblyPath: (
projectName: string,
_project: devkit.ProjectConfiguration,
csProjFilePath: string,
) =>
`${root}/dist/apps/${projectName}/${csProjFilePath.replace(
'csproj',
'dll',
)}`,
}));

describe('Update-Swagger Executor', () => {
let context: ExecutorContext;
let dotnetClient: DotNetClient;
Expand Down Expand Up @@ -91,7 +102,14 @@ describe('Update-Swagger Executor', () => {
const res = await executor(options, context, dotnetClient);
expect(
(dotnetClient as jest.Mocked<DotNetClient>).runTool,
).toHaveBeenCalled();
).toHaveBeenCalledWith('swagger', [
'tofile',
'--output',
`${root}/libs/generated/my-app-swagger/swagger.json`,
`${root}/dist/apps/my-app/1.dll`,
'v1',
]);
expect(dotnetClient.cwd).toEqual(`${root}/apps/my-app`);
expect(res.success).toBeTruthy();
});

Expand Down
17 changes: 11 additions & 6 deletions packages/core/src/executors/update-swagger/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ function normalizeOptions(
projectName: string,
): UpdateSwaggerJsonExecutorSchema {
return {
output: opts.output ?? `dist/swagger/${project.root}/swagger.json`,
startupAssembly:
opts.startupAssembly ??
buildStartupAssemblyPath(projectName, project, csProjFilePath),
output: resolve(
workspaceRoot,
opts.output ?? `dist/swagger/${project.root}/swagger.json`,
),
startupAssembly: opts.startupAssembly
? resolve(workspaceRoot, opts.startupAssembly)
: resolve(buildStartupAssemblyPath(projectName, project, csProjFilePath)),

swaggerDoc: opts.swaggerDoc ?? 'v1',
skipInstall: opts.skipInstall ?? false,
};
Expand Down Expand Up @@ -77,7 +81,8 @@ export default async function runExecutor(
const csProjFilePath = await getProjectFileForNxProject(
nxProjectConfiguration,
);

const projectDirectory = resolve(workspaceRoot, nxProjectConfiguration.root);
dotnetClient.cwd = projectDirectory;
const options = normalizeOptions(
schema,
nxProjectConfiguration,
Expand All @@ -99,7 +104,7 @@ export default async function runExecutor(
'tofile',
'--output',
options.output,
resolve(options.startupAssembly),
options.startupAssembly,
options.swaggerDoc,
]);

Expand Down

0 comments on commit 12d89ac

Please sign in to comment.