@@ -7,11 +7,15 @@ package bundler
77import (
88 "errors"
99 "fmt"
10+ "strings"
1011
12+ "github.com/davecgh/go-spew/spew"
1113 "github.com/pb33f/libopenapi"
1214 "github.com/pb33f/libopenapi/datamodel"
13- v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
15+ highV3 "github.com/pb33f/libopenapi/datamodel/high/v3"
16+ lowV3 "github.com/pb33f/libopenapi/datamodel/low/v3"
1417 "github.com/pb33f/libopenapi/index"
18+ "github.com/pb33f/libopenapi/utils"
1519)
1620
1721// ErrInvalidModel is returned when the model is not usable.
@@ -66,11 +70,11 @@ func BundleBytes(bytes []byte, configuration *datamodel.DocumentConfiguration, o
6670// document will be a valid OpenAPI specification, containing no references.
6771//
6872// Circular references will not be resolved and will be skipped.
69- func BundleDocument (model * v3 .Document ) ([]byte , error ) {
73+ func BundleDocument (model * highV3 .Document ) ([]byte , error ) {
7074 return bundle (model , BundleOptions {RelativeRefHandling : RefHandlingInline })
7175}
7276
73- func bundle (model * v3 .Document , opts BundleOptions ) (_ []byte , err error ) {
77+ func bundle (model * highV3 .Document , opts BundleOptions ) (_ []byte , err error ) {
7478 rolodex := model .Rolodex
7579
7680 idx := rolodex .GetRootIndex ()
@@ -99,12 +103,57 @@ func bundle(model *v3.Document, opts BundleOptions) (_ []byte, err error) {
99103 if err := bundleRefTarget (sequenced , mappedReference , bundledComponents , opts ); err != nil {
100104 return nil , err
101105 }
106+
107+ model , err = composeDocument (model , bundledComponents )
108+ if err != nil {
109+ return nil , err
110+ }
102111 }
103112 }
104113
105114 return model .Render ()
106115}
107116
117+ func composeDocument (model * highV3.Document , comps map [string ]* index.ReferenceNode ) (* highV3.Document , error ) {
118+ // lowModel := model.GoLow()
119+
120+ // components := lowModel.Components
121+
122+ for def , component := range comps {
123+ defParts := strings .Split (def , "/" )
124+ // TODO: use constant from low model labels
125+ if len (defParts ) != 4 || defParts [1 ] != lowV3 .ComponentsLabel {
126+ return nil , fmt .Errorf ("unsupported component section: %s" , def )
127+ }
128+ spew .Dump (component )
129+
130+ switch defParts [2 ] {
131+ case "schemas" :
132+ // key := low.KeyReference[string]{
133+ // Value: defParts[3],
134+ // KeyNode: &yaml.Node{
135+ // Kind: yaml.ScalarNode,
136+ // Style: yaml.TaggedStyle,
137+ // Tag: "!!str",
138+ // Value: defParts[3],
139+ // },
140+ // }
141+ // value := low.ValueReference[*base.SchemaProxy]{
142+ // Reference: low.Reference{},
143+ // Value: &base.SchemaProxy{},
144+ // ValueNode: &yaml.Node{},
145+ // }
146+ _ , _ := utils .FindKeyNodeFullTop ()
147+ // components.Value.Schemas.Value.Set(key, value)
148+
149+ default :
150+ return nil , fmt .Errorf ("unsupported component type: %s" , defParts [2 ])
151+ }
152+ }
153+
154+ return nil , nil
155+ }
156+
108157func bundleRefTarget (ref , mappedRef * index.ReferenceNode , bundledComponents map [string ]* index.ReferenceNode , opts BundleOptions ) error {
109158 idx := ref .Index
110159 if mappedRef == nil {
0 commit comments