Skip to content

Commit 53f8970

Browse files
fredbiclaude
andauthored
doc: add portable agentic instructions (#101)
* doc: add portable agentic instructions Add CLAUDE.md, copilot-instructions.md, AGENTS.md (symlink), .github/copilot symlink to .claude/rules, contributions rule, and GitHub workflows conventions rule. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com> * doc: include previously ignored rule files Add linting.md and testing.md rules that were hidden by the old .gitignore pattern. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com> --------- Signed-off-by: Frederic BIDON <fredbi@yahoo.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 97f7e4c commit 53f8970

11 files changed

Lines changed: 519 additions & 1 deletion

.claude/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
plans/
2+
skills/
3+
commands/
4+
agents/
5+
hooks/

.claude/CLAUDE.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This package provides structured error types for the go-openapi/go-swagger ecosystem.
8+
It defines an `Error` interface (with an HTTP status code and message) and concrete types
9+
for validation failures, parsing errors, authentication errors, and HTTP middleware errors.
10+
These error types are consumed by validators, spec loaders, and API runtimes to report
11+
problems back to API consumers in a structured, JSON-serializable way.
12+
13+
See [docs/MAINTAINERS.md](../docs/MAINTAINERS.md) for CI/CD, release process, and repo structure details.
14+
15+
### Package layout
16+
17+
| File | Contents |
18+
|------|----------|
19+
| `doc.go` | Package-level godoc |
20+
| `api.go` | Core `Error` interface, `apiError` struct, `New`/`NotFound`/`NotImplemented`/`MethodNotAllowed` constructors, `ServeError` HTTP handler, `CompositeError` flattening |
21+
| `schema.go` | `Validation` struct, `CompositeError` struct, and ~30 constructor functions for JSON Schema / OpenAPI validation failures (type, required, enum, min/max, pattern, etc.); error code constants (`InvalidTypeCode`, `RequiredFailCode`, ...) |
22+
| `headers.go` | `Validation` constructors for HTTP header errors: `InvalidContentType`, `InvalidResponseFormat` |
23+
| `parsing.go` | `ParseError` struct and `NewParseError` constructor for parameter parsing failures |
24+
| `auth.go` | `Unauthenticated` constructor (401) |
25+
| `middleware.go` | `APIVerificationFailed` struct for mismatches between spec and registered handlers |
26+
27+
### Key API
28+
29+
- `Error` interface -- `error` + `Code() int32`
30+
- `New(code, message, args...)` -- general-purpose error constructor
31+
- `NotFound` / `NotImplemented` / `MethodNotAllowed` / `Unauthenticated` -- HTTP error constructors
32+
- `Validation` struct -- carries `Name`, `In`, `Value` context for validation failures
33+
- ~30 validation constructors: `Required`, `InvalidType`, `TooLong`, `TooShort`, `EnumFail`, `ExceedsMaximum`, `FailedPattern`, `DuplicateItems`, `TooManyItems`, `TooFewItems`, `PropertyNotAllowed`, `CompositeValidationError`, etc.
34+
- `CompositeError` -- groups multiple errors; implements `Unwrap() []error`
35+
- `ServeError(rw, r, err)` -- HTTP handler that serializes any `Error` to JSON
36+
- `ParseError` -- parsing failure with `Name`, `In`, `Value`, `Reason`
37+
38+
### Dependencies
39+
40+
- `github.com/go-openapi/testify/v2` -- test-only assertions (zero-dep testify fork)
41+
42+
This package has **zero runtime dependencies** outside the Go standard library.
43+
44+
### Notable design decisions
45+
46+
- **Error codes above 599 are domain codes, not HTTP codes** -- validation error codes (`InvalidTypeCode = 600`, `RequiredFailCode = 601`, ...) use values >= 600 so they can be distinguished from real HTTP status codes. `ServeError` maps any code >= 600 to `DefaultHTTPCode` (422).
47+
- **`Validation.ValidateName` mutates in place** -- callers chain `.ValidateName(name)` to prepend parent property names for nested validation errors, building dotted paths like `address.street`.
48+
- **All error types implement `json.Marshaler`** -- errors serialize to structured JSON with `code`, `message`, and type-specific fields (`name`, `in`, `value`), not just a string.
49+
- **`CompositeError` flattens recursively** -- `ServeError` flattens nested `CompositeError` trees and serves only the first leaf error to avoid overwhelming API consumers.

.claude/rules/contributions.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
paths:
3+
- "**/*"
4+
---
5+
6+
# Contribution rules (go-openapi)
7+
8+
Read `.github/CONTRIBUTING.md` before opening a pull request.
9+
10+
## Commit hygiene
11+
12+
- Every commit **must** be DCO signed-off (`git commit -s`) with a real email address.
13+
PGP-signed commits are appreciated but not required.
14+
- Agents may be listed as co-authors (`Co-Authored-By:`) but the commit **author must be the human sponsor**.
15+
We do not accept commits solely authored by bots or agents.
16+
- Squash commits into logical units of work before requesting review (`git rebase -i`).
17+
18+
## Linting
19+
20+
Before pushing, verify your changes pass linting against the base branch:
21+
22+
```sh
23+
golangci-lint run --new-from-rev master
24+
```
25+
26+
Install the latest version if you don't have it:
27+
28+
```sh
29+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
30+
```
31+
32+
## Problem statement
33+
34+
- Clearly describe the problem the PR solves, or reference an existing issue.
35+
- PR descriptions must not be vague ("fix bug", "improve code") — explain *what* was wrong and *why* the change is correct.
36+
37+
## Tests are mandatory
38+
39+
- Every bug fix or feature **must** include tests that demonstrate the problem and verify the fix.
40+
- The only exceptions are documentation changes and typo fixes.
41+
- Aim for at least 80% coverage of your patch.
42+
- Run the full test suite before submitting:
43+
44+
For mono-repos:
45+
```sh
46+
go test work ./...
47+
```
48+
49+
For single module repos:
50+
```sh
51+
go test ./...
52+
```

0 commit comments

Comments
 (0)