Skip to content

Commit efeef19

Browse files
authored
fix: Rename spec structs for better representation in JSON schema (#424)
Follow-up for cloudquery/codegen#135
1 parent 96ffdd3 commit efeef19

12 files changed

Lines changed: 69 additions & 64 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ lint:
88

99
.PHONY: gen-spec-schema
1010
gen-spec-schema:
11+
# vendor for gen
12+
go mod vendor
1113
go run schemagen/main.go
1214

1315
# All gen targets

csv/spec.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"github.com/invopop/jsonschema"
77
)
88

9-
type Spec struct {
9+
// nolint:revive
10+
type CSVSpec struct {
1011
SkipHeader bool `json:"skip_header,omitempty"`
1112
Delimiter string `json:"delimiter,omitempty"`
1213
}
1314

14-
func (Spec) JSONSchema() *jsonschema.Schema {
15+
func (CSVSpec) JSONSchema() *jsonschema.Schema {
1516
properties := jsonschema.NewProperties()
1617
properties.Set("skip_header", &jsonschema.Schema{
1718
Type: "boolean",
@@ -32,13 +33,13 @@ func (Spec) JSONSchema() *jsonschema.Schema {
3233
}
3334
}
3435

35-
func (s *Spec) SetDefaults() {
36+
func (s *CSVSpec) SetDefaults() {
3637
if s.Delimiter == "" {
3738
s.Delimiter = ","
3839
}
3940
}
4041

41-
func (s *Spec) Validate() error {
42+
func (s *CSVSpec) Validate() error {
4243
if len(s.Delimiter) != 1 {
4344
return fmt.Errorf("delimiter must be a single character")
4445
}

csv/spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestSpec_JSONSchema(t *testing.T) {
11-
schema, err := jsonschema.Generate(Spec{})
11+
schema, err := jsonschema.Generate(CSVSpec{})
1212
require.NoError(t, err)
1313

1414
jsonschema.TestJSONSchema(t, string(schema), []jsonschema.TestCase{

json/spec.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ package json
22

33
import "github.com/invopop/jsonschema"
44

5-
type Spec struct{}
5+
// nolint:revive
6+
type JSONSpec struct{}
67

7-
func (Spec) JSONSchema() *jsonschema.Schema {
8+
func (JSONSpec) JSONSchema() *jsonschema.Schema {
89
return &jsonschema.Schema{
910
Description: "CloudQuery JSON file output spec.",
1011
Type: "object",
1112
AdditionalProperties: jsonschema.FalseSchema, // "additionalProperties": false
1213
}
1314
}
1415

15-
func (*Spec) SetDefaults() {}
16+
func (*JSONSpec) SetDefaults() {}
1617

17-
func (*Spec) Validate() error {
18+
func (*JSONSpec) Validate() error {
1819
return nil
1920
}

json/spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestSpec_JSONSchema(t *testing.T) {
11-
schema, err := jsonschema.Generate(Spec{})
11+
schema, err := jsonschema.Generate(JSONSpec{})
1212
require.NoError(t, err)
1313

1414
jsonschema.TestJSONSchema(t, string(schema), []jsonschema.TestCase{

parquet/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type Options func(*Client)
44

55
// Client is a parquet client.
66
type Client struct {
7-
spec Spec
7+
spec ParquetSpec
88
}
99

1010
func NewClient(options ...Options) (*Client, error) {
@@ -16,7 +16,7 @@ func NewClient(options ...Options) (*Client, error) {
1616
return c, nil
1717
}
1818

19-
func WithSpec(spec Spec) Options {
19+
func WithSpec(spec ParquetSpec) Options {
2020
return func(c *Client) {
2121
c.spec = spec
2222
}

parquet/spec.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ package parquet
22

33
import "github.com/invopop/jsonschema"
44

5-
type Spec struct{}
5+
// nolint:revive
6+
type ParquetSpec struct{}
67

7-
func (Spec) JSONSchema() *jsonschema.Schema {
8+
func (ParquetSpec) JSONSchema() *jsonschema.Schema {
89
return &jsonschema.Schema{
910
Description: "CloudQuery Parquet file output spec.",
1011
Type: "object",
1112
AdditionalProperties: jsonschema.FalseSchema, // "additionalProperties": false
1213
}
1314
}
1415

15-
func (*Spec) SetDefaults() {
16+
func (*ParquetSpec) SetDefaults() {
1617
}
1718

18-
func (*Spec) Validate() error {
19+
func (*ParquetSpec) Validate() error {
1920
return nil
2021
}

parquet/spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestSpec_JSONSchema(t *testing.T) {
11-
schema, err := jsonschema.Generate(Spec{})
11+
schema, err := jsonschema.Generate(ParquetSpec{})
1212
require.NoError(t, err)
1313

1414
jsonschema.TestJSONSchema(t, string(schema), []jsonschema.TestCase{

schema.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ func (FileSpec) JSONSchemaOptions() []cqjsonschema.Option {
2020
return nil
2121
}
2222
return reflect.VisibleFields(reflect.TypeOf(struct {
23-
CSVSpec csv.Spec
24-
JSONSpec jsonfile.Spec
25-
ParquetSpec parquet.Spec
23+
CSVSpec csv.CSVSpec
24+
JSONSpec jsonfile.JSONSpec
25+
ParquetSpec parquet.ParquetSpec
2626
}{}))
2727
}
2828
if r.AdditionalFields == nil {

schema.json

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
"$id": "https://github.com/cloudquery/filetypes/v4/file-spec",
44
"$ref": "#/$defs/FileSpec",
55
"$defs": {
6+
"CSVSpec": {
7+
"properties": {
8+
"skip_header": {
9+
"type": "boolean",
10+
"description": "Specifies if the first line of a file should be the header.",
11+
"default": false
12+
},
13+
"delimiter": {
14+
"type": "string",
15+
"pattern": "^.$",
16+
"description": "Character that will be used as the delimiter.",
17+
"default": ","
18+
}
19+
},
20+
"additionalProperties": false,
21+
"type": "object",
22+
"description": "CloudQuery CSV file output spec."
23+
},
624
"FileSpec": {
725
"oneOf": [
826
{
@@ -14,7 +32,7 @@
1432
"format_spec": {
1533
"oneOf": [
1634
{
17-
"$ref": "#/$defs/Spec"
35+
"$ref": "#/$defs/CSVSpec"
1836
},
1937
{
2038
"type": "null"
@@ -32,7 +50,7 @@
3250
"format_spec": {
3351
"oneOf": [
3452
{
35-
"$ref": "#/$defs/Spec-1"
53+
"$ref": "#/$defs/JSONSpec"
3654
},
3755
{
3856
"type": "null"
@@ -50,7 +68,7 @@
5068
"format_spec": {
5169
"oneOf": [
5270
{
53-
"$ref": "#/$defs/Spec-2"
71+
"$ref": "#/$defs/ParquetSpec"
5472
},
5573
{
5674
"type": "null"
@@ -75,13 +93,13 @@
7593
{
7694
"anyOf": [
7795
{
78-
"$ref": "#/$defs/Spec"
96+
"$ref": "#/$defs/CSVSpec"
7997
},
8098
{
81-
"$ref": "#/$defs/Spec-1"
99+
"$ref": "#/$defs/JSONSpec"
82100
},
83101
{
84-
"$ref": "#/$defs/Spec-2"
102+
"$ref": "#/$defs/ParquetSpec"
85103
}
86104
]
87105
},
@@ -105,30 +123,12 @@
105123
"format"
106124
]
107125
},
108-
"Spec": {
109-
"properties": {
110-
"skip_header": {
111-
"type": "boolean",
112-
"description": "Specifies if the first line of a file should be the header.",
113-
"default": false
114-
},
115-
"delimiter": {
116-
"type": "string",
117-
"pattern": "^.$",
118-
"description": "Character that will be used as the delimiter.",
119-
"default": ","
120-
}
121-
},
122-
"additionalProperties": false,
123-
"type": "object",
124-
"description": "CloudQuery CSV file output spec."
125-
},
126-
"Spec-1": {
126+
"JSONSpec": {
127127
"additionalProperties": false,
128128
"type": "object",
129129
"description": "CloudQuery JSON file output spec."
130130
},
131-
"Spec-2": {
131+
"ParquetSpec": {
132132
"additionalProperties": false,
133133
"type": "object",
134134
"description": "CloudQuery Parquet file output spec."

0 commit comments

Comments
 (0)