Skip to content

Feature/customize namespaces #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ OPTIONS:
--disableCodingRules Disable ATC-Coding-Rules
--useProblemDetailsAsDefaultResponseBody Use ProblemDetails as default responsen body
--endpointsLocation [ENDPOINTSLOCATION] If endpoints-localtion is provided, generated files will be placed here instead of the Endpoints folder
--endpointsNamespace [ENDPOINTSNAMESPACE] If endpoints-namespace is provided, generated files will be placed here instead of the Endpoints namespace
--contractsLocation [CONTRACTSLOCATION] If contracts-localtion is provided, generated files will be placed here instead of the Contracts folder
--contractsNamespace [CONTRACTSNAMESPACE] If contracts-namespace is provided, generated files will be placed here instead of the Contracts namespace
--handlersLocation [HANDLERSLOCATION] If handlers-localtion is provided, generated files will be placed here instead of the Handlers folder
--handlersNamespace [HANDLERSNAMESPACE] If handlers-namespace is provided, generated files will be placed here instead of the Handlers namespace
--usePartialClassForContracts Use Partial-Class for contracts
--usePartialClassForEndpoints Use Partial-Class for endpoints
--removeNamespaceGroupSeparatorInGlobalUsings Remove space between namespace groups in GlobalUsing.cs
Expand Down Expand Up @@ -256,8 +259,11 @@ COMMANDS:
"projectName": "",
"projectSuffixName": "",
"contractsLocation": "Contracts.[[apiGroupName]]",
"contractsNamespace": "Contracts.[[apiGroupName]]",
"endpointsLocation": "Endpoints.[[apiGroupName]]",
"endpointsNamespace": "Endpoints.[[apiGroupName]]",
"handlersLocation": "Handlers.[[apiGroupName]]",
"handlersNamespace": "Handlers.[[apiGroupName]]",
"usePartialClassForContracts": false,
"usePartialClassForEndpoints": false,
"removeNamespaceGroupSeparatorInGlobalUsings": false,
Expand Down Expand Up @@ -288,8 +294,11 @@ COMMANDS:
"projectName": "",
"projectSuffixName": "",
"contractsLocation": "Contracts.[[apiGroupName]]",
"contractsNamespace": "Contracts.[[apiGroupName]]",
"endpointsLocation": "Endpoints.[[apiGroupName]]",
"endpointsNamespace": "Endpoints.[[apiGroupName]]",
"handlersLocation": "Handlers.[[apiGroupName]]",
"handlersNamespace": "Handlers.[[apiGroupName]]",
"usePartialClassForContracts": false,
"usePartialClassForEndpoints": false,
"removeNamespaceGroupSeparatorInGlobalUsings": false,
Expand Down Expand Up @@ -346,7 +355,7 @@ You can use specific syntax to define and customize the output file structure.

##### Syntax

For options like `contractsLocation`, `endpointsLocation`, and `handlersLocation`,
For options like `contractsLocation`, `contractsNamespace`, `endpointsLocation`, `endpointsNamespace`, `handlersLocation`, `handlersNamespace`,
you can define paths using placeholders and custom directory names.

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

| Option-Name | Option-Value | Example-file | Generated-output |
|-------------|--------------|--------------|------------------|
| contractsLocation | Contracts | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
| contractsLocation | Contracts.[[apiGroupName]] | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
| contractsLocation | Contracts-[[apiGroupName]] | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
| contractsLocation | [[apiGroupName]].MyContracts | Account.cs | [Project-root]\Accounts\MyContracts\Account.cs |
| contractsLocation | [[apiGroupName]]-MyContracts | Account.cs | [Project-root]\Accounts\MyContracts\Account.cs |
| contractsLocation | [[apiGroupName]] | Account.cs | [Project-root]\Accounts\Account.cs |
| contractsLocation | . | Account.cs | [Project-root]\Account.cs |
| contractsLocation | Contracts | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
| contractsLocation | Contracts.[[apiGroupName]] | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
| contractsLocation | Contracts-[[apiGroupName]] | Account.cs | [Project-root]\Contracts\Accounts\Account.cs |
| contractsLocation | [[apiGroupName]].MyContracts | Account.cs | [Project-root]\Accounts\MyContracts\Account.cs |
| contractsLocation | [[apiGroupName]]-MyContracts | Account.cs | [Project-root]\Accounts\MyContracts\Account.cs |
| contractsLocation | [[apiGroupName]] | Account.cs | [Project-root]\Accounts\Account.cs |
| contractsLocation | . | Account.cs | [Project-root]\Account.cs |
| contractsNamespace | Contracts | Account.cs | [Project-root].Contracts.Accounts.Account.cs |
| contractsNamespace | Contracts.[[apiGroupName]] | Account.cs | [Project-root].Contracts.Accounts.Account.cs |
| contractsNamespace | Contracts-[[apiGroupName]] | Account.cs | [Project-root].Contracts.Accounts.Account.cs |
| contractsNamespace | [[apiGroupName]].MyContracts | Account.cs | [Project-root].Accounts.MyContracts.Account.cs |
| contractsNamespace | [[apiGroupName]]-MyContracts | Account.cs | [Project-root].Accounts.MyContracts.Account.cs |
| contractsNamespace | [[apiGroupName]] | Account.cs | [Project-root].Accounts.Account.cs |
| contractsNamespace | . | Account.cs | [Project-root].Account.cs |

> Placeholder Explanation:
>
Expand Down
42 changes: 36 additions & 6 deletions src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,28 @@ private static void ApplyGeneratorOverrides(
apiOptions.Generator.ProjectName = serverCommandSettings.ProjectPrefixName;
}

if (serverCommandSettings.EndpointsLocation is not null &&
serverCommandSettings.EndpointsLocation.IsSet)
{
apiOptions.Generator.EndpointsLocation = serverCommandSettings.EndpointsLocation.Value;
}

if (serverCommandSettings.EndpointsNamespace is not null &&
serverCommandSettings.EndpointsNamespace.IsSet)
{
apiOptions.Generator.EndpointsNamespace = serverCommandSettings.EndpointsNamespace.Value;
}

if (serverCommandSettings.ContractsLocation is not null &&
serverCommandSettings.ContractsLocation.IsSet)
{
apiOptions.Generator.ContractsLocation = serverCommandSettings.ContractsLocation.Value;
}

if (serverCommandSettings.EndpointsLocation is not null &&
serverCommandSettings.EndpointsLocation.IsSet)
if (serverCommandSettings.ContractsNamespace is not null &&
serverCommandSettings.ContractsNamespace.IsSet)
{
apiOptions.Generator.EndpointsLocation = serverCommandSettings.EndpointsLocation.Value;
apiOptions.Generator.ContractsNamespace = serverCommandSettings.ContractsNamespace.Value;
}

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

if (serverCommandSettings.HandlersNamespace is not null &&
serverCommandSettings.HandlersNamespace.IsSet)
{
apiOptions.Generator.HandlersNamespace = serverCommandSettings.HandlersNamespace.Value;
}

if (serverCommandSettings.UsePartialClassForContracts)
{
apiOptions.Generator.UsePartialClassForContracts = serverCommandSettings.UsePartialClassForContracts;
Expand Down Expand Up @@ -212,16 +230,28 @@ private static void ApplyGeneratorOverrides(
apiOptions.Generator.ProjectSuffixName = $"{ContentGeneratorConstants.DefaultHttpClientName}.Generated";
}

if (clientApiCommandSettings.EndpointsLocation is not null &&
clientApiCommandSettings.EndpointsLocation.IsSet)
{
apiOptions.Generator.EndpointsLocation = clientApiCommandSettings.EndpointsLocation.Value;
}

if (clientApiCommandSettings.EndpointsNamespace is not null &&
clientApiCommandSettings.EndpointsNamespace.IsSet)
{
apiOptions.Generator.EndpointsNamespace = clientApiCommandSettings.EndpointsNamespace.Value;
}

if (clientApiCommandSettings.ContractsLocation is not null &&
clientApiCommandSettings.ContractsLocation.IsSet)
{
apiOptions.Generator.ContractsLocation = clientApiCommandSettings.ContractsLocation.Value;
}

if (clientApiCommandSettings.EndpointsLocation is not null &&
clientApiCommandSettings.EndpointsLocation.IsSet)
if (clientApiCommandSettings.ContractsNamespace is not null &&
clientApiCommandSettings.ContractsNamespace.IsSet)
{
apiOptions.Generator.EndpointsLocation = clientApiCommandSettings.EndpointsLocation.Value;
apiOptions.Generator.ContractsNamespace = clientApiCommandSettings.ContractsNamespace.Value;
}

if (clientApiCommandSettings.UsePartialClassForContracts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public static class ArgumentCommandConstants
public const string LongConfigurationValidateModelPropertyNameCasingStyle = "--validate-modelPropertyNameCasingStyle";

public const string LongEndpointsLocation = "--endpointsLocation";
public const string LongEndpointsNamespace = "--endpointsNamespace";
public const string LongContractsLocation = "--contractsLocation";
public const string LongContractsNamespace = "--contractsNamespace";
public const string LongHandlersLocation = "--handlersLocation";
public const string LongHandlersNamespace = "--handlersNamespace";

public const string LongClientHttpClientName = "--httpClientName";
public const string LongExcludeEndpointGeneration = "--excludeEndpointGeneration";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ public class BaseGenerateCommandSettings : BaseConfigurationCommandSettings
[Description($"If endpoints-localtion is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Endpoints} folder.")]
public FlagValue<string>? EndpointsLocation { get; init; }

[CommandOption($"{ArgumentCommandConstants.LongEndpointsNamespace} [ENDPOINTSNAMESPACE]")]
[Description($"If endpoints-namespace is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Endpoints} namespace.")]
public FlagValue<string>? EndpointsNamespace { get; init; }

[CommandOption($"{ArgumentCommandConstants.LongContractsLocation} [CONTRACTSLOCATION]")]
[Description($"If contracts-localtion is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Contracts} folder.")]
public FlagValue<string>? ContractsLocation { get; init; }

[CommandOption($"{ArgumentCommandConstants.LongContractsNamespace} [CONTRACTSNAMESPACE]")]
[Description($"If contracts-namespace is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Contracts} namespace.")]
public FlagValue<string>? ContractsNamespace { get; init; }

[CommandOption($"{ArgumentCommandConstants.LongHandlersLocation} [HANDLERSLOCATION]")]
[Description($"If handlers-localtion is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Handlers} folder.")]
public FlagValue<string>? HandlersLocation { get; init; }

[CommandOption($"{ArgumentCommandConstants.LongHandlersNamespace} [HANDLERSNAMESPACE]")]
[Description($"If handlers-namespace is provided, generated files will be placed here instead of the {ContentGeneratorConstants.Handlers} namespace.")]
public FlagValue<string>? HandlersNamespace { get; init; }

[CommandOption(ArgumentCommandConstants.LongUsePartialClassForContracts)]
[Description("Use Partial-Class for contracts")]
public bool UsePartialClassForContracts { get; init; }
Expand Down
Loading
Loading