Skip to content

Commit 4c0c95f

Browse files
committed
doc: added instructions for claude and copilot
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 76784f4 commit 4c0c95f

2 files changed

Lines changed: 42 additions & 30 deletions

File tree

.claude/CLAUDE.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,45 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
Go implementation of [JSON Pointer (RFC 6901)](https://datatracker.ietf.org/doc/html/rfc6901) for navigating
8-
and mutating JSON documents represented as Go values. Unlike most implementations, it works not only with
9-
`map[string]any` and slices, but also with Go structs (resolved via `json` struct tags and reflection).
7+
Go library for validating OpenAPI v2 (Swagger) specifications and JSON Schema draft 4 data.
8+
It is part of the [go-openapi](https://github.com/go-openapi) ecosystem and used by [go-swagger](https://github.com/go-swagger/go-swagger).
9+
10+
The library provides two main capabilities:
11+
1. **Spec validation** — validates a Swagger 2.0 spec document against the JSON meta-schema, plus extra semantic rules (path uniqueness, parameter consistency, $ref resolution, etc.)
12+
2. **Schema validation** — validates arbitrary data against a JSON Schema draft 4 schema (tested against the official JSON-Schema-Test-Suite)
13+
14+
API is stable. This is legacy/maintenance code — deep refactoring is not worthwhile;
15+
a ground-up replacement is the long-term plan.
1016

1117
See [docs/MAINTAINERS.md](../docs/MAINTAINERS.md) for CI/CD, release process, and repo structure details.
1218

13-
### Package layout (single package)
19+
### Package layout
1420

15-
| File | Contents |
16-
|------|----------|
17-
| `pointer.go` | Core types (`Pointer`, `JSONPointable`, `JSONSetable`), `New`, `Get`, `Set`, `Offset`, `Escape`/`Unescape` |
18-
| `errors.go` | Sentinel errors: `ErrPointer`, `ErrInvalidStart`, `ErrUnsupportedValueType` |
21+
| Package | Contents |
22+
|---------|----------|
23+
| `validate` (root) | Spec validator (`SpecValidator`), schema validator (`SchemaValidator`), `AgainstSchema()`, individual type/format/object/slice/string/number validators, result handling, pools |
24+
| `post` | Post-validation transforms: `ApplyDefaults` (fills in schema defaults) and `Prune` (removes additional properties) |
1925

2026
### Key API
2127

22-
- `New(string) (Pointer, error)` — parse a JSON pointer string (e.g. `"/foo/0/bar"`)
23-
- `Pointer.Get(document any) (any, reflect.Kind, error)` — retrieve a value
24-
- `Pointer.Set(document, value any) (any, error)` — set a value (document must be pointer/map/slice)
25-
- `Pointer.Offset(jsonString string) (int64, error)` — byte offset of token in raw JSON
26-
- `GetForToken` / `SetForToken` — single-level convenience helpers
27-
- `Escape` / `Unescape` — RFC 6901 token escaping (`~0``~`, `~1``/`)
28-
29-
Custom types can implement `JSONPointable` (for Get) or `JSONSetable` (for Set) to bypass reflection.
28+
- `Spec(doc, formats) error` — high-level spec validation
29+
- `NewSpecValidator(schema, formats) *SpecValidator` — configurable spec validator
30+
- `AgainstSchema(schema, data, formats, ...Option) error` — validate data against a JSON schema
31+
- `NewSchemaValidator(schema, root, path, formats, ...Option) *SchemaValidator` — configurable schema validator
32+
- `post.ApplyDefaults(result)` — apply default values from validation result
33+
- `post.Prune(result)` — remove undeclared properties from validation result
3034

3135
### Dependencies
3236

33-
- `github.com/go-openapi/swag/jsonname` — struct tag → JSON field name resolution
34-
- `github.com/go-openapi/testify/v2` — test-only assertions
35-
36-
### Notable historical design decisions
37+
Key runtime dependencies (see `go.mod` for full list):
38+
- `github.com/go-openapi/spec` — Swagger 2.0 spec model
39+
- `github.com/go-openapi/analysis` — spec analysis and flattening
40+
- `github.com/go-openapi/loads` — spec loading (used in tests/examples)
41+
- `github.com/go-openapi/errors` — structured validation errors
42+
- `github.com/go-openapi/strfmt` — format registry (date-time, uuid, email, etc.)
43+
- `github.com/go-openapi/testify/v2` — test-only assertions (zero-dep testify fork)
3744

38-
See also .claude/plans/ROADMAP.md.
45+
### Architecture notes
3946

40-
- Struct fields **must** have a `json` tag to be reachable; untagged fields are ignored
41-
(differs from `encoding/json` which defaults to the Go field name).
42-
- Anonymous embedded struct fields are traversed only if tagged.
43-
- The RFC 6901 `"-"` array suffix (append) is **not** implemented.
47+
The validator chain is built from `valueValidator` implementations (type, format, string, number, slice, object, common, schemaProps), assembled by `SchemaValidator`. Validators and results are pooled for performance (`pools.go`). The codebase has known complexity issues (many `//nolint:gocognit` deferrals) stemming from the original design.
4448

.github/copilot-instructions.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22

33
## Project Overview
44

5-
Go implementation of a OpenAPI v2 (swagger) validator and JSON Schema draft 4 validator
5+
Go library for validating OpenAPI v2 (Swagger) specifications and JSON Schema draft 4 data.
6+
Part of the [go-openapi](https://github.com/go-openapi) ecosystem. API is stable; maintenance-only.
67

7-
## Package Layout (single package)
8+
## Package Layout
89

9-
| File | Contents |
10-
|------|----------|
10+
| Package | Contents |
11+
|---------|----------|
12+
| `validate` (root) | Spec validator, schema validator, type/format/object/slice/string/number validators, result handling, pools |
13+
| `post` | Post-validation transforms: `ApplyDefaults` and `Prune` |
1114

1215
## Key API
1316

14-
## Design Decisions
17+
- `Spec(doc, formats) error` — high-level spec validation
18+
- `AgainstSchema(schema, data, formats, ...Option) error` — validate data against a JSON schema
19+
- `NewSchemaValidator(schema, root, path, formats, ...Option) *SchemaValidator`
20+
- `post.ApplyDefaults(result)` / `post.Prune(result)`
1521

1622
## Dependencies
1723

24+
- `github.com/go-openapi/spec`, `analysis`, `loads`, `errors`, `strfmt`
25+
1826
## Conventions
1927

2028
- All `.go` files must have SPDX license headers (Apache-2.0).

0 commit comments

Comments
 (0)