Skip to content

Commit 3cce6ea

Browse files
authored
fix: yaml stream format input and remove whitespace YAMLs (#94)
* fix: yaml stream format input and remove whitespace YAMLs Signed-off-by: peefy <[email protected]> * chore: add dependbot Signed-off-by: peefy <[email protected]> --------- Signed-off-by: peefy <[email protected]>
1 parent 7d5d348 commit 3cce6ea

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

.github/dependabot.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "gomod" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
commit-message:
13+
prefix: "Chore: "
14+
include: "scope"
15+
ignore:
16+
- dependency-name: k8s.io/*
17+
- package-ecosystem: "github-actions"
18+
directory: "/"
19+
schedule:
20+
interval: "weekly"
21+
commit-message:
22+
prefix: "chore: "
23+
include: "scope"

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ basic OpenAPI logic in go-swagger.
1212

1313
Main use cases:
1414

15-
+ Swagger Openapi
15+
+ Swagger OpenAPI
1616
+ Translate Swagger OpenAPI spec to KCL code
1717
+ Kubernetes CRD
1818
+ Translate Kubernetes CRD to KCL code
@@ -94,5 +94,4 @@ If the tool isn't working as you expect, please reach out to us by filing an [is
9494

9595
Apache License Version 2.0
9696

97-
98-
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkcl-lang%2Fkcl-openapi.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkcl-lang%2Fkcl-openapi?ref=badge_large)
97+
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkcl-lang%2Fkcl-openapi.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkcl-lang%2Fkcl-openapi?ref=badge_large)

pkg/kube_resource/generator/generator.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"path/filepath"
2323
"regexp"
2424
"strings"
25+
"unicode"
2526

2627
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
2728
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install"
@@ -159,8 +160,16 @@ func splitDocuments(s string) ([]string, error) {
159160
if len(trimmedContentAfterSeparator) > 0 && trimmedContentAfterSeparator[0] != '#' {
160161
return nil, fmt.Errorf("invalid document separator: %s", strings.TrimSpace(separator))
161162
}
162-
163-
docs = append(docs, s[prev:loc[0]])
163+
// Remove all whitespace
164+
result := strings.Map(func(r rune) rune {
165+
if unicode.IsSpace(r) {
166+
return -1
167+
}
168+
return r
169+
}, s[prev:loc[0]])
170+
if len(result) > 0 {
171+
docs = append(docs, result)
172+
}
164173
prev = loc[1]
165174
}
166175
docs = append(docs, s[prev:])

pkg/kube_resource/generator/generator_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
const (
1212
workload = `
13+
1314
---
1415
apiVersion: apiextensions.k8s.io/v1beta1
1516
kind: CustomResourceDefinition
@@ -626,7 +627,7 @@ func TestGenerate(t *testing.T) {
626627
func TestSplitDocuments(t *testing.T) {
627628
crds := v1Crd + v1beta1Crd
628629
files, _ := splitDocuments(crds)
629-
if len(files) != 3 {
630-
t.Errorf("splitDocuments failed. expected 3, got %d", len(files))
630+
if len(files) != 2 {
631+
t.Errorf("splitDocuments failed. expected 2, got %d", len(files))
631632
}
632633
}

0 commit comments

Comments
 (0)