@@ -20,18 +20,19 @@ import (
2020 "sync"
2121 "testing"
2222
23- "github.com/pb33f/libopenapi/datamodel/low"
23+ "github.com/stretchr/testify/assert"
24+ "github.com/stretchr/testify/require"
25+ "go.yaml.in/yaml/v4"
2426
2527 "github.com/pb33f/libopenapi"
28+ "github.com/pb33f/libopenapi/bundler/test/specs/schemawithrefs"
2629 "github.com/pb33f/libopenapi/datamodel"
2730 "github.com/pb33f/libopenapi/datamodel/high/base"
2831 v3high "github.com/pb33f/libopenapi/datamodel/high/v3"
32+ "github.com/pb33f/libopenapi/datamodel/low"
2933 "github.com/pb33f/libopenapi/index"
3034 "github.com/pb33f/libopenapi/orderedmap"
3135 "github.com/pb33f/libopenapi/utils"
32- "github.com/stretchr/testify/assert"
33- "github.com/stretchr/testify/require"
34- "go.yaml.in/yaml/v4"
3536)
3637
3738// Test helper functions to reduce duplication across DigitalOcean tests
@@ -2209,8 +2210,8 @@ func TestCopySchemaToComponents_NameCollision(t *testing.T) {
22092210func TestCalculateCollisionNameInline_NumericSuffix (t * testing.T ) {
22102211 // Test: When filename-based name also collides, use numeric suffix
22112212 existingNames := map [string ]bool {
2212- "Cat" : true ,
2213- "Cat__external" : true , // Filename-based collision also exists
2213+ "Cat" : true ,
2214+ "Cat__external" : true , // Filename-based collision also exists
22142215 "Cat__external__1" : true , // First numeric suffix also taken (format: name__basename__N)
22152216 }
22162217
@@ -2284,3 +2285,44 @@ components:
22842285 assert .Equal (t , "#node" , itemsSchema .DynamicRef , "DynamicRef should be '#node'" )
22852286}
22862287
2288+ func TestBundleDocument_Embedded (t * testing.T ) {
2289+ expected , err := os .ReadFile ("test/specs/schemawithrefs_expected.yaml" )
2290+ require .NoError (t , err )
2291+
2292+ tests := []struct {
2293+ name string
2294+ config * datamodel.DocumentConfiguration
2295+ }{
2296+ {
2297+ name : "directory" ,
2298+ config : & datamodel.DocumentConfiguration {
2299+ BasePath : "test/specs/schemawithrefs" ,
2300+ AllowFileReferences : true ,
2301+ },
2302+ },
2303+ {
2304+ name : "embed" ,
2305+ config : & datamodel.DocumentConfiguration {
2306+ LocalFS : schemawithrefs .Files ,
2307+ AllowFileReferences : true ,
2308+ },
2309+ },
2310+ }
2311+
2312+ for _ , tt := range tests {
2313+ t .Run (tt .name , func (t * testing.T ) {
2314+ doc , err := libopenapi .NewDocumentWithConfiguration (schemawithrefs .Schema , tt .config )
2315+ require .NoError (t , err )
2316+
2317+ t .Run ("v3" , func (t * testing.T ) {
2318+ v3 , err := doc .BuildV3Model ()
2319+ require .NoError (t , err )
2320+
2321+ b , err := BundleDocument (& v3 .Model )
2322+ require .NoError (t , err )
2323+
2324+ assert .Equal (t , string (b ), string (expected ))
2325+ })
2326+ })
2327+ }
2328+ }
0 commit comments