Skip to content

Commit d1044f6

Browse files
committed
feat(core): allow tool installation to be skipped for update-swagger
1 parent c189540 commit d1044f6

File tree

8 files changed

+49
-9
lines changed

8 files changed

+49
-9
lines changed

e2e/core-e2e/tests/nx-dotnet.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ public class UnitTest1
446446
});
447447
});
448448

449-
describe('swagger integration', () => {
450-
it('should generate swagger project for webapi', async () => {
449+
fdescribe('swagger integration', () => {
450+
fit('should generate swagger project for webapi', async () => {
451451
const api = uniq('api');
452452
await runNxCommandAsync(
453453
`generate @nx-dotnet/core:app ${api} --language="C#" --template="webapi"`,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"kill-port": "^1.6.1",
7676
"lint-staged": "^12.3.4",
7777
"nx": "13.10.2",
78+
"openapi-types": "^11.0.1",
7879
"prettier": "2.5.1",
7980
"run-p": "*",
8081
"semantic-release": "^19.0.2",

packages/core/generators.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
"factory": "./src/generators/add-swagger-target/add-swagger-target",
6060
"schema": "./src/generators/add-swagger-target/schema.json",
6161
"description": "Generate a target to extract the swagger.json file from a .NET webapi"
62+
},
63+
"swagger-typescript": {
64+
"factory": "./src/generators/swagger-typescript/generator",
65+
"schema": "./src/generators/swagger-typescript/schema.json",
66+
"description": "swagger-typescript generator"
6267
}
6368
}
6469
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const options: UpdateSwaggerJsonExecutorSchema = {
2424
output: '',
2525
startupAssembly: '',
2626
swaggerDoc: '',
27+
skipInstall: false,
2728
};
2829

2930
const root = '/virtual';
@@ -109,7 +110,7 @@ describe('Update-Swagger Executor', () => {
109110
expect(res.success).toBeTruthy();
110111
});
111112

112-
it(`doesnt install ${SWAGGER_CLI_TOOL} if already installed`, async () => {
113+
it(`doesn't install ${SWAGGER_CLI_TOOL} if already installed`, async () => {
113114
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
114115
jest.spyOn(fs, 'readFileSync').mockImplementation((p): string => {
115116
if (p === '1.csproj') {
@@ -134,4 +135,24 @@ describe('Update-Swagger Executor', () => {
134135
).not.toHaveBeenCalled();
135136
expect(res.success).toBeTruthy();
136137
});
138+
139+
it(`skips installation when skipInstall is true`, async () => {
140+
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
141+
jest.spyOn(fs, 'readFileSync').mockImplementation((p): string => {
142+
if (p === '1.csproj') {
143+
return mockCSProj;
144+
}
145+
throw new Error('Attempted to read unexpected file');
146+
});
147+
jest.spyOn(devkit, 'readJsonFile').mockReturnValue({});
148+
const res = await executor(
149+
{ ...options, skipInstall: true },
150+
context,
151+
dotnetClient,
152+
);
153+
expect(
154+
(dotnetClient as jest.Mocked<DotNetClient>).installTool,
155+
).not.toHaveBeenCalled();
156+
expect(res.success).toBeTruthy();
157+
});
137158
});

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function normalizeOptions(
3636
opts.startupAssembly ??
3737
buildStartupAssemblyPath(projectName, project, csProjFilePath),
3838
swaggerDoc: opts.swaggerDoc ?? 'v1',
39+
skipInstall: opts.skipInstall ?? false,
3940
};
4041
}
4142

@@ -85,11 +86,14 @@ export default async function runExecutor(
8586
);
8687
ensureDirSync(dirname(options.output));
8788

88-
ensureSwaggerToolInstalled(
89-
context,
90-
dotnetClient,
91-
await readSwashbuckleVersion(csProjFilePath),
92-
);
89+
if (!options.skipInstall) {
90+
ensureSwaggerToolInstalled(
91+
context,
92+
dotnetClient,
93+
await readSwashbuckleVersion(csProjFilePath),
94+
);
95+
}
96+
9397
dotnetClient.runTool('swagger', [
9498
'tofile',
9599
'--output',

packages/core/src/executors/update-swagger/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export interface UpdateSwaggerJsonExecutorSchema {
22
output: string;
33
swaggerDoc: string;
44
startupAssembly: string;
5+
skipInstall: boolean;
56
}

packages/core/src/executors/update-swagger/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
"startupAssembly": {
1818
"type": "string",
1919
"description": "Path from workspace root to the built api's startup dll file"
20+
},
21+
"skipInstall": {
22+
"type": "boolean",
23+
"description": "Skips installing Swashbuckle.AspNetCore.Cli. This option should be used if you are managing the installation on your own.",
24+
"default": false
2025
}
2126
},
2227
"required": []

yarn.lock

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10297,7 +10297,10 @@ open@^8.0.9, open@^8.4.0:
1029710297
is-docker "^2.1.1"
1029810298
is-wsl "^2.2.0"
1029910299

10300-
opener@^1.5.2:
10300+
openapi-types@^11.0.1:
10301+
version "11.0.1"
10302+
resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-11.0.1.tgz#7e1cee2c9b8cb16787d14f2b0f433c5ba0e32e96"
10303+
integrity sha512-P2pGRlHFXgP8z6vrp5P/MtftOXYtlIY1A+V0VmioOoo85NN6RSPgGbEprRAUNMIsbfRjnCPdx/r8mi8QRR7grQ==
1030110304
version "1.5.2"
1030210305
resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598"
1030310306
integrity sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==

0 commit comments

Comments
 (0)