Skip to content

fix: emit valid multiline string defaults for CRD models#152

Merged
Peefy merged 2 commits intokcl-lang:mainfrom
officialasishkumar:fix/multiline-default-string
Apr 6, 2026
Merged

fix: emit valid multiline string defaults for CRD models#152
Peefy merged 2 commits intokcl-lang:mainfrom
officialasishkumar:fix/multiline-default-string

Conversation

@officialasishkumar
Copy link
Copy Markdown
Contributor

fix invalid KCL generation for CRD string defaults that contain embedded newlines.

  • emit triple-quoted KCL literals for multiline string defaults in generated schema bodies
  • keep schema docstrings safe by rendering multiline defaults with escaped \n sequences instead of nested triple quotes
  • add unit coverage for multiline string rendering and a CRD end-to-end regression test covering the reported reproducer

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

fix #150

2. What is the scope of this PR (e.g. component or file name):

pkg/swagger/generator/language.go
pkg/swagger/generator/template_repo.go
pkg/swagger/generator/templates/propertydoc.gotmpl
pkg/swagger/generator/templates/docstring.gotmpl
pkg/swagger/generator/support_test.go
pkg/swagger/generator/template_repo_test.go

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

More details:

  • the current generator always emits regular quoted strings for defaults, which produces invalid KCL when the source default contains literal newlines
  • this update keeps the generated assignment valid while preserving readable schema docs
  • the new regression test exercises the CRD flow end to end with the multiline default from the issue report

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

Test coverage:

  • go test ./pkg/swagger/generator -run 'Test(ToKCLValue|ToKCLDocValue|Generate_CRD2KCL_MultilineStringDefault)'
  • go test ./...

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@officialasishkumar
Copy link
Copy Markdown
Contributor Author

PTAL @Peefy

@Peefy Peefy merged commit 89b5a0e into kcl-lang:main Apr 6, 2026
7 of 8 checks passed
@coveralls
Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 24009554990

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 14 of 17 (82.35%) changed or added relevant lines in 1 file are covered.
  • 132 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-3.6%) to 62.682%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/swagger/generator/language.go 14 17 82.35%
Files with Coverage Reduction New Missed Lines %
pkg/utils/integrate_gen.go 132 0.0%
Totals Coverage Status
Change from base Build 22742151113: -3.6%
Covered Lines: 2234
Relevant Lines: 3564

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kcl import -m crd generates invalid KCL for multiline string defaults (missing triple-quotes)

3 participants