Skip to content

Commit 93beb5a

Browse files
docs: make the GO.md snippet runnable
The original snippet was diff.Get(&diff.Config{}, spec1, spec2) — but spec1 and spec2 were undefined and a reader couldn't actually run it. Adds the imports and the kin-openapi LoadFromFile calls so the example is a complete, copyable program. Switches to diff.NewConfig() and notes why (the constructor initializes maps that &diff.Config{} leaves nil). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 82b32ca commit 93beb5a

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

docs/GO.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
## Notes for Go Developers
22

33
### Embedding oasdiff into your program
4-
The simplest way to get a diff in your go program is:
4+
Load each spec with the kin-openapi loader, then call `diff.Get`:
5+
56
```go
6-
diff.Get(&diff.Config{}, spec1, spec2)
7+
import (
8+
"github.com/getkin/kin-openapi/openapi3"
9+
"github.com/oasdiff/oasdiff/diff"
10+
)
11+
12+
loader := openapi3.NewLoader()
13+
14+
s1, err := loader.LoadFromFile("base.yaml")
15+
// handle err
16+
17+
s2, err := loader.LoadFromFile("revision.yaml")
18+
// handle err
19+
20+
diffReport, err := diff.Get(diff.NewConfig(), s1, s2)
21+
// handle err
722
```
823

9-
### Advanced Examples
24+
Use `diff.NewConfig()` rather than `&diff.Config{}` — the constructor initializes internal maps that the diff engine expects to be non-nil.
25+
26+
### Runnable Examples
1027
- [diff](https://pkg.go.dev/github.com/oasdiff/oasdiff/diff#example-Get)
1128
- [breaking changes](https://pkg.go.dev/github.com/oasdiff/oasdiff/diff#example-GetPathsDiff)
1229

13-
1430
### OpenAPI References
15-
Note that oasdiff expects [OpenAPI References](https://swagger.io/docs/specification/using-ref/) to be resolved.
16-
References are normally resolved automatically when you load the spec. In other cases you can resolve refs using [Loader.ResolveRefsIn](https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#Loader.ResolveRefsIn).
31+
oasdiff expects [OpenAPI references](https://swagger.io/docs/specification/using-ref/) to be resolved. The kin-openapi loader resolves them automatically when you load the spec; if you build a spec another way, resolve them with [Loader.ResolveRefsIn](https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#Loader.ResolveRefsIn).

0 commit comments

Comments
 (0)