From 6bd3e40e5d612946960269e234f37c70923d690b Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Fri, 19 Sep 2025 11:37:06 +0200 Subject: [PATCH] refactor: rename schema --- config.yaml => posh.example.yaml | 2 +- config.schema.json => posh.schema.json | 63 ++++---------------------- main_test.go => schema_test.go | 6 ++- 3 files changed, 13 insertions(+), 58 deletions(-) rename config.yaml => posh.example.yaml (80%) rename config.schema.json => posh.schema.json (69%) rename main_test.go => schema_test.go (87%) diff --git a/config.yaml b/posh.example.yaml similarity index 80% rename from config.yaml rename to posh.example.yaml index eed2be0..15b56ae 100644 --- a/config.yaml +++ b/posh.example.yaml @@ -1,4 +1,4 @@ -# yaml-language-server: $schema=config.schema.json +# yaml-language-server: $schema=posh.schema.json version: '1.0' # Prompt settings diff --git a/config.schema.json b/posh.schema.json similarity index 69% rename from config.schema.json rename to posh.schema.json index bc6e769..a7ab9c4 100644 --- a/config.schema.json +++ b/posh.schema.json @@ -19,13 +19,9 @@ "$ref": "#/$defs/Require" } }, - "additionalProperties": false, "type": "object", "required": [ - "version", - "env", - "prompt", - "require" + "version" ] }, "Env": { @@ -38,12 +34,7 @@ "type": "string" } }, - "additionalProperties": false, - "type": "object", - "required": [ - "name", - "value" - ] + "type": "object" }, "type": "array" }, @@ -68,15 +59,7 @@ "type": "object" } }, - "additionalProperties": false, - "type": "object", - "required": [ - "title", - "prefix", - "prefixGit", - "history", - "aliases" - ] + "type": "object" }, "PromptHistory": { "properties": { @@ -90,13 +73,7 @@ "type": "string" } }, - "additionalProperties": false, - "type": "object", - "required": [ - "limit", - "filename", - "lockFilename" - ] + "type": "object" }, "Require": { "properties": { @@ -119,13 +96,7 @@ "type": "array" } }, - "additionalProperties": false, - "type": "object", - "required": [ - "envs", - "scripts", - "packages" - ] + "type": "object" }, "RequireEnv": { "properties": { @@ -136,12 +107,7 @@ "type": "string" } }, - "additionalProperties": false, - "type": "object", - "required": [ - "name", - "help" - ] + "type": "object" }, "RequirePackage": { "properties": { @@ -158,14 +124,7 @@ "type": "string" } }, - "additionalProperties": false, - "type": "object", - "required": [ - "name", - "version", - "command", - "help" - ] + "type": "object" }, "RequireScript": { "properties": { @@ -179,13 +138,7 @@ "type": "string" } }, - "additionalProperties": false, - "type": "object", - "required": [ - "name", - "command", - "help" - ] + "type": "object" } } } \ No newline at end of file diff --git a/main_test.go b/schema_test.go similarity index 87% rename from main_test.go rename to schema_test.go index 446176b..ee46977 100644 --- a/main_test.go +++ b/schema_test.go @@ -26,7 +26,7 @@ type Config struct { Require config.Require `json:"require"` } -func TestConfig(t *testing.T) { +func TestSchema(t *testing.T) { t.Parallel() testingx.Tags(t, tagx.Short) @@ -34,12 +34,14 @@ func TestConfig(t *testing.T) { require.NoError(t, err) reflector := new(jsonschema.Reflector) + reflector.AllowAdditionalProperties = true + reflector.RequiredFromJSONSchemaTags = true require.NoError(t, reflector.AddGoComments("github.com/foomo/posh", "./")) schema := reflector.Reflect(&Config{}) actual, err := json.MarshalIndent(schema, "", " ") require.NoError(t, err) - filename := path.Join(cwd, "config.schema.json") + filename := path.Join(cwd, "posh.schema.json") expected, err := os.ReadFile(filename) if !errors.Is(err, os.ErrNotExist) { require.NoError(t, err)