From 9527fc77253ff1a2984fa26efaec65e9b1e4458d Mon Sep 17 00:00:00 2001 From: Dan Ramich Date: Thu, 25 Jan 2024 15:01:24 -0700 Subject: [PATCH] Handle empty arrays by returing null error (#4) * Update README * Handle empty arrays by returing null error --- README.md | 11 +++-------- pkg/helm/helmtoschema.go | 2 +- pkg/helm/testdata/values.yaml | 5 ++++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7ac0cd9..fbfb75d 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,12 @@ - + # AIRLOCK [![Go Report Card](https://goreportcard.com/badge/github.com/massdriver-cloud/airlock)](https://goreportcard.com/report/github.com/massdriver-cloud/airlock) -[![Build Status](https://travis-ci.com/massdriver-cloud/airlock.svg?branch=master)](https://travis-ci.com/massdriver-cloud/airlock) -[![Coverage Status](https://coveralls.io/repos/github/massdriver-cloud/airlock/badge.svg?branch=master)](https://coveralls.io/github/massdriver-cloud/airlock?branch=master) -[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/massdriver-cloud/airlock/blob/master/LICENSE) +[![License](https://img.shields.io/github/license/massdriver-cloud/airlock)](https://github.com/massdriver-cloud/airlock/blob/master/LICENSE) ## Overview -Briefly describe what your project does and what it's used for. - -## Features -List the key features of your project. +Generate JSON Schema from various sources (terraform, helm) ## Getting Started diff --git a/pkg/helm/helmtoschema.go b/pkg/helm/helmtoschema.go index e91cb39..de081d5 100644 --- a/pkg/helm/helmtoschema.go +++ b/pkg/helm/helmtoschema.go @@ -161,7 +161,7 @@ func parseArrayNode(sch *schema.Schema, node *yaml.Node) error { sch.Type = "array" if len(node.Content) == 0 { - return fmt.Errorf("error: cannot infer element type in array %s. Arrays cannot be empty or the type is ambiguous", sch.Title) + return &nullError{} } sch.Items = new(schema.Schema) err := parseValueNode(sch.Items, node.Content[0]) diff --git a/pkg/helm/testdata/values.yaml b/pkg/helm/testdata/values.yaml index 5212112..cd03168 100644 --- a/pkg/helm/testdata/values.yaml +++ b/pkg/helm/testdata/values.yaml @@ -18,4 +18,7 @@ array: - foo - bar -nullValue: \ No newline at end of file +# An empty array should not cause an error +emptyArray: [] + +nullValue: