用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/rudironsoni/Synaxis --skill dotnet-openapi命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Routes .NET/C# work to domain skills. Loads coding-standards for code paths.
基于 SOC 职业分类
正在显示 SKILL.md
| name | dotnet-openapi |
| category | web |
| subcategory | minimal-apis |
| description | Generates OpenAPI docs. MS.AspNetCore.OpenApi (.NET 9+), Swashbuckle migration, NSwag. |
| license | MIT |
| targets | ["*"] |
| tags | ["api","dotnet","skill"] |
| version | 0.0.1 |
| author | dotnet-agent-harness |
| invocable | true |
| claudecode | {"allowed-tools":["Read","Grep","Glob","Bash","Write","Edit"]} |
| codexcli | {"short-description":".NET skill guidance for api tasks"} |
| opencode | {"allowed-tools":["Read","Grep","Glob","Bash","Write","Edit"]} |
| copilot | {} |
| geminicli | {} |
| antigravity | {} |
OpenAPI/Swagger integration for ASP.NET Core. Microsoft.AspNetCore.OpenApi is the recommended first-party approach for .NET 9+ and is the default in new project templates. Swashbuckle is no longer actively maintained; existing projects using Swashbuckle should plan migration. NSwag remains an alternative for client generation and advanced scenarios.
Cross-references: [skill:dotnet-minimal-apis] for endpoint patterns that generate OpenAPI metadata, [skill:dotnet-api-versioning] for versioned OpenAPI documents.
Microsoft.AspNetCore.OpenApi is the first-party OpenAPI package for ASP.NET Core 9+ and is included by default in new project templates. .NET 10 adds OpenAPI 3.1 support with JSON Schema draft 2020-12 compliance.
// Microsoft.AspNetCore.OpenApi -- included by default in .NET 9+ project templates
// If not present, add: <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.*" />
// Version must match the project's target framework major version
builder.Services.AddOpenApi();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi(); // Serves /openapi/v1.json
}
```json
### Multiple Documents
Generate separate OpenAPI documents per API version or functional group:
```csharp
builder.Services.AddOpenApi("v1", options =>
{
options.OpenApiVersion = OpenApiSpecVersion.OpenApi3_0;
});
builder.Services.AddOpenApi("v2", options =>
{
options.OpenApiVersion = OpenApiSpecVersion.OpenApi3_1;
});
var app = builder.Build();
app.MapOpenApi(); // Serves /openapi/v1.json and /openapi/v2.json
```json
---
Document transformers modify the generated OpenAPI document after it built. Use them to server information, security schemes, custom metadata.
```csharp
:
{
{
document.Components ??= OpenApiComponents();
document.Components.SecuritySchemes[] = OpenApiSecurityScheme
{
Type = SecuritySchemeType.Http,
Scheme = ,
BearerFormat = ,
Description =
};
document.SecurityRequirements.Add( OpenApiSecurityRequirement
{
[] = Array.Empty<>()
});
Task.CompletedTask;
}
}
builder.Services.AddOpenApi(options =>
{
options.AddDocumentTransformer<SecuritySchemeTransformer>();
});
```text
For simple transformations, use the lambda overload:
```csharp
builder.Services.AddOpenApi(options =>
{
options.AddDocumentTransformer((document, context, ct) =>
{
document.Info = OpenApiInfo
{
Title = ,
Version = ,
Description = ,
Contact = OpenApiContact
{
Name = ,
Email =
}
};
Task.CompletedTask;
});
});
```text
---
{
{
deprecatedAttr = context.Description.ActionDescriptor
.EndpointMetadata
.OfType<ObsoleteAttribute>()
.FirstOrDefault();
(deprecatedAttr )
{
operation.Deprecated = ;
operation.Description = ;
}
Task.CompletedTask;
}
}
builder.Services.AddOpenApi(options =>
{
options.AddOperationTransformer<DeprecationTransformer>();
});
```text
---
Customize how .NET types map to OpenAPI schemas schema transformers:
```csharp
builder.Services.AddOpenApi(options =>
{
options.AddSchemaTransformer((schema, context, ct) =>
{
(context.JsonTypeInfo.Type == (ProductDto))
{
schema.Example = OpenApiObject
{
[] = OpenApiInteger(),
[] = OpenApiString(),
[] = OpenApiDouble()
};
}
Task.CompletedTask;
});
});
```text
Use fluent methods endpoint builders to provide richer OpenAPI metadata:
```csharp
products.MapGet(, GetProductById)
.WithName()
.WithSummary()
.WithDescription()
.WithTags()
.Produces<Product>(StatusCodes.Status200OK)
.ProducesProblem(StatusCodes.Status404NotFound);
```text
---
Swashbuckle (`Swashbuckle.AspNetCore`) no longer actively maintained. It does support OpenAPI . Existing projects should plan migration to `Microsoft.AspNetCore.OpenApi`.
**When Swashbuckle still needed:** Projects .NET that cannot upgrade to .NET +, projects that depend Swashbuckle-= Version= /> -->
<!-- <PackageReference Include= Version= /> -->
```xml
Replace service registration:
```csharp
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc(, OpenApiInfo { Title = , Version = });
});
builder.Services.AddOpenApi();
```text
Replace middleware:
```csharp
app.UseSwagger();
app.UseSwaggerUI();
app.MapOpenApi();
```json
For Swagger UI, a standalone UI package use Scalar:
```csharp
app.MapScalarApiReference();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint(, );
});
```json
Migrate Swashbuckle filters to transformers:
| Swashbuckle concept | Built- replacement |
|---------------------|---------------------|
| `IDocumentFilter` | `IOpenApiDocumentTransformer` |
| `IOperationFilter` | `IOpenApiOperationTransformer` |
| `ISchemaFilter` | Schema transformers via `AddSchemaTransformer` |
| `[SwaggerOperation]` | `.WithSummary()`, `.WithDescription()` |
| `[SwaggerResponse]` | `.Produces<T>()`, `TypedResults` |
---
NSwag an alternative OpenAPI toolchain that includes document generation, ;
app = builder.Build();
app.UseOpenApi();
app.UseSwaggerUi();
```json
NSwag generates typed C
```bash
dotnet tool install -- NSwag.ConsoleCore
nswag openapi2csclient /input:https:
/output:GeneratedClient.cs \
/: \
/:
```
**:** `` . . .
---
## 3.1 (. 10)
. 10 3.1 2020-12 . 3.0:
- ** :** `: ["", ""]` `: `
- ** :** /
- **:** -
- ** :** 2020-12
```
( =>
{
options.OpenApiVersion = OpenApiSpecVersion.OpenApi3_1;
});
```text
**Gotcha:** Swashbuckle does support OpenAPI . Projects requiring features must migrate to `Microsoft.AspNetCore.OpenApi`.
---
**Do pin mismatched major versions of `Microsoft.AspNetCore.OpenApi`** -- the package version must match the project
Primary approach: Use Serena symbol operations for efficient code navigation:
serena_find_symbol instead of text searchserena_get_symbols_overview for file organizationserena_find_referencing_symbols for impact analysisserena_replace_symbol_body for clean modificationsWhen to use Serena vs traditional tools:
Example workflow:
# Instead of:
Read: src/Services/OrderService.cs
Grep: "public void ProcessOrder"
# Use:
serena_find_symbol: "OrderService/ProcessOrder"
serena_get_symbols_overview: "src/Services/OrderService.cs"