@@ -3,6 +3,7 @@ package raml
33import (
44 "container/list"
55 "context"
6+ "encoding/json"
67 "errors"
78 "io"
89 "os"
@@ -14,12 +15,38 @@ import (
1415 "github.com/stretchr/testify/require"
1516)
1617
18+ func writeToDiskHelper (t * testing.T , tt struct {
19+ name string
20+ typeName string
21+ outSchema * JSONSchemaRAML
22+ }) {
23+ outputDir := "./test_output"
24+ if err := os .MkdirAll (outputDir , os .ModePerm ); err != nil {
25+ t .Errorf ("Failed to create output directory: %v" , err )
26+ }
27+ outputPath := filepath .Join (outputDir , tt .name + "_" + tt .typeName + ".json" )
28+ var jsonData []byte
29+ jsonData , err := json .MarshalIndent (tt .outSchema , "" , " " )
30+ if err != nil {
31+ t .Errorf ("Failed to marshal JSON Schema: %v" , err )
32+ }
33+ if err := os .WriteFile (outputPath , jsonData , 0644 ); err != nil {
34+ t .Errorf ("Failed to write JSON Schema to file: %v" , err )
35+ }
36+ t .Logf ("Successfully wrote JSON Schema to %s" , outputPath )
37+ }
38+
39+
1740func Test_ParseFixturesIntegration (t * testing.T ) {
1841 // Define test cases for valid fixtures that should parse successfully
1942 validTests := []struct {
2043 name string
2144 path string
2245 }{
46+ {
47+ name : "library_recursive_trait.raml" ,
48+ path : "./fixtures/library_recursive_trait.raml" ,
49+ },
2350 {
2451 name : "library.raml" ,
2552 path : "./fixtures/library.raml" ,
@@ -78,19 +105,25 @@ func Test_ParseFixturesIntegration(t *testing.T) {
78105 case * Library :
79106 for pair := f .AnnotationTypes .Oldest (); pair != nil ; pair = pair .Next () {
80107 s := pair .Value
81- _ , errConv := conv .Convert (s .Shape )
82- require .NoError (t , errConv , "Failed to convert annotation type shape in %s: %v" , tt .path , errConv )
108+ typeName := pair .Key
109+ outSchema , err := conv .Convert (s .Shape )
110+ writeToDiskHelper (t , struct {name string ; typeName string ; outSchema * JSONSchemaRAML }{name : tt .name , typeName : typeName , outSchema : outSchema })
111+ require .NoError (t , err , "Failed to convert annotation type shape in %s: %v" , tt .path , err )
83112 convertedCount ++
84113 }
85114 for pair := f .Types .Oldest (); pair != nil ; pair = pair .Next () {
86115 s := pair .Value
87- _ , errConv := conv .Convert (s .Shape )
88- require .NoError (t , errConv , "Failed to convert type shape in %s: %v" , tt .path , errConv )
116+ typeName := pair .Key
117+ outSchema , err := conv .Convert (s .Shape )
118+ writeToDiskHelper (t , struct {name string ; typeName string ; outSchema * JSONSchemaRAML }{name : tt .name , typeName : typeName , outSchema : outSchema })
119+ require .NoError (t , err , "Failed to convert type shape in %s: %v" , tt .path , err )
89120 convertedCount ++
90121 }
91122 case * DataType :
92- _ , errConv := conv .Convert (f .Shape .Shape )
93- require .NoError (t , errConv , "Failed to convert data type shape in %s: %v" , tt .path , errConv )
123+ typeName := f .Shape .Name
124+ outSchema , err := conv .Convert (f .Shape .Shape )
125+ writeToDiskHelper (t , struct {name string ; typeName string ; outSchema * JSONSchemaRAML }{name : tt .name , typeName : typeName , outSchema : outSchema })
126+ require .NoError (t , err , "Failed to convert data type shape in %s: %v" , tt .path , err )
94127 convertedCount ++
95128 }
96129 }
@@ -136,8 +169,12 @@ func Test_ParseFixturesIntegration(t *testing.T) {
136169 path : "./fixtures/library_invalid_unwrap.raml" ,
137170 },
138171 {
139- name : "named_example_invalid_decode.raml" ,
140- path : "./fixtures/named_example_invalid_decode.raml" ,
172+ name : "library_invalid_recursive_trait.raml" ,
173+ path : "./fixtures/library_invalid_inherited_recursive_trait.raml" ,
174+ },
175+ {
176+ name : "library_invalid_trait_example.raml" ,
177+ path : "./fixtures/library_invalid_trait_example.raml" ,
141178 },
142179 }
143180
0 commit comments