File tree Expand file tree Collapse file tree 2 files changed +69
-7
lines changed
pkg/kube_resource/generator Expand file tree Collapse file tree 2 files changed +69
-7
lines changed Original file line number Diff line number Diff line change @@ -161,13 +161,8 @@ func splitDocuments(s string) ([]string, error) {
161161 return nil , fmt .Errorf ("invalid document separator: %s" , strings .TrimSpace (separator ))
162162 }
163163 // 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 {
164+ result := s [prev :loc [0 ]]
165+ if len (result ) > 0 && ! isAllWhitespace (result ) {
171166 docs = append (docs , result )
172167 }
173168 prev = loc [1 ]
@@ -177,6 +172,15 @@ func splitDocuments(s string) ([]string, error) {
177172 return docs , nil
178173}
179174
175+ func isAllWhitespace (str string ) bool {
176+ for _ , r := range str {
177+ if ! unicode .IsSpace (r ) {
178+ return false
179+ }
180+ }
181+ return true
182+ }
183+
180184// generate swagger model based on crd
181185func generate (crdYaml string ) (* spec.Swagger , error ) {
182186 crdObj , _ , err := scheme .Codecs .UniversalDeserializer ().
Original file line number Diff line number Diff line change @@ -631,3 +631,61 @@ func TestSplitDocuments(t *testing.T) {
631631 t .Errorf ("splitDocuments failed. expected 2, got %d" , len (files ))
632632 }
633633}
634+
635+ func TestSplitYamlStreamDocuments (t * testing.T ) {
636+ crds := `
637+ apiVersion: apiextensions.k8s.io/v1
638+ kind: CustomResourceDefinition
639+ metadata:
640+ name: foo.example.com
641+ spec:
642+ group: example.com
643+ versions:
644+ - name: v1
645+ served: true
646+ storage: true
647+ schema:
648+ openAPIV3Schema:
649+ type: object
650+ properties:
651+ spec:
652+ type: object
653+ properties:
654+ field1:
655+ type: string
656+ scope: Namespaced
657+ names:
658+ plural: foo
659+ singular: foo
660+ kind: Foo
661+ ---
662+ apiVersion: apiextensions.k8s.io/v1
663+ kind: CustomResourceDefinition
664+ metadata:
665+ name: bar.example.com
666+ spec:
667+ group: example.com
668+ versions:
669+ - name: v1
670+ served: true
671+ storage: true
672+ schema:
673+ openAPIV3Schema:
674+ type: object
675+ properties:
676+ spec:
677+ type: object
678+ properties:
679+ field2:
680+ type: string
681+ scope: Namespaced
682+ names:
683+ plural: bar
684+ singular: bar
685+ kind: Bar
686+ `
687+ files , _ := splitDocuments (crds )
688+ if len (files ) != 2 {
689+ t .Errorf ("splitDocuments failed. expected 2, got %d" , len (files ))
690+ }
691+ }
You can’t perform that action at this time.
0 commit comments