Commit 2b424bf
perf(fixer): skip defensive deep copy when caller owns document (#297)
* perf(fixer): skip defensive deep copy when caller owns document
The fixer deep-copies parsed documents before mutating them, protecting
callers who reuse the input. Three code paths in the CLI never reuse the
parsed document, so the copy is wasted work:
- Fix() parses internally and owns the result — now sets MutableInput
with defer-based save/restore for panic safety
- CLI stdin path owns its locally-parsed result
- CLI source-map path owns its locally-parsed result
Also modernizes isFixEnabled to use slices.Contains (gopls hint).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test(fixer): add coverage for Fix() mutable input save/restore
Exercises the Fix(path) code path to cover the new MutableInput
save/restore logic, and verifies the field is restored after return.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test(fixer): add subtest for MutableInput=true save/restore
Addresses CodeRabbit review: the false→false case would also pass if
Fix() hardcoded false instead of saving/restoring. The true→true
subtest validates the defer actually restores the original value.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test(fixer): add parse-error subtest for Fix() MutableInput
Addresses CodeRabbit review: adds error-path subtest. Note this tests
the early-return path (parse failure at line 408, before save/restore),
not the defer — the field is untouched, not restored.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(docs): correct dangerous deep copy advice in copilot instructions
The previous guideline recommended JSON marshal/unmarshal for deep
copying OAS documents — this silently loses interface{} type
distinctions (string vs []string in OAS 3.1 schema.Type) and drops
json:"-" fields. Updated to recommend the generated DeepCopy() methods
and document the WithMutableInput(true) opt-in for owned documents.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(docs): replace JSON marshal deep copy advice across all docs
Audit found locations recommending JSON marshal/unmarshal for deep
copying OAS documents. This approach silently loses interface{} type
distinctions (string vs []string in OAS 3.1 schema.Type) and drops
json:"-" fields.
Updated all to recommend generated DeepCopy() methods instead.
Files fixed:
- AGENTS.md
- .claude/docs/oas-concepts.md
- .claude/agents/developer.md
- CONTRIBUTORS.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs(claude): add deep copy, make check, and docs/ generation guidance
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent a6ba2b4 commit 2b424bf
9 files changed
Lines changed: 49 additions & 15 deletions
File tree
- .claude
- agents
- docs
- .github
- cmd/oastools/commands
- fixer
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
177 | | - | |
178 | | - | |
| 176 | + | |
179 | 177 | | |
180 | 178 | | |
181 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
617 | | - | |
618 | | - | |
619 | | - | |
| 617 | + | |
620 | 618 | | |
621 | 619 | | |
622 | 620 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| |||
264 | 265 | | |
265 | 266 | | |
266 | 267 | | |
| 268 | + | |
267 | 269 | | |
268 | 270 | | |
269 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
407 | 408 | | |
408 | 409 | | |
409 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
410 | 415 | | |
411 | 416 | | |
412 | 417 | | |
| |||
445 | 450 | | |
446 | 451 | | |
447 | 452 | | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
| 453 | + | |
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
0 commit comments