Skip to content

Commit 3c77e92

Browse files
committed
fix: driver.meta.dict allow empty
1 parent ef4f1a8 commit 3c77e92

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

schema/json.go

+36-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type SchemaJSON struct {
1212
Relations []*RelationJSON `json:"relations,omitempty"`
1313
Functions []*Function `json:"functions,omitempty"`
1414
Enums []*Enum `json:"enums,omitempty"`
15-
Driver *Driver `json:"driver,omitempty"`
15+
Driver *DriverJSON `json:"driver,omitempty"`
1616
Labels Labels `json:"labels,omitempty"`
1717
Viewpoints Viewpoints `json:"viewpoints,omitempty"`
1818
}
@@ -54,6 +54,18 @@ type RelationJSON struct {
5454
Virtual bool `json:"virtual,omitempty"`
5555
}
5656

57+
type DriverJSON struct {
58+
Name string `json:"name"`
59+
DatabaseVersion string `json:"database_version,omitempty" yaml:"databaseVersion,omitempty"`
60+
Meta *DriverMetaJSON `json:"meta,omitempty"`
61+
}
62+
63+
type DriverMetaJSON struct {
64+
CurrentSchema string `json:"current_schema,omitempty" yaml:"currentSchema,omitempty"`
65+
SearchPaths []string `json:"search_paths,omitempty" yaml:"searchPaths,omitempty"`
66+
Dict map[string]string `json:"dict,omitempty"`
67+
}
68+
5769
// ToJSONObjct convert schema.Schema to JSON object
5870
func (s Schema) ToJSONObject() SchemaJSON {
5971
var tables []*TableJSON
@@ -73,7 +85,7 @@ func (s Schema) ToJSONObject() SchemaJSON {
7385
Relations: relations,
7486
Functions: s.Functions,
7587
Enums: s.Enums,
76-
Driver: s.Driver,
88+
Driver: s.Driver.ToJSONObject(),
7789
Labels: s.Labels,
7890
Viewpoints: s.Viewpoints,
7991
}
@@ -140,6 +152,28 @@ func (r Relation) ToJSONObject() RelationJSON {
140152
}
141153
}
142154

155+
func (d *Driver) ToJSONObject() *DriverJSON {
156+
if d == nil {
157+
return nil
158+
}
159+
return &DriverJSON{
160+
Name: d.Name,
161+
DatabaseVersion: d.DatabaseVersion,
162+
Meta: d.Meta.ToJSONObject(),
163+
}
164+
}
165+
166+
func (d *DriverMeta) ToJSONObject() *DriverMetaJSON {
167+
if d == nil {
168+
return nil
169+
}
170+
return &DriverMetaJSON{
171+
CurrentSchema: d.CurrentSchema,
172+
SearchPaths: d.SearchPaths,
173+
Dict: d.Dict.Dump(),
174+
}
175+
}
176+
143177
// MarshalJSON return custom JSON byte
144178
func (s Schema) MarshalJSON() ([]byte, error) {
145179
ss := s.ToJSONObject()

spec/tbls.schema.json_schema.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@
8484
"table"
8585
]
8686
},
87-
"Dict": {
88-
"properties": {},
89-
"additionalProperties": false,
90-
"type": "object"
91-
},
9287
"Driver": {
9388
"properties": {
9489
"name": {
@@ -119,7 +114,10 @@
119114
"type": "array"
120115
},
121116
"dict": {
122-
"$ref": "#/$defs/Dict"
117+
"additionalProperties": {
118+
"type": "string"
119+
},
120+
"type": "object"
123121
}
124122
},
125123
"additionalProperties": false,

0 commit comments

Comments
 (0)