Skip to content

Commit 1c22946

Browse files
committed
Update dependencies to latest versions
- Upgrade libopenapi from v0.21.8 to v0.36.1 - Migrate yaml dependency from gopkg.in/yaml.v3 to go.yaml.in/yaml/v4 - Fix shared schema mutation bug in allOf resolution: libopenapi v0.34+ reuses the same *base.Schema instance for all references to the same $ref target. Shallow-copy the schema before overriding the description to prevent corruption across properties sharing a reference. - Adapt to BuildV3Model() returning single error instead of []error - Regenerate golden test files
1 parent 7250fcf commit 1c22946

12 files changed

Lines changed: 177 additions & 219 deletions

File tree

go.mod

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
module github.com/doitintl/terraform-plugin-codegen-openapi
22

3-
go 1.23.0
4-
5-
toolchain go1.24.0
3+
go 1.25.0
64

75
require (
86
github.com/google/go-cmp v0.7.0
97
github.com/hashicorp/cli v1.1.7
108
github.com/hashicorp/terraform-plugin-codegen-spec v0.2.0
119
github.com/mattn/go-colorable v0.1.14
12-
github.com/pb33f/libopenapi v0.21.8
10+
github.com/pb33f/libopenapi v0.36.1
11+
go.yaml.in/yaml/v4 v4.0.0-rc.4
1312
gopkg.in/yaml.v3 v3.0.1
1413
)
1514

1615
require (
16+
dario.cat/mergo v1.0.2 // indirect
1717
github.com/Masterminds/goutils v1.1.1 // indirect
18-
github.com/Masterminds/semver/v3 v3.2.0 // indirect
19-
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
18+
github.com/Masterminds/semver/v3 v3.4.0 // indirect
19+
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
2020
github.com/armon/go-radix v1.0.0 // indirect
2121
github.com/bahlo/generic-list-go v0.2.0 // indirect
22-
github.com/bgentry/speakeasy v0.1.0 // indirect
23-
github.com/buger/jsonparser v1.1.1 // indirect
24-
github.com/fatih/color v1.16.0 // indirect
25-
github.com/google/uuid v1.3.0 // indirect
22+
github.com/bgentry/speakeasy v0.2.0 // indirect
23+
github.com/buger/jsonparser v1.1.2 // indirect
24+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
25+
github.com/fatih/color v1.19.0 // indirect
26+
github.com/google/uuid v1.6.0 // indirect
2627
github.com/hashicorp/errwrap v1.1.0 // indirect
2728
github.com/hashicorp/go-multierror v1.1.1 // indirect
28-
github.com/huandu/xstrings v1.4.0 // indirect
29-
github.com/imdario/mergo v0.3.15 // indirect
30-
github.com/mailru/easyjson v0.7.7 // indirect
31-
github.com/mattn/go-isatty v0.0.20 // indirect
29+
github.com/huandu/xstrings v1.5.0 // indirect
30+
github.com/mattn/go-isatty v0.0.21 // indirect
3231
github.com/mitchellh/copystructure v1.2.0 // indirect
3332
github.com/mitchellh/reflectwalk v1.0.2 // indirect
33+
github.com/pb33f/jsonpath v0.8.2 // indirect
34+
github.com/pb33f/ordered-map/v2 v2.3.1 // indirect
35+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3436
github.com/posener/complete v1.2.3 // indirect
35-
github.com/shopspring/decimal v1.3.1 // indirect
36-
github.com/speakeasy-api/jsonpath v0.6.1 // indirect
37-
github.com/spf13/cast v1.5.0 // indirect
38-
github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd // indirect
39-
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
37+
github.com/shopspring/decimal v1.4.0 // indirect
38+
github.com/spf13/cast v1.10.0 // indirect
39+
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
4040
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
4141
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
42-
golang.org/x/crypto v0.32.0 // indirect
43-
golang.org/x/sys v0.29.0 // indirect
42+
golang.org/x/crypto v0.50.0 // indirect
43+
golang.org/x/sync v0.20.0 // indirect
44+
golang.org/x/sys v0.43.0 // indirect
4445
)

go.sum

Lines changed: 50 additions & 86 deletions
Large diffs are not rendered by default.

internal/cmd/generate.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package cmd
66
import (
77
"context"
88
"encoding/json"
9-
"errors"
109
"flag"
1110
"fmt"
1211
"log/slog"
@@ -20,7 +19,6 @@ import (
2019

2120
"github.com/hashicorp/cli"
2221
"github.com/pb33f/libopenapi"
23-
"github.com/pb33f/libopenapi/index"
2422
)
2523

2624
type GenerateCommand struct {
@@ -130,20 +128,14 @@ func (cmd *GenerateCommand) runInternal(logger *slog.Logger) error {
130128
// 3. Build out the OpenAPI model, this will recursively load all local + remote references into one cohesive model
131129
model, errs := doc.BuildV3Model()
132130

133-
// 4. Log circular references as warnings and fail on any other model building errors
134-
var errResult error
135-
for _, err := range errs {
136-
if rslvErr, ok := err.(*index.ResolvingError); ok {
137-
logger.Warn(
138-
"circular reference found in OpenAPI spec",
139-
"circular_ref", rslvErr.CircularReference.GenerateJourneyPath())
140-
continue
141-
}
142-
143-
errResult = errors.Join(errResult, err)
131+
// 4. Log circular references as warnings; fail only on fatal errors.
132+
// libopenapi guarantees: nil model = fatal error, non-nil model with non-nil err = circular refs only.
133+
// Circular references are non-fatal and the generated model is still usable.
134+
if model == nil && errs != nil {
135+
return fmt.Errorf("error building OpenAPI 3.x model: %w", errs)
144136
}
145-
if errResult != nil {
146-
return fmt.Errorf("error building OpenAPI 3.x model: %w", errResult)
137+
if errs != nil {
138+
logger.Warn("circular reference(s) found in OpenAPI spec, proceeding", "err", errs)
147139
}
148140

149141
// 5. Generate provider code spec w/ config

internal/cmd/testdata/kubernetes/provider_code_spec.json

Lines changed: 81 additions & 81 deletions
Large diffs are not rendered by default.

internal/explorer/config_explorer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func extractCommonParameters(paths *high.Paths, path string) ([]*high.Parameter,
175175

176176
func extractSchemaProxy(document high.Document, componentRef string) (*highbase.SchemaProxy, error) {
177177
// find the reference using the root document.Index
178-
indexRef := document.Index.FindComponentInRoot(componentRef)
178+
indexRef := document.Index.FindComponentInRoot(context.Background(), componentRef)
179179
if indexRef == nil {
180180
return nil, fmt.Errorf("unable to find reference: %s", componentRef)
181181
}

internal/explorer/config_explorer_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"testing"
1010

11-
"gopkg.in/yaml.v3"
11+
yaml "go.yaml.in/yaml/v4"
1212

1313
"github.com/doitintl/terraform-plugin-codegen-openapi/internal/config"
1414
"github.com/doitintl/terraform-plugin-codegen-openapi/internal/explorer"
@@ -637,13 +637,9 @@ components:
637637
return high.Document{}, fmt.Errorf("unexpected error parsing test OAS: %w", err)
638638
}
639639

640-
testOASModel, errs := doc.BuildV3Model()
641-
if len(errs) > 0 {
642-
var errResult error
643-
for _, err := range errs {
644-
errResult = errors.Join(errResult, err)
645-
}
646-
return high.Document{}, fmt.Errorf("unexpected error building test OAS: %w", errResult)
640+
testOASModel, err := doc.BuildV3Model()
641+
if testOASModel == nil && err != nil {
642+
return high.Document{}, fmt.Errorf("unexpected error building test OAS: %w", err)
647643
}
648644

649645
return testOASModel.Model, nil

internal/mapper/oas/bool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-codegen-spec/provider"
1111
"github.com/hashicorp/terraform-plugin-codegen-spec/resource"
1212
"github.com/hashicorp/terraform-plugin-codegen-spec/schema"
13-
"gopkg.in/yaml.v3"
13+
yaml "go.yaml.in/yaml/v4"
1414

1515
"github.com/doitintl/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1616
"github.com/doitintl/terraform-plugin-codegen-openapi/internal/mapper/oas"

internal/mapper/oas/build.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ func buildSchemaProxy(proxy *base.SchemaProxy) (*base.Schema, *SchemaError) {
171171
return nil, err
172172
}
173173

174-
// Override the description w/ the parent if populated
174+
// Override the description w/ the parent if populated.
175+
// Shallow-copy the schema first to avoid mutating a shared *base.Schema
176+
// instance — libopenapi v0.34+ reuses the same object for all references
177+
// to the same $ref target.
175178
if s.Description != "" {
176-
allOfSchema.Description = s.Description
179+
allOfSchemaCopy := *allOfSchema
180+
allOfSchemaCopy.Description = s.Description
181+
return &allOfSchemaCopy, nil
177182
}
178183

179184
return allOfSchema, nil

internal/mapper/oas/integer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-codegen-spec/provider"
1212
"github.com/hashicorp/terraform-plugin-codegen-spec/resource"
1313
"github.com/hashicorp/terraform-plugin-codegen-spec/schema"
14-
"gopkg.in/yaml.v3"
14+
yaml "go.yaml.in/yaml/v4"
1515

1616
"github.com/doitintl/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1717
"github.com/doitintl/terraform-plugin-codegen-openapi/internal/mapper/oas"

internal/mapper/oas/number_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-codegen-spec/provider"
1212
"github.com/hashicorp/terraform-plugin-codegen-spec/resource"
1313
"github.com/hashicorp/terraform-plugin-codegen-spec/schema"
14-
"gopkg.in/yaml.v3"
14+
yaml "go.yaml.in/yaml/v4"
1515

1616
"github.com/doitintl/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1717
"github.com/doitintl/terraform-plugin-codegen-openapi/internal/mapper/oas"

0 commit comments

Comments
 (0)