Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Stojanov <[email protected]>
  • Loading branch information
losisin committed Aug 30, 2024
1 parent 7a2132a commit e7a1f41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 0 additions & 1 deletion pkg/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkg/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e7a1f41

Please sign in to comment.