File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,14 @@ func Parse(docs ...[]byte) ([]Schema, error) {
153
153
if err := s .parse (root ); err != nil {
154
154
return nil , err
155
155
}
156
- parsed [tns ] = s
156
+ // schema already exists, so merge types with new ones
157
+ if ps , ok := parsed [tns ]; ok {
158
+ for name , newType := range s .Types {
159
+ ps .Types [name ] = newType
160
+ }
161
+ } else {
162
+ parsed [tns ] = s
163
+ }
157
164
}
158
165
159
166
for _ , s := range parsed {
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ func (cfg *Config) GenCode(data ...[]byte) (*Code, error) {
55
55
// GenAST creates an *ast.File containing type declarations and
56
56
// associated methods based on a set of XML schema.
57
57
func (cfg * Config ) GenAST (files ... string ) (* ast.File , error ) {
58
+ cfg .filesRead = make (map [string ]bool )
58
59
data , err := cfg .readFiles (files ... )
59
60
code , err := cfg .GenCode (data ... )
60
61
if err != nil {
@@ -70,11 +71,17 @@ func (cfg *Config) readFiles(files ...string) ([][]byte, error) {
70
71
if err != nil {
71
72
return nil , err
72
73
}
74
+ if _ , ok := cfg .filesRead [path ]; ok {
75
+ // skip reading the file again
76
+ continue
77
+ }
78
+ cfg .filesRead [path ] = true
79
+
73
80
b , err := ioutil .ReadFile (path )
74
81
if err != nil {
75
82
return nil , err
76
83
}
77
- cfg .debugf ("read %s(%s) " , path , filename )
84
+ cfg .debugf ("read %s" , path )
78
85
if cfg .followImports {
79
86
dir := filepath .Dir (path )
80
87
importedRefs , err := xsd .Imports (b )
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ type Config struct {
44
44
// if populated, only types that are true in this map
45
45
// will be selected.
46
46
allowTypes map [xml.Name ]bool
47
+
48
+ // keep track of files that are read already to avoid reading it again
49
+ filesRead map [string ]bool
47
50
}
48
51
49
52
type typeTransform func (xsd.Schema , xsd.Type ) xsd.Type
You can’t perform that action at this time.
0 commit comments