-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: generate JSON schema file for configuration for IDE auto com…
…pletion
- Loading branch information
1 parent
f3e940c
commit 063e45d
Showing
14 changed files
with
2,723 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/marnixbouhuis/confpb/internal/codegen" | ||
"github.com/marnixbouhuis/confpb/internal/codegen/jsonschemagen" | ||
) | ||
|
||
func main() { | ||
codegen.RunProtocPlugin(jsonschemagen.GenerateFile) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$defs": { | ||
"config.v1.ApplicationConfig": { | ||
"title": "config.v1.ApplicationConfig", | ||
"description": "", | ||
"deprecated": false, | ||
"additionalProperties": false, | ||
"properties": { | ||
"keyValue": { | ||
"title": "config.v1.ApplicationConfig.key_value", | ||
"description": "", | ||
"deprecated": false, | ||
"additionalProperties": { | ||
"title": "config.v1.ApplicationConfig.KeyValueEntry.value", | ||
"description": "", | ||
"deprecated": false, | ||
"type": [ | ||
"string" | ||
] | ||
}, | ||
"type": [ | ||
"object" | ||
] | ||
}, | ||
"server": { | ||
"title": "config.v1.ApplicationConfig.server", | ||
"description": "", | ||
"deprecated": false, | ||
"allOf": [ | ||
{ | ||
"$ref": "#/$defs/config.v1.ApplicationConfig.ServerConfig" | ||
} | ||
] | ||
}, | ||
"serverList": { | ||
"items": { | ||
"title": "config.v1.ApplicationConfig.server_list", | ||
"description": "// Multiple values can also be set for nested messages, the env key specified for the list will be used as prefix.\n// Values can be set using:\n// - SERVER_LIST_1_HOST = \"1.2.3.4\"\n// - SERVER_LIST_1_HOST = \"8080\"\n// - SERVER_LIST_2_HOST = \"127.0.0.1\"\n// - SERVER_LIST_2_HOST = \"433\"\n// ...\n", | ||
"deprecated": false, | ||
"allOf": [ | ||
{ | ||
"$ref": "#/$defs/config.v1.ApplicationConfig.ServerConfig" | ||
} | ||
] | ||
}, | ||
"type": [ | ||
"array" | ||
] | ||
}, | ||
"someDuration": { | ||
"title": "config.v1.ApplicationConfig.some_duration", | ||
"description": "// Some types have a special mapping. For durations, strings are parsed to durations (e.g. 10s, 10m30s, 1h).\n// Other types that use special parsing include: timestamps, structs, struct values, and fields with the \"bytes\" type.\n", | ||
"deprecated": false, | ||
"type": [ | ||
"string" | ||
], | ||
"pattern": "^-?([0-9]*[.])?[0-9]+(s)$" | ||
}, | ||
"someList": { | ||
"items": { | ||
"title": "config.v1.ApplicationConfig.some_list", | ||
"description": "// Multiple values can be set for a list using:\n// - SOME_LIST_1 = \"item1\"\n// - SOME_LIST_2 = \"item2\"\n// - SOME_LIST_3 = \"item3\"\n// - SOME_LIST_4 = \"item4\"\n// ...\n", | ||
"deprecated": false, | ||
"type": [ | ||
"string" | ||
] | ||
}, | ||
"type": [ | ||
"array" | ||
] | ||
} | ||
}, | ||
"type": [ | ||
"object" | ||
] | ||
}, | ||
"config.v1.ApplicationConfig.ServerConfig": { | ||
"title": "config.v1.ApplicationConfig.ServerConfig", | ||
"description": "", | ||
"deprecated": false, | ||
"additionalProperties": false, | ||
"properties": { | ||
"host": { | ||
"title": "config.v1.ApplicationConfig.ServerConfig.host", | ||
"description": "", | ||
"deprecated": false, | ||
"type": [ | ||
"string" | ||
] | ||
}, | ||
"port": { | ||
"title": "config.v1.ApplicationConfig.ServerConfig.port", | ||
"description": "", | ||
"deprecated": false, | ||
"type": [ | ||
"integer" | ||
], | ||
"maximum": 4294967295, | ||
"minimum": 0 | ||
} | ||
}, | ||
"type": [ | ||
"object" | ||
] | ||
} | ||
}, | ||
"title": "config.v1", | ||
"description": "Code generated by protoc-gen-jsonschema. DO NOT EDIT. Schema definitions for config.v1.", | ||
"oneOf": [ | ||
{ | ||
"title": "Configuration file format for: config.v1.ApplicationConfig.ServerConfig.", | ||
"description": "", | ||
"deprecated": false, | ||
"additionalProperties": false, | ||
"properties": { | ||
"@type": { | ||
"type": [ | ||
"string" | ||
], | ||
"const": "type.googleapis.com/config.v1.ApplicationConfig.ServerConfig" | ||
} | ||
}, | ||
"allOf": [ | ||
{ | ||
"$ref": "#/$defs/config.v1.ApplicationConfig.ServerConfig" | ||
} | ||
], | ||
"type": [ | ||
"object" | ||
], | ||
"required": [ | ||
"@type" | ||
] | ||
}, | ||
{ | ||
"title": "Configuration file format for: config.v1.ApplicationConfig.", | ||
"description": "", | ||
"deprecated": false, | ||
"additionalProperties": false, | ||
"properties": { | ||
"@type": { | ||
"type": [ | ||
"string" | ||
], | ||
"const": "type.googleapis.com/config.v1.ApplicationConfig" | ||
} | ||
}, | ||
"allOf": [ | ||
{ | ||
"$ref": "#/$defs/config.v1.ApplicationConfig" | ||
} | ||
], | ||
"type": [ | ||
"object" | ||
], | ||
"required": [ | ||
"@type" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package e2e_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/marnixbouhuis/confpb/internal/codegen/jsonschemagen" | ||
"github.com/marnixbouhuis/confpb/internal/codegen/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSnapshot(t *testing.T) { | ||
t.Parallel() | ||
|
||
res := testutil.RunGeneratorForFiles(t, jsonschemagen.GenerateFile, testDataFS, "testdata/e2e.proto") | ||
content := testutil.GetFileFromGenerationResult(t, res, "e2e.schema.json") | ||
|
||
expected, err := testDataFS.ReadFile("testdata/e2e.schema.json") | ||
require.NoError(t, err) | ||
require.Equal(t, string(expected), content) | ||
} |
Oops, something went wrong.