Skip to content

Commit

Permalink
automatically minify spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed May 1, 2024
1 parent 0f6ac13 commit 7ad1b31
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 4 deletions.
16 changes: 13 additions & 3 deletions cmd/airbyte-source/spec.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package airbyte_source

import (
"fmt"
"encoding/json"
"io"
"strings"

_ "embed"

"github.com/spf13/cobra"
)

Expand All @@ -14,13 +17,20 @@ func init() {
rootCmd.AddCommand(SpecCommand())
}

func minifyJSON(out io.Writer, in io.Reader) error {
var data any
if err := json.NewDecoder(in).Decode(&data); err != nil {
return err
}
return json.NewEncoder(out).Encode(data)
}

func SpecCommand() *cobra.Command {
return &cobra.Command{
Use: "spec",
Short: "Describes inputs needed for connecting to PlanetScale databases",
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", staticSpec)

minifyJSON(cmd.OutOrStdout(), strings.NewReader(staticSpec))
},
}
}
92 changes: 91 additions & 1 deletion cmd/airbyte-source/spec.json
Original file line number Diff line number Diff line change
@@ -1 +1,91 @@
{"type":"SPEC","spec":{"documentationUrl":"https://planetscale.com/docs/integrations/airbyte","connectionSpecification":{"$schema":"http://json-schema.org/draft-07/schema#","title":"PlanetScale Source Spec","type":"object","required":["host","database","username","password"],"additionalProperties":false,"properties":{"host":{"description":"The host name of the database.","title":"Host","type":"string","order":0},"shards":{"description":"Comma separated list of shards you'd like to sync, by default all shards are synced.","title":"Shards","type":"string","order":5},"database":{"description":"The PlanetScale database name.","title":"Database","type":"string","order":1},"username":{"description":"The username which is used to access the database.","title":"Username","type":"string","order":2},"password":{"description":"The password associated with the username.","title":"Password","type":"string","order":3,"airbyte_secret":true},"use_replica":{"description":"Use a replica to pull data from","title":"Use replica?","type":"boolean","default":false,"order":4},"starting_gtids":{"type":"string","title":"Starting GTIDs","default":"","description":"A JSON string containing start GTIDs for every { keyspace: { shard: starting_gtid } }","order":6},"options":{"type":"object","title":"Customize serialization","description":"The storage Provider or Location of the file(s) which should be replicated.","default":"Public Web","oneOf":[{"title":"tinyint(1) serialization","required":["do_not_treat_tiny_int_as_boolean"],"properties":{"storage":{"type":"string","const":"HTTPS"},"do_not_treat_tiny_int_as_boolean":{"type":"boolean","title":"Do not treat tinyint(1) as boolean","default":false,"description":"If enabled, properties of type TinyInt(1) are output as TinyInt, and not boolean."}}}]}}}}}
{
"type": "SPEC",
"spec": {
"documentationUrl": "https://planetscale.com/docs/integrations/airbyte",
"connectionSpecification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PlanetScale Source Spec",
"type": "object",
"required": [
"host",
"database",
"username",
"password"
],
"additionalProperties": false,
"properties": {
"host": {
"description": "The host name of the database.",
"title": "Host",
"type": "string",
"order": 0
},
"shards": {
"description": "Comma separated list of shards you'd like to sync, by default all shards are synced.",
"title": "Shards",
"type": "string",
"order": 5
},
"database": {
"description": "The PlanetScale database name.",
"title": "Database",
"type": "string",
"order": 1
},
"username": {
"description": "The username which is used to access the database.",
"title": "Username",
"type": "string",
"order": 2
},
"password": {
"description": "The password associated with the username.",
"title": "Password",
"type": "string",
"order": 3,
"airbyte_secret": true
},
"use_replica": {
"description": "Use a replica to pull data from",
"title": "Use replica?",
"type": "boolean",
"default": false,
"order": 4
},
"starting_gtids": {
"type": "string",
"title": "Starting GTIDs",
"default": "",
"description": "A JSON string containing start GTIDs for every { keyspace: { shard: starting_gtid } }",
"order": 6
},
"options": {
"type": "object",
"title": "Customize serialization",
"description": "The storage Provider or Location of the file(s) which should be replicated.",
"default": "Public Web",
"oneOf": [
{
"title": "tinyint(1) serialization",
"required": [
"do_not_treat_tiny_int_as_boolean"
],
"properties": {
"storage": {
"type": "string",
"const": "HTTPS"
},
"do_not_treat_tiny_int_as_boolean": {
"type": "boolean",
"title": "Do not treat tinyint(1) as boolean",
"default": false,
"description": "If enabled, properties of type TinyInt(1) are output as TinyInt, and not boolean."
}
}
}
]
}
}
}
}
}

0 comments on commit 7ad1b31

Please sign in to comment.