agentleFS
zdanovichnickzdanovichnick/dotnet-pilot/skills/api-contract/SKILL.md

api-contract

Skill5 starsChanged 22 days agoMITView on GitHub

The seam between an ASP.NET Core API and its TypeScript client — the contract format, generating TypeScript types from the API's OpenAPI document, and the C#-to-JSON mismatches that break the client.

20 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use design-system, release-notes and 4 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • AnthropicSkill

    design-system

    Audit, document, or extend your design system. Use when checking for naming inconsistencies or hardcoded values across components, writing documentation for a component's variants, states, and accessibility notes, or designing a new pattern that fits the existing system.

    Also in 4 projects that use this

  • Microsoft AzureSkill

    release-notes

    Author and update release notes for Azure App Configuration libraries and providers. USE FOR: write release notes, add release note entry, update release notes, draft release notes, new version release notes, format release notes. DO NOT USE FOR: generating changelogs from git history, writing internal engineering notes.

    Also in 4 projects that use this

  • OpenAISkill

    systematic-debugging

    Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

    Also in 3 projects that use this

  • CloudflareSkill

    security-audit

    Security guidance and vulnerability review for codebases, APIs, services, CLI tools, libraries, and daemons. Use for security questions, focused reviews, vulnerability research, security audits, or pen tests. Run the complete workflow only for explicit codebase audit or pen-test requests, full/comprehensive/end-to-end reviews, or requested report artifacts.

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 5 projects that use this

  • MicrosoftSkill

    release

    Use ONLY when the user explicitly asks to cut/publish a Huabu desktop release or tag a version. Performs an outward action — bumps the version in apps/desktop/package.json, commits + annotated-tags vX.Y.Z, and pushes the branch + tag. That tag push auto-builds the macOS/Windows installers and publishes a GitHub Release. Provides `status`, `bump`, `tag-push`, and a one-command `run` (bump → tag-push).

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 14 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When the project has none, the build-time document plus openapi-typescript is the default:

    line 49

“Common” is measured: kept by at least 6 in 10 of the 14 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Contract

One contract, written before either side is coded. The server implements it, the client consumes it, and generated types prove afterwards that the two agree.

Contract format

State every point; a point left out is a point the two sides will guess differently.

POST /api/orders/{orderId}/notes        auth: Bearer, policy "Orders.Write"

Request   { "text": string (1..2000), "pinned": boolean? }
201       { "id": string (guid), "text": string, "pinned": boolean, "createdAt": string (ISO 8601) }
400       ProblemDetails + errors: { "text": ["..."] }      validation failed
404       ProblemDetails                                    order not found
409       ProblemDetails, type ".../order-closed"           order is closed
  • Property names are the wire names (camelCase by default), not the C# names.
  • Mark each property required, optional (may be absent) or nullable (present, may be null).
  • List every status code the client must handle. Each one needs a UI answer.

The seam module

The client declares the contract's types in one module (for example src/api/orders.ts) and every component imports them from there. While the API is being built, the types are written by hand from the contract. Afterwards the module re-exports the generated types, so a mismatch is a compiler error in one known file and not a runtime surprise in a component.

import type { components } from './schema';

export type OrderNote = components['schemas']['OrderNoteResponse'];
export type CreateOrderNote = components['schemas']['CreateOrderNoteRequest'];

Generating the types

An existing script in the client's package.json wins. Use it and do not add a second generator (openapi-typescript, orval, NSwag and hand-written fetch types do not mix).

When the project has none, the build-time document plus openapi-typescript is the default:

<!-- API .csproj -->
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="..." PrivateAssets="all" />
<PropertyGroup>
  <OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild>
  <OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)/openapi</OpenApiDocumentsDirectory>
</PropertyGroup>
dotnet build <Api.csproj>
npx openapi-typescript <path>/<ApiProject>.json -o <frontend>/src/api/schema.d.ts
npx tsc --noEmit -p <frontend>
  • Without OpenApiDocumentsDirectory the document lands in obj/, named after the project.
  • Adding the package is a package decision. Ask before adding it.
  • Build-time generation runs the app's startup code. An API whose startup needs a live database or a secret store can fail to generate. Guard that code on the entry assembly, or fall back to the existing script.
  • Generate from the document the local build produced. A script that downloads the document from a deployed environment cannot see an endpoint that is not deployed yet.
  • With openapi-fetch, createClient<paths>() types the routes too, so a wrong URL or verb is also a compiler error.

Server-side OpenAPI setup (AddOpenApi, transformers, one document per API version) is in skills/aspnet-api-patterns/SKILL.md.

Mismatches that bite

C# sideOn the wireTypeScript consequence
PascalCase propertycamelCase by defaultA hand-typed OrderId reads undefined. A [JsonPropertyName] or a naming-policy change renames the wire field
enumnumber by defaultstatus === 'Shipped' is never true. A string union is correct only when JsonStringEnumConverter is registered
DateTime, DateTimeOffset, DateOnlyISO 8601 stringThe type is string, not Date. Parse at the seam. DateTime with Kind=Unspecified carries no offset, so the browser reads it as local time
long, ulongJSON numberValues above 2^53 lose precision in JavaScript. Send identifiers of that size as strings
decimalJSON numberBecomes a binary float. Do not do money arithmetic on it in the client
GuidstringNo client-side type check beyond string
string? vs stringnullable vs requiredFollows nullable reference types. A project with nullable disabled reports everything as optional
T? property that is omitted when nullabsent, not nullprop?: T and prop: T | null are different types. Match the serializer's DefaultIgnoreCondition
Dictionary<string, T>objectRecord<string, T>. Keys keep their original casing; the naming policy does not touch them
Error resultapplication/problem+jsonThe error body is ProblemDetails (type, title, status, detail, plus errors for validation), not the success type. Type both branches

A 200 with an empty body, a 204, and a 201 with a Location header are three different client code paths. The contract says which one.

Contract changes

The contract is fixed once both sides start. A side that needs a change stops and reports it; it does not edit its own half and continue. The other side is working from the old text.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.