Skip to content

Commit

Permalink
fix(core): app swaggerLib generation should work using dotnet pathSch…
Browse files Browse the repository at this point in the history
…eme (#645)
  • Loading branch information
pleiris authored Mar 10, 2023
1 parent 8033f76 commit 6443e32
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
21 changes: 20 additions & 1 deletion e2e/core-e2e/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public class UnitTest1
[Fact]
public void Test1()
{
Assert.Equal(1, 2)
Assert.Equal(1, 2);
}
}`,
);
Expand Down Expand Up @@ -484,6 +484,25 @@ public class UnitTest1
checkFilesExist(`libs/generated/${api}-swagger/swagger.json`),
).not.toThrow();
});

it('should generate swagger project using dotnet pathScheme', async () => {
const apiName = uniq('CurveDental.Foobar.SomeApi');
const apiNxProjectName = names(apiName).fileName;
await runNxCommandAsync(
`generate @nx-dotnet/core:app ${apiName} --language="C#" --pathScheme=dotnet --template="webapi" --skipSwaggerLib=false`,
);

expect(() => checkFilesExist(`apps/${apiName}`)).not.toThrow();
expect(() =>
checkFilesExist(`libs/generated/${apiNxProjectName}-swagger`),
).not.toThrow();
expect(() => runNxCommand(`swagger ${apiName}`)).not.toThrow();
expect(() =>
checkFilesExist(
`libs/generated/${apiNxProjectName}-swagger/swagger.json`,
),
).not.toThrow();
});
});
});

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/generators/utils/generate-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface NormalizedSchema
parsedTags: string[];
className: string;
namespaceName: string;
nxProjectName: string;
projectType?: ProjectType;
}

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

return {
...options,
Expand All @@ -80,6 +82,7 @@ export async function normalizeOptions(
projectLanguage: options.language,
projectTemplate: template as KnownDotnetTemplates,
namespaceName,
nxProjectName,
projectType: projectType ?? options.projectType ?? 'library',
};
}
Expand Down Expand Up @@ -232,8 +235,8 @@ export async function GenerateProject(
tasks.push(
await generateSwaggerSetup(host, {
project: normalizedOptions.projectName,
swaggerProject: `${normalizedOptions.projectName}-swagger`,
codegenProject: `${normalizedOptions.projectName}-types`,
swaggerProject: `${normalizedOptions.nxProjectName}-swagger`,
codegenProject: `${normalizedOptions.nxProjectName}-types`,
useNxPluginOpenAPI: normalizedOptions.useNxPluginOpenAPI,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('nx-dotnet test project generator', () => {
skipSwaggerLib: true,
className: 'DomainExistingApp',
namespaceName: 'Domain.ExistingApp',
nxProjectName: 'domain-existing-app',
pathScheme: 'nx',
};
testProjectName = options.name + '-test';
Expand Down

0 comments on commit 6443e32

Please sign in to comment.