-
Notifications
You must be signed in to change notification settings - Fork 0
Working with CLI
The atc-rest-api-gen CLI tool provides a command-line interface for setting up projects that use the Atc.Rest.Api.SourceGenerator. It validates OpenAPI specifications, creates project scaffolds, and manages configuration files.
# Install as a global tool
dotnet tool install -g Atc.Rest.Api.CliGenerator
# Or run directly from source
dotnet run --project src/Atc.Rest.Api.CliGenerator/Atc.Rest.Api.CliGenerator.csproj -- <commands>atc-rest-api-gen
βββ validate
β βββ schema # β
Validate an OpenAPI specification file
βββ generate
β βββ server # π₯οΈ Generate server contracts and domain handler scaffolds
β βββ client # π± Generate a client project
βββ options
βββ create # π Create a default ApiGeneratorOptions.json file
βββ validate # β
Validate an ApiGeneratorOptions.json fileValidates an OpenAPI specification file against the ATC validation rules.
atc-rest-api-gen validate schema -s <PATH> [--no-strict]βοΈ Options:
| Option | Description |
|---|---|
-s, --specification <PATH> |
(Required) Path to the OpenAPI specification file (YAML or JSON) |
--no-strict |
Disable strict validation mode |
π Examples:
# β
Validate with strict mode (default)
atc-rest-api-gen validate schema -s api.yaml
# π Validate with standard mode (less strict)
atc-rest-api-gen validate schema -s api.yaml --no-strictGenerates server contracts and optionally domain handler scaffolds from an OpenAPI specification.
atc-rest-api-gen generate server -s <PATH> -o <PATH> -n <NAME> [options]π Required Options:
| Option | Description |
|---|---|
-s, --specification <PATH> |
Path to the OpenAPI specification file |
-o, --output <PATH> |
Output directory for the contracts project |
-n, --name <NAME> |
Name of the contracts project |
π§ Common Options:
| Option | Description |
|---|---|
--options <PATH> |
Path to ApiGeneratorOptions.json file |
--no-strict |
Disable strict validation mode |
--include-deprecated |
Include deprecated operations and schemas |
--namespace <NAMESPACE> |
Custom namespace prefix |
π₯οΈ Server-Specific Options:
| Option | Description |
|---|---|
--sub-folder-strategy <STRATEGY> |
None, FirstPathSegment, or OpenApiTag
|
--versioning-strategy <STRATEGY> |
None, QueryString, Header, UrlSegment, or Combined
|
--default-api-version <VERSION> |
Default API version (e.g., 1.0) |
--domain-output <PATH> |
Output path for domain handler scaffolds |
--handler-suffix <SUFFIX> |
Suffix for handler class names |
--stub-implementation <TYPE> |
throw-not-implemented, error-501, or default-value
|
ποΈ Scaffolding Options:
| Option | Description |
|---|---|
--project-structure <TYPE> |
SingleProject, TwoProjects, or TreeProjects (default) |
--no-coding-rules |
Skip adding ATC coding rules files |
--host-ui <TYPE> |
None, Swagger, or Scalar (default) |
--host-ui-mode <MODE> |
DevelopmentOnly (default) or Always
|
--aspire |
Create an Aspire AppHost project |
π Project Name Overrides:
| Option | Description |
|---|---|
--host-project <NAME> |
Override the host project name |
--contracts-project <NAME> |
Override the contracts project name |
--domain-project <NAME> |
Override the domain project name |
π Namespace Overrides:
| Option | Description |
|---|---|
--host-namespace <NAMESPACE> |
Override the host namespace |
--contracts-namespace <NAMESPACE> |
Override the contracts namespace |
--domain-namespace <NAMESPACE> |
Override the domain namespace |
π Examples:
# ποΈ Generate server with default settings (TreeProjects mode - 3 projects)
atc-rest-api-gen generate server \
-s api.yaml \
-o ./my-api \
-n DemoApi
# π’ Generate server with URL segment versioning
atc-rest-api-gen generate server \
-s api.yaml \
-o ./my-api \
-n DemoApi \
--versioning-strategy UrlSegment \
--default-api-version 2.0
# π¦ Single project mode
atc-rest-api-gen generate server \
-s api.yaml \
-o output/Demo.Api \
-n Demo.Api \
--project-structure SingleProject
# βοΈ Generate with Aspire AppHost
atc-rest-api-gen generate server \
-s api.yaml \
-o ./my-api \
-n DemoApi \
--aspire
# π Custom project names
atc-rest-api-gen generate server \
-s api.yaml \
-o ./my-api \
-n DemoApi \
--host-project MyDemoApi \
--contracts-project Api.Contracts \
--domain-project MyDemo.DomainStuffπ Repository Structure (TreeProjects mode):
my-api/
βββ DemoApi.slnx # π Solution file
βββ .gitignore
βββ Directory.Build.props
βββ atc-coding-rules-updater.json
βββ atc-coding-rules-updater.ps1
βββ src/
β βββ DemoApi.Api/ # π₯οΈ Host project
β β βββ DemoApi.Api.csproj
β β βββ Program.cs
β βββ DemoApi.Api.Contracts/ # π Contracts project
β β βββ DemoApi.Api.Contracts.csproj
β β βββ api.yaml
β β βββ .atc-rest-api-server-contracts
β βββ DemoApi.Domain/ # π’ Domain project
β β βββ DemoApi.Domain.csproj
β β βββ api.yaml
β β βββ .atc-rest-api-server-handlers
β βββ DemoApi.Aspire/ # βοΈ Aspire AppHost (optional)
β βββ DemoApi.Aspire.csproj
β βββ Program.cs
βββ test/
βββ DemoApi.Tests/
βββ DemoApi.Tests.csproj
βββ UnitTest1.csGenerates a client project from an OpenAPI specification.
atc-rest-api-gen generate client -s <PATH> -o <PATH> -n <NAME> [options]π Required Options:
| Option | Description |
|---|---|
-s, --specification <PATH> |
Path to the OpenAPI specification file |
-o, --output <PATH> |
Output directory for the client project |
-n, --name <NAME> |
Name of the client project |
π± Client-Specific Options:
| Option | Description |
|---|---|
--generation-mode <MODE> |
TypedClient or EndpointPerOperation
|
--client-suffix <SUFFIX> |
Suffix for HTTP client class name |
--no-oauth |
Disable OAuth2 token management generation |
π Examples:
# π± Generate client with TypedClient mode (default)
atc-rest-api-gen generate client \
-s api.yaml \
-o output/Demo.Client \
-n Demo.Client
# π― Generate client with EndpointPerOperation mode
atc-rest-api-gen generate client \
-s api.yaml \
-o output/Demo.Client \
-n Demo.Client \
--generation-mode EndpointPerOperationCreates a default ApiGeneratorOptions.json file.
atc-rest-api-gen options create -o <PATH> [--force]βοΈ Options:
| Option | Description |
|---|---|
-o, --output <PATH> |
(Required) Output path for the options file |
--force |
Overwrite existing file if present |
Validates an existing ApiGeneratorOptions.json file.
atc-rest-api-gen options validate -o <PATH>The ApiGeneratorOptions.json file provides centralized configuration for all code generation settings. The CLI auto-discovers this file in:
- π Explicitly specified via
--options <PATH> - π Same directory as the OpenAPI specification
- π Parent directory of the specification
- π Current working directory
{
"general": {
"validateSpecificationStrategy": "Strict",
"includeDeprecated": false
},
"scaffolding": {
"projectStructure": "TreeProjects",
"noCodingRules": false,
"testFramework": "xunit",
"targetFramework": "net10.0",
"hostUi": "Scalar",
"hostUiMode": "DevelopmentOnly"
},
"server": {
"namespace": null,
"subFolderStrategy": "FirstPathSegment",
"useMinimalApiPackage": "auto",
"useValidationFilter": "auto",
"useGlobalErrorHandler": "auto",
"versioningStrategy": "None",
"defaultApiVersion": "1.0",
"domain": {
"generateHandlersOutput": "ApiHandlers",
"subFolderStrategy": "None",
"handlerSuffix": "Handler",
"stubImplementation": "throw-not-implemented"
}
},
"client": {
"namespace": null,
"generationMode": "TypedClient",
"clientSuffix": "Client",
"generateOAuthTokenManagement": true
}
}| Option | Type | Default | Description |
|---|---|---|---|
validateSpecificationStrategy |
enum | "Strict" |
None, Standard, or Strict
|
includeDeprecated |
bool | false |
Include deprecated operations |
| Option | Type | Default | Description |
|---|---|---|---|
projectStructure |
enum | "TreeProjects" |
SingleProject, TwoProjects, or TreeProjects
|
noCodingRules |
bool | false |
Skip ATC coding rules files |
testFramework |
string | "xunit" |
Test framework for generated test project |
targetFramework |
string | "net10.0" |
Target framework |
hostUi |
enum | "Scalar" |
None, Swagger, or Scalar
|
hostUiMode |
enum | "DevelopmentOnly" |
DevelopmentOnly or Always
|
| Option | Type | Default | Description |
|---|---|---|---|
namespace |
string? | null |
Custom namespace (null = auto-detect) |
subFolderStrategy |
enum | "FirstPathSegment" |
None, FirstPathSegment, OpenApiTag
|
versioningStrategy |
enum | "None" |
None, QueryString, Header, UrlSegment, Combined
|
defaultApiVersion |
string | "1.0" |
Default API version |
useMinimalApiPackage |
enum | "auto" |
auto, enabled, disabled
|
useValidationFilter |
enum | "auto" |
auto, enabled, disabled
|
| Option | Type | Default | Description |
|---|---|---|---|
generateHandlersOutput |
string | "ApiHandlers" |
Output folder for handlers |
subFolderStrategy |
enum | "None" |
None, FirstPathSegment, OpenApiTag
|
handlerSuffix |
string | "Handler" |
Handler class name suffix |
stubImplementation |
string | "throw-not-implemented" |
throw-not-implemented, error-501, default-value
|
| Option | Type | Default | Description |
|---|---|---|---|
namespace |
string? | null |
Custom namespace (null = auto-detect) |
generationMode |
enum | "TypedClient" |
TypedClient or EndpointPerOperation
|
clientSuffix |
string | "Client" |
HTTP client class name suffix |
generateOAuthTokenManagement |
bool | true |
Generate OAuth2 token management |
The atc-rest-api-gen CLI is a setup tool, not a code generator itself. It:
- β Validates your OpenAPI specification
- π Creates project scaffolds with correct structure
- βοΈ Configures marker files that trigger the source generator
- π Generates
.csprojfiles with proper references
The actual code generation happens when you run dotnet build on the created projects.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π οΈ atc-rest-api-gen CLI β
β β
β 1. β
Validates OpenAPI specification β
β 2. π Creates project directories β
β 3. π Copies specification files β
β 4. βοΈ Creates marker files (.atc-rest-api-*) β
β 5. π Creates .csproj files with source generator reference β
ββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π¨ dotnet build β
β β
β 1. π Source generator reads marker file configuration β
β 2. π Source generator parses OpenAPI specification β
β 3. βοΈ Source generator emits C# code to obj/Generated/ β
β 4. π§ Compiler includes generated code in compilation β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Code | Description |
|---|---|
0 |
β Success |
1 |
β Failure (validation errors, file errors, etc.) |
π Home
- π Getting Started with Basic
- π οΈ Getting Started with CLI
- π Working with OpenAPI
- π οΈ Working with CLI
- π Working with Security
- π¦ Working with Rate Limiting
- π Working with Resilience
- ποΈ Working with Caching
- π’ Working with Versioning
- β Working with Validations
- π Analyzer Rules
- πΊοΈ Roadmap
- πͺ Showcase Demo
- π§ Development Notes
- π¦ GitHub Repository
- π₯ NuGet Package
- π Report Issues