Skip to content

Commit 6443e32

Browse files
authored
fix(core): app swaggerLib generation should work using dotnet pathScheme (#645)
1 parent 8033f76 commit 6443e32

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public class UnitTest1
442442
[Fact]
443443
public void Test1()
444444
{
445-
Assert.Equal(1, 2)
445+
Assert.Equal(1, 2);
446446
}
447447
}`,
448448
);
@@ -484,6 +484,25 @@ public class UnitTest1
484484
checkFilesExist(`libs/generated/${api}-swagger/swagger.json`),
485485
).not.toThrow();
486486
});
487+
488+
it('should generate swagger project using dotnet pathScheme', async () => {
489+
const apiName = uniq('CurveDental.Foobar.SomeApi');
490+
const apiNxProjectName = names(apiName).fileName;
491+
await runNxCommandAsync(
492+
`generate @nx-dotnet/core:app ${apiName} --language="C#" --pathScheme=dotnet --template="webapi" --skipSwaggerLib=false`,
493+
);
494+
495+
expect(() => checkFilesExist(`apps/${apiName}`)).not.toThrow();
496+
expect(() =>
497+
checkFilesExist(`libs/generated/${apiNxProjectName}-swagger`),
498+
).not.toThrow();
499+
expect(() => runNxCommand(`swagger ${apiName}`)).not.toThrow();
500+
expect(() =>
501+
checkFilesExist(
502+
`libs/generated/${apiNxProjectName}-swagger/swagger.json`,
503+
),
504+
).not.toThrow();
505+
});
487506
});
488507
});
489508

packages/core/src/generators/utils/generate-project.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface NormalizedSchema
4444
parsedTags: string[];
4545
className: string;
4646
namespaceName: string;
47+
nxProjectName: string;
4748
projectType?: ProjectType;
4849
}
4950

@@ -68,6 +69,7 @@ export async function normalizeOptions(
6869
const parsedTags = getProjectTagsFromSchema(options);
6970
const template = await getTemplate(options, client);
7071
const namespaceName = getNamespaceFromSchema(host, options, projectDirectory);
72+
const nxProjectName = names(options.name).fileName;
7173

7274
return {
7375
...options,
@@ -80,6 +82,7 @@ export async function normalizeOptions(
8082
projectLanguage: options.language,
8183
projectTemplate: template as KnownDotnetTemplates,
8284
namespaceName,
85+
nxProjectName,
8386
projectType: projectType ?? options.projectType ?? 'library',
8487
};
8588
}
@@ -232,8 +235,8 @@ export async function GenerateProject(
232235
tasks.push(
233236
await generateSwaggerSetup(host, {
234237
project: normalizedOptions.projectName,
235-
swaggerProject: `${normalizedOptions.projectName}-swagger`,
236-
codegenProject: `${normalizedOptions.projectName}-types`,
238+
swaggerProject: `${normalizedOptions.nxProjectName}-swagger`,
239+
codegenProject: `${normalizedOptions.nxProjectName}-types`,
237240
useNxPluginOpenAPI: normalizedOptions.useNxPluginOpenAPI,
238241
}),
239242
);

packages/core/src/generators/utils/generate-test-project.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ describe('nx-dotnet test project generator', () => {
9191
skipSwaggerLib: true,
9292
className: 'DomainExistingApp',
9393
namespaceName: 'Domain.ExistingApp',
94+
nxProjectName: 'domain-existing-app',
9495
pathScheme: 'nx',
9596
};
9697
testProjectName = options.name + '-test';

0 commit comments

Comments
 (0)