Skip to content

Commit 57f97ec

Browse files
Merge pull request #215 from atc-net/feature/customize-namespaces
Feature/customize namespaces
2 parents e113161 + 5aac2e5 commit 57f97ec

26 files changed

+441
-164
lines changed

Diff for: README.md

+24-8
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,11 @@ OPTIONS:
211211
--disableCodingRules Disable ATC-Coding-Rules
212212
--useProblemDetailsAsDefaultResponseBody Use ProblemDetails as default responsen body
213213
--endpointsLocation [ENDPOINTSLOCATION] If endpoints-localtion is provided, generated files will be placed here instead of the Endpoints folder
214+
--endpointsNamespace [ENDPOINTSNAMESPACE] If endpoints-namespace is provided, generated files will be placed here instead of the Endpoints namespace
214215
--contractsLocation [CONTRACTSLOCATION] If contracts-localtion is provided, generated files will be placed here instead of the Contracts folder
216+
--contractsNamespace [CONTRACTSNAMESPACE] If contracts-namespace is provided, generated files will be placed here instead of the Contracts namespace
215217
--handlersLocation [HANDLERSLOCATION] If handlers-localtion is provided, generated files will be placed here instead of the Handlers folder
218+
--handlersNamespace [HANDLERSNAMESPACE] If handlers-namespace is provided, generated files will be placed here instead of the Handlers namespace
216219
--usePartialClassForContracts Use Partial-Class for contracts
217220
--usePartialClassForEndpoints Use Partial-Class for endpoints
218221
--removeNamespaceGroupSeparatorInGlobalUsings Remove space between namespace groups in GlobalUsing.cs
@@ -256,8 +259,11 @@ COMMANDS:
256259
"projectName": "",
257260
"projectSuffixName": "",
258261
"contractsLocation": "Contracts.[[apiGroupName]]",
262+
"contractsNamespace": "Contracts.[[apiGroupName]]",
259263
"endpointsLocation": "Endpoints.[[apiGroupName]]",
264+
"endpointsNamespace": "Endpoints.[[apiGroupName]]",
260265
"handlersLocation": "Handlers.[[apiGroupName]]",
266+
"handlersNamespace": "Handlers.[[apiGroupName]]",
261267
"usePartialClassForContracts": false,
262268
"usePartialClassForEndpoints": false,
263269
"removeNamespaceGroupSeparatorInGlobalUsings": false,
@@ -288,8 +294,11 @@ COMMANDS:
288294
"projectName": "",
289295
"projectSuffixName": "",
290296
"contractsLocation": "Contracts.[[apiGroupName]]",
297+
"contractsNamespace": "Contracts.[[apiGroupName]]",
291298
"endpointsLocation": "Endpoints.[[apiGroupName]]",
299+
"endpointsNamespace": "Endpoints.[[apiGroupName]]",
292300
"handlersLocation": "Handlers.[[apiGroupName]]",
301+
"handlersNamespace": "Handlers.[[apiGroupName]]",
293302
"usePartialClassForContracts": false,
294303
"usePartialClassForEndpoints": false,
295304
"removeNamespaceGroupSeparatorInGlobalUsings": false,
@@ -346,7 +355,7 @@ You can use specific syntax to define and customize the output file structure.
346355

347356
##### Syntax
348357

349-
For options like `contractsLocation`, `endpointsLocation`, and `handlersLocation`,
358+
For options like `contractsLocation`, `contractsNamespace`, `endpointsLocation`, `endpointsNamespace`, `handlersLocation`, `handlersNamespace`,
350359
you can define paths using placeholders and custom directory names.
351360

352361
The syntax is flexible and allows you to organize files based on grouping or specific requirements.
@@ -355,13 +364,20 @@ The syntax is flexible and allows you to organize files based on grouping or spe
355364

356365
| Option-Name | Option-Value | Example-file | Generated-output |
357366
|-------------|--------------|--------------|------------------|
358-
| contractsLocation | Contracts | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
359-
| contractsLocation | Contracts.[[apiGroupName]] | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
360-
| contractsLocation | Contracts-[[apiGroupName]] | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
361-
| contractsLocation | [[apiGroupName]].MyContracts | Account.cs | [Project-root]\Accounts\MyContracts\Account.cs |
362-
| contractsLocation | [[apiGroupName]]-MyContracts | Account.cs | [Project-root]\Accounts\MyContracts\Account.cs |
363-
| contractsLocation | [[apiGroupName]] | Account.cs | [Project-root]\Accounts\Account.cs |
364-
| contractsLocation | . | Account.cs | [Project-root]\Account.cs |
367+
| contractsLocation | Contracts | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
368+
| contractsLocation | Contracts.[[apiGroupName]] | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
369+
| contractsLocation | Contracts-[[apiGroupName]] | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
370+
| contractsLocation | [[apiGroupName]].MyContracts | Account.cs | [Project-root]\Accounts\MyContracts\Account.cs |
371+
| contractsLocation | [[apiGroupName]]-MyContracts | Account.cs | [Project-root]\Accounts\MyContracts\Account.cs |
372+
| contractsLocation | [[apiGroupName]] | Account.cs | [Project-root]\Accounts\Account.cs |
373+
| contractsLocation | . | Account.cs | [Project-root]\Account.cs |
374+
| contractsNamespace | Contracts | Account.cs | [Project-root].Contracts.Accounts.Account.cs |
375+
| contractsNamespace | Contracts.[[apiGroupName]] | Account.cs | [Project-root].Contracts.Accounts.Account.cs |
376+
| contractsNamespace | Contracts-[[apiGroupName]] | Account.cs | [Project-root].Contracts.Accounts.Account.cs |
377+
| contractsNamespace | [[apiGroupName]].MyContracts | Account.cs | [Project-root].Accounts.MyContracts.Account.cs |
378+
| contractsNamespace | [[apiGroupName]]-MyContracts | Account.cs | [Project-root].Accounts.MyContracts.Account.cs |
379+
| contractsNamespace | [[apiGroupName]] | Account.cs | [Project-root].Accounts.Account.cs |
380+
| contractsNamespace | . | Account.cs | [Project-root].Account.cs |
365381

366382
> Placeholder Explanation:
367383
>

Diff for: src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs

+36-6
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,28 @@ private static void ApplyGeneratorOverrides(
154154
apiOptions.Generator.ProjectName = serverCommandSettings.ProjectPrefixName;
155155
}
156156

157+
if (serverCommandSettings.EndpointsLocation is not null &&
158+
serverCommandSettings.EndpointsLocation.IsSet)
159+
{
160+
apiOptions.Generator.EndpointsLocation = serverCommandSettings.EndpointsLocation.Value;
161+
}
162+
163+
if (serverCommandSettings.EndpointsNamespace is not null &&
164+
serverCommandSettings.EndpointsNamespace.IsSet)
165+
{
166+
apiOptions.Generator.EndpointsNamespace = serverCommandSettings.EndpointsNamespace.Value;
167+
}
168+
157169
if (serverCommandSettings.ContractsLocation is not null &&
158170
serverCommandSettings.ContractsLocation.IsSet)
159171
{
160172
apiOptions.Generator.ContractsLocation = serverCommandSettings.ContractsLocation.Value;
161173
}
162174

163-
if (serverCommandSettings.EndpointsLocation is not null &&
164-
serverCommandSettings.EndpointsLocation.IsSet)
175+
if (serverCommandSettings.ContractsNamespace is not null &&
176+
serverCommandSettings.ContractsNamespace.IsSet)
165177
{
166-
apiOptions.Generator.EndpointsLocation = serverCommandSettings.EndpointsLocation.Value;
178+
apiOptions.Generator.ContractsNamespace = serverCommandSettings.ContractsNamespace.Value;
167179
}
168180

169181
if (serverCommandSettings.HandlersLocation is not null &&
@@ -172,6 +184,12 @@ private static void ApplyGeneratorOverrides(
172184
apiOptions.Generator.HandlersLocation = serverCommandSettings.HandlersLocation.Value;
173185
}
174186

187+
if (serverCommandSettings.HandlersNamespace is not null &&
188+
serverCommandSettings.HandlersNamespace.IsSet)
189+
{
190+
apiOptions.Generator.HandlersNamespace = serverCommandSettings.HandlersNamespace.Value;
191+
}
192+
175193
if (serverCommandSettings.UsePartialClassForContracts)
176194
{
177195
apiOptions.Generator.UsePartialClassForContracts = serverCommandSettings.UsePartialClassForContracts;
@@ -212,16 +230,28 @@ private static void ApplyGeneratorOverrides(
212230
apiOptions.Generator.ProjectSuffixName = $"{ContentGeneratorConstants.DefaultHttpClientName}.Generated";
213231
}
214232

233+
if (clientApiCommandSettings.EndpointsLocation is not null &&
234+
clientApiCommandSettings.EndpointsLocation.IsSet)
235+
{
236+
apiOptions.Generator.EndpointsLocation = clientApiCommandSettings.EndpointsLocation.Value;
237+
}
238+
239+
if (clientApiCommandSettings.EndpointsNamespace is not null &&
240+
clientApiCommandSettings.EndpointsNamespace.IsSet)
241+
{
242+
apiOptions.Generator.EndpointsNamespace = clientApiCommandSettings.EndpointsNamespace.Value;
243+
}
244+
215245
if (clientApiCommandSettings.ContractsLocation is not null &&
216246
clientApiCommandSettings.ContractsLocation.IsSet)
217247
{
218248
apiOptions.Generator.ContractsLocation = clientApiCommandSettings.ContractsLocation.Value;
219249
}
220250

221-
if (clientApiCommandSettings.EndpointsLocation is not null &&
222-
clientApiCommandSettings.EndpointsLocation.IsSet)
251+
if (clientApiCommandSettings.ContractsNamespace is not null &&
252+
clientApiCommandSettings.ContractsNamespace.IsSet)
223253
{
224-
apiOptions.Generator.EndpointsLocation = clientApiCommandSettings.EndpointsLocation.Value;
254+
apiOptions.Generator.ContractsNamespace = clientApiCommandSettings.ContractsNamespace.Value;
225255
}
226256

227257
if (clientApiCommandSettings.UsePartialClassForContracts)

Diff for: src/Atc.Rest.ApiGenerator.CLI/Commands/ArgumentCommandConstants.cs

+3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ public static class ArgumentCommandConstants
2121
public const string LongConfigurationValidateModelPropertyNameCasingStyle = "--validate-modelPropertyNameCasingStyle";
2222

2323
public const string LongEndpointsLocation = "--endpointsLocation";
24+
public const string LongEndpointsNamespace = "--endpointsNamespace";
2425
public const string LongContractsLocation = "--contractsLocation";
26+
public const string LongContractsNamespace = "--contractsNamespace";
2527
public const string LongHandlersLocation = "--handlersLocation";
28+
public const string LongHandlersNamespace = "--handlersNamespace";
2629

2730
public const string LongClientHttpClientName = "--httpClientName";
2831
public const string LongExcludeEndpointGeneration = "--excludeEndpointGeneration";

Diff for: src/Atc.Rest.ApiGenerator.CLI/Commands/Settings/BaseGenerateCommandSettings.cs

+12
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,26 @@ public class BaseGenerateCommandSettings : BaseConfigurationCommandSettings
1818
[Description($"If endpoints-localtion is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Endpoints} folder.")]
1919
public FlagValue<string>? EndpointsLocation { get; init; }
2020

21+
[CommandOption($"{ArgumentCommandConstants.LongEndpointsNamespace} [ENDPOINTSNAMESPACE]")]
22+
[Description($"If endpoints-namespace is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Endpoints} namespace.")]
23+
public FlagValue<string>? EndpointsNamespace { get; init; }
24+
2125
[CommandOption($"{ArgumentCommandConstants.LongContractsLocation} [CONTRACTSLOCATION]")]
2226
[Description($"If contracts-localtion is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Contracts} folder.")]
2327
public FlagValue<string>? ContractsLocation { get; init; }
2428

29+
[CommandOption($"{ArgumentCommandConstants.LongContractsNamespace} [CONTRACTSNAMESPACE]")]
30+
[Description($"If contracts-namespace is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Contracts} namespace.")]
31+
public FlagValue<string>? ContractsNamespace { get; init; }
32+
2533
[CommandOption($"{ArgumentCommandConstants.LongHandlersLocation} [HANDLERSLOCATION]")]
2634
[Description($"If handlers-localtion is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Handlers} folder.")]
2735
public FlagValue<string>? HandlersLocation { get; init; }
2836

37+
[CommandOption($"{ArgumentCommandConstants.LongHandlersNamespace} [HANDLERSNAMESPACE]")]
38+
[Description($"If handlers-namespace is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Handlers} namespace.")]
39+
public FlagValue<string>? HandlersNamespace { get; init; }
40+
2941
[CommandOption(ArgumentCommandConstants.LongUsePartialClassForContracts)]
3042
[Description("Use Partial-Class for contracts")]
3143
public bool UsePartialClassForContracts { get; init; }

0 commit comments

Comments
 (0)