Skip to content

Commit 78ac884

Browse files
committed
WIP
1 parent 80d86bd commit 78ac884

2 files changed

Lines changed: 71 additions & 3 deletions

File tree

bundler/bundler.go

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ package bundler
77
import (
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+
108157
func bundleRefTarget(ref, mappedRef *index.ReferenceNode, bundledComponents map[string]*index.ReferenceNode, opts BundleOptions) error {
109158
idx := ref.Index
110159
if mappedRef == nil {

test_specs/minimal_remote_refs/openapi.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,27 @@ paths:
2929
responses:
3030
"200":
3131
$ref: ./schemas/components.openapi.yaml#/components/responses/ListAccounts
32+
/api/v1/example:
33+
get:
34+
summary: TODO
35+
description: TODO
36+
tags:
37+
- Account
38+
operationId: placeholder
39+
responses:
40+
"200":
41+
description: >
42+
Foo
43+
content:
44+
application/json:
45+
schema:
3246
components:
3347
securitySchemes:
3448
BearerAuth:
3549
type: http
3650
scheme: bearer
51+
schemas:
52+
Foobar:
53+
type: string
54+
description: >
55+
Something nice to say.

0 commit comments

Comments
 (0)