-
Notifications
You must be signed in to change notification settings - Fork 1
Working with Multi Part Specs
This guide explains how to split large OpenAPI specifications across multiple files and use the spec merge and spec split CLI commands.
Large APIs with many endpoints become difficult to manage in a single YAML file. Multi-part specifications let teams work on different API domains independently while the generator automatically merges them at build time.
MyApi.yaml # Base file (info, servers, security)
MyApi_Accounts.yaml # Account endpoints + schemas
MyApi_Users.yaml # User endpoints + schemas
MyApi_Common.yaml # Shared schemas (PaginatedResult, Error)
Part files follow the pattern {BaseName}_{PartName}.yaml:
| Base File | Part Files |
|---|---|
MyApi.yaml |
MyApi_Accounts.yaml, MyApi_Users.yaml, MyApi_Common.yaml
|
PetStore.yaml |
PetStore_Pets.yaml, PetStore_Store.yaml
|
The generator auto-discovers part files by this naming convention.
atc-rest-api-gen spec split \
-s MyApi.yaml \
-o ./specs/ \
--strategy FirstPathSegmentSplit strategies:
| Strategy | Description |
|---|---|
FirstPathSegment |
Groups by first path segment (/users/* -> Users part) |
OpenApiTag |
Groups by operation tag |
After splitting, the base file contains shared elements:
# MyApi.yaml (base)
openapi: 3.1.1
info:
title: My Demo API
version: 1.0.0
servers:
- url: /api/v1
security:
- BearerAuth: []
# Marker for multi-part configuration
x-multipart:
enabled: true
discovery: auto
paths: {}
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearerEach part file contains only its domain's paths and schemas:
# MyApi_Users.yaml (part)
paths:
/users:
get:
operationId: listUsers
tags: [users]
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
/users/{userId}:
get:
operationId: getUserById
tags: [users]
parameters:
- name: userId
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
required: [id, name, email]
properties:
id:
type: string
format: uuid
name:
type: string
email:
type: stringMerge part files back into a single spec (for validation or external tools):
atc-rest-api-gen spec merge \
-s MyApi.yaml \
-o merged-output.yamlConfigure how conflicts are handled in the marker file:
{
"multiPartConfiguration": {
"enabled": true,
"discovery": "auto",
"pathsMergeStrategy": "ErrorOnDuplicate",
"schemasMergeStrategy": "ErrorOnDuplicate",
"parametersMergeStrategy": "MergeIfIdentical",
"tagsMergeStrategy": "AppendUnique"
}
}| Strategy | Behavior |
|---|---|
ErrorOnDuplicate |
Fail if same path/schema defined in multiple parts |
MergeIfIdentical |
Allow duplicates only if definitions are identical |
AppendUnique |
Merge by appending unique entries |
For non-standard naming, specify parts explicitly:
{
"multiPartConfiguration": {
"discovery": "explicit",
"parts": [
"specs/accounts-api.yaml",
"specs/users-api.yaml",
"specs/shared-schemas.yaml"
]
}
}The source generator automatically merges part files during build β no manual merge step needed:
- Generator detects
MyApi.yamlas the base file - Discovers
MyApi_*.yamlpart files in the same directory - Merges paths, schemas, parameters, and tags
- Generates code from the merged document
π‘ Tip: Run
spec mergebefore committing to verify no merge conflicts.
See sample/MultipartDemo/ for a working example with 6 part files across different API domains.
- Working with OpenAPI β YAML patterns and generated code
- Working with CLI β Full CLI command reference
- Marker Files β Configuration reference
π Home
- πΌ FAQ Business Value
- π Getting Started with Basic
- π οΈ Getting Started with CLI
- π Migration Guide
- β¬οΈ Upgrading to v2
- π Working with OpenAPI
- π³οΈ Working with Nullability
- π οΈ Working with CLI
- π How-To Guides
- π Working with Security
- π¦ Working with Rate Limiting
- π Working with Resilience
- ποΈ Working with Caching
- π’ Working with Versioning
- β Working with Validations
- π Working with Webhooks
- βοΈ Working with Aspire
- π£οΈ Working with Endpoint Definitions
- π Working with Multi-Part Specs
- π§ͺ Working with Code Coverage
- π Working with C# Client
- π§ͺ Working with C# Client Testing
- π¦ Working with TypeScript Client
- πͺ Showcase Demo
- π§ͺ Working with E2E Testing
- βοΈ Working with Configuration
- π Marker Files
- π API Reference
- π Analyzer Rules
- β FAQ and Troubleshooting
- πΊοΈ Roadmap
- π§ Development Notes
- π¦ GitHub Repository
- π₯ NuGet Package
- π Report Issues