From e7a1f418bdf426de570ff0091f52dc0509c2c474 Mon Sep 17 00:00:00 2001 From: Aleksandar Stojanov Date: Fri, 30 Aug 2024 14:37:48 +0200 Subject: [PATCH] add test case Signed-off-by: Aleksandar Stojanov --- pkg/generator.go | 1 - pkg/schema.go | 2 -- pkg/schema_test.go | 23 +++++++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pkg/generator.go b/pkg/generator.go index 869d6a6..29fed13 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -63,7 +63,6 @@ func GenerateJsonSchema(config *Config) error { // Exclude hidden nodes if schema != nil && !schema.Hidden { if schema.SkipProperties && schema.Type == "object" { - // Apply skipProperties logic for objects schema.Properties = nil } properties[keyNode.Value] = schema diff --git a/pkg/schema.go b/pkg/schema.go index d95c99d..3bedc9c 100644 --- a/pkg/schema.go +++ b/pkg/schema.go @@ -273,13 +273,11 @@ func parseNode(keyNode *yaml.Node, valNode *yaml.Node) (*Schema, bool) { } } - // Process comments and determine if the node is required or hidden propIsRequired, isHidden := processComment(schema, getComment(keyNode, valNode)) if isHidden { return nil, false } - // If schema is of type object and SkipProperties is true, set Properties to nil if schema.SkipProperties && schema.Type == "object" { schema.Properties = nil } diff --git a/pkg/schema_test.go b/pkg/schema_test.go index d19240d..f5a3f83 100644 --- a/pkg/schema_test.go +++ b/pkg/schema_test.go @@ -399,6 +399,29 @@ func TestParseNode(t *testing.T) { }, expectedType: "string", }, + { + name: "parse object node with skipProperties:true", + valNode: &yaml.Node{ + Kind: yaml.MappingNode, + Content: []*yaml.Node{ + { + Kind: yaml.ScalarNode, + Value: "key", + }, + { + Kind: yaml.MappingNode, + Content: []*yaml.Node{ + {Kind: yaml.ScalarNode, Value: "nestedKey"}, + {Kind: yaml.ScalarNode, Value: "nestedValue"}, + }, + LineComment: "# @schema skipProperties:true", + }, + }, + }, + expectedType: "object", + expectedProps: map[string]*Schema{"key": {Type: "object", Properties: nil, SkipProperties: true}}, + expectedReq: nil, + }, } for _, tt := range tests {