Skip to content

Commit eb183a9

Browse files
authored
feat: Use autogenerated JSON schema (#14275)
Same as #14111 but for Oracle source plugin
1 parent 84fb893 commit eb183a9

File tree

7 files changed

+69
-11
lines changed

7 files changed

+69
-11
lines changed

plugins/source/oracle/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ gen-docs: build
2626
sed -i.bak -e 's_(\(.*\).md)_(\1)_' ../../../website/tables/oracle/*.md
2727
rm -rf ../../../website/tables/oracle/*.bak
2828

29+
.PHONY: gen-spec-schema
30+
gen-spec-schema:
31+
go run client/spec/gen/main.go
32+
2933
# All gen targets
3034
.PHONY: gen
31-
gen: gen-docs
35+
gen: gen-spec-schema gen-docs
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"path"
7+
"runtime"
8+
9+
"github.com/cloudquery/cloudquery/plugins/source/oracle/client/spec"
10+
"github.com/cloudquery/codegen/jsonschema"
11+
)
12+
13+
func main() {
14+
fmt.Println("Generating JSON schema for plugin spec")
15+
jsonschema.GenerateIntoFile(new(spec.Spec), path.Join(currDir(), "..", "schema.json"))
16+
}
17+
18+
func currDir() string {
19+
_, filename, _, ok := runtime.Caller(0)
20+
if !ok {
21+
log.Fatal("Failed to get caller information")
22+
}
23+
return path.Dir(filename)
24+
}
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"title": "CloudQuery Oracle Source Plugin Spec",
4-
"type": "object",
5-
"properties": {
6-
"concurrency": {
7-
"title": "Concurrency",
8-
"description": "A best effort maximum number of Go routines to use. Lower this number to reduce memory usage.",
9-
"type": "integer",
10-
"minimum": 1,
11-
"default": 10000
3+
"$id": "https://github.com/cloudquery/cloudquery/plugins/source/oracle/client/spec/spec",
4+
"$ref": "#/$defs/Spec",
5+
"$defs": {
6+
"Spec": {
7+
"properties": {
8+
"concurrency": {
9+
"type": "integer",
10+
"minimum": 1,
11+
"default": 10000
12+
}
13+
},
14+
"additionalProperties": false,
15+
"type": "object"
1216
}
1317
}
1418
}

plugins/source/oracle/client/spec/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package spec
33
import _ "embed"
44

55
type Spec struct {
6-
Concurrency int `json:"concurrency,omitempty"`
6+
Concurrency int `json:"concurrency,omitempty" jsonschema:"minimum=1,default=10000"`
77
}
88

99
func (s *Spec) SetDefaults() {

plugins/source/oracle/client/spec/spec_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"testing"
66

7+
"github.com/cloudquery/codegen/jsonschema"
78
"github.com/cloudquery/plugin-sdk/v4/plugin"
89
"github.com/stretchr/testify/require"
910
)
@@ -45,3 +46,9 @@ func TestSpec(t *testing.T) {
4546
})
4647
}
4748
}
49+
50+
func TestEnsureJSONSchema(t *testing.T) {
51+
data, err := jsonschema.Generate(new(Spec))
52+
require.NoError(t, err)
53+
require.JSONEqf(t, string(data), JSONSchema, "new schema should be:\n%s\n", string(data))
54+
}

plugins/source/oracle/go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.20
44

55
require (
66
github.com/apache/arrow/go/v14 v14.0.0-20230929201650-00efb06dc0de
7+
github.com/cloudquery/codegen v0.3.3
78
github.com/cloudquery/plugin-sdk/v4 v4.11.1
89
github.com/oracle/oci-go-sdk/v65 v65.28.3
910
github.com/rs/zerolog v1.29.1
@@ -16,6 +17,8 @@ replace github.com/apache/arrow/go/v14 => github.com/cloudquery/arrow/go/v14 v14
1617

1718
require (
1819
github.com/apache/arrow/go/v13 v13.0.0-20230731205701-112f94971882 // indirect
20+
github.com/bahlo/generic-list-go v0.2.0 // indirect
21+
github.com/buger/jsonparser v1.1.1 // indirect
1922
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
2023
github.com/cloudquery/plugin-pb-go v1.10.0 // indirect
2124
github.com/cloudquery/plugin-sdk/v2 v2.7.0 // indirect
@@ -32,8 +35,10 @@ require (
3235
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0 // indirect
3336
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
3437
github.com/inconshreveable/mousetrap v1.1.0 // indirect
38+
github.com/invopop/jsonschema v0.11.0 // indirect
3539
github.com/klauspost/compress v1.16.7 // indirect
3640
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
41+
github.com/mailru/easyjson v0.7.7 // indirect
3742
github.com/mattn/go-colorable v0.1.13 // indirect
3843
github.com/mattn/go-isatty v0.0.19 // indirect
3944
github.com/pierrec/lz4/v4 v4.1.18 // indirect
@@ -43,6 +48,7 @@ require (
4348
github.com/spf13/cobra v1.6.1 // indirect
4449
github.com/spf13/pflag v1.0.5 // indirect
4550
github.com/thoas/go-funk v0.9.3 // indirect
51+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
4652
github.com/zeebo/xxh3 v1.0.2 // indirect
4753
go.opentelemetry.io/otel v1.16.0 // indirect
4854
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect

plugins/source/oracle/go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
3737
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
3838
github.com/apache/arrow/go/v13 v13.0.0-20230731205701-112f94971882 h1:mFDZW1FQk9yndPvxScp7RpcOpdSHaqcgBWO7sDlx4S8=
3939
github.com/apache/arrow/go/v13 v13.0.0-20230731205701-112f94971882/go.mod h1:W69eByFNO0ZR30q1/7Sr9d83zcVZmF2MiP3fFYAWJOc=
40+
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
41+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
4042
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
43+
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
44+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
4145
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
4246
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
4347
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -49,6 +53,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
4953
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5054
github.com/cloudquery/arrow/go/v14 v14.0.0-20231002001222-7ded38b478cd h1:LtWC4oaOh0kI5Xhgl0U4w04vm9qdux/H1E0XBv/Lyio=
5155
github.com/cloudquery/arrow/go/v14 v14.0.0-20231002001222-7ded38b478cd/go.mod h1:/SqmdO2dsWqFHqQQeupnsr0ollL8C91n3x0I72rArY8=
56+
github.com/cloudquery/codegen v0.3.3 h1:riM+5GVXcjNJ8gmgRocSY+QiZedmmjvM9TwEBTfzBr4=
57+
github.com/cloudquery/codegen v0.3.3/go.mod h1:+UAJNPydpAJfMwYKhJgzogwebKdY4sJolH/LuQoTDC0=
5258
github.com/cloudquery/plugin-pb-go v1.10.0 h1:76DSubESX8HWFJZaB90J0mPDnmUoXEzyXutwL0w0TfI=
5359
github.com/cloudquery/plugin-pb-go v1.10.0/go.mod h1:K0L9ugyPVKBgmxhWwr7wNEE/khfJr1lTmhl6HfkhXYA=
5460
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=
@@ -163,6 +169,9 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
163169
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
164170
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
165171
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
172+
github.com/invopop/jsonschema v0.11.0 h1:tdAVvos5ttrsYLyEuVymkVVK31EFpwnTu5hWiyYLGWA=
173+
github.com/invopop/jsonschema v0.11.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
174+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
166175
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
167176
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
168177
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@@ -175,6 +184,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
175184
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
176185
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
177186
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
187+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
188+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
178189
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
179190
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
180191
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
@@ -219,6 +230,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
219230
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
220231
github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw=
221232
github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
233+
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
234+
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
222235
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
223236
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
224237
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

0 commit comments

Comments
 (0)