Skip to content

Commit

Permalink
fix: yaml stream format input and remove whitespace YAMLs (#94)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Peefy authored Aug 8, 2024
1 parent 7d5d348 commit 3cce6ea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
commit-message:
prefix: "Chore: "
include: "scope"
ignore:
- dependency-name: k8s.io/*
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "chore: "
include: "scope"
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ basic OpenAPI logic in go-swagger.

Main use cases:

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

Apache License Version 2.0


[![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)
[![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)
13 changes: 11 additions & 2 deletions pkg/kube_resource/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"regexp"
"strings"
"unicode"

"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install"
Expand Down Expand Up @@ -159,8 +160,16 @@ func splitDocuments(s string) ([]string, error) {
if len(trimmedContentAfterSeparator) > 0 && trimmedContentAfterSeparator[0] != '#' {
return nil, fmt.Errorf("invalid document separator: %s", strings.TrimSpace(separator))
}

docs = append(docs, s[prev:loc[0]])
// Remove all whitespace
result := strings.Map(func(r rune) rune {
if unicode.IsSpace(r) {
return -1
}
return r
}, s[prev:loc[0]])
if len(result) > 0 {
docs = append(docs, result)
}
prev = loc[1]
}
docs = append(docs, s[prev:])
Expand Down
5 changes: 3 additions & 2 deletions pkg/kube_resource/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

const (
workload = `
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -626,7 +627,7 @@ func TestGenerate(t *testing.T) {
func TestSplitDocuments(t *testing.T) {
crds := v1Crd + v1beta1Crd
files, _ := splitDocuments(crds)
if len(files) != 3 {
t.Errorf("splitDocuments failed. expected 3, got %d", len(files))
if len(files) != 2 {
t.Errorf("splitDocuments failed. expected 2, got %d", len(files))
}
}

0 comments on commit 3cce6ea

Please sign in to comment.