Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folded blocks in YAML cause extra line breaks #42

Closed
felixjung opened this issue Jan 18, 2022 · 2 comments · Fixed by #52
Closed

Folded blocks in YAML cause extra line breaks #42

felixjung opened this issue Jan 18, 2022 · 2 comments · Fixed by #52
Milestone

Comments

@felixjung
Copy link
Contributor

When generating code from a YAML schema definition that uses folded blocks for descriptions, the comments in the generated output code have a trailing comment line.

The issue may be related to go-yaml/yaml#789.

Example

Input

"$schema": "http://json-schema.org/draft-04/schema#"
"$id": "https://example.com/yaml_formatting"

title: MyObject
type: object
properties:
  foo:
    description: >
      I'm a multiline description in a folded block. Folded blocks should not
      have hard line breaks after parsing. They should also not end in a line break.
    type: string
  bar:
    description: |
      I'm a multiline description in a literal block. Literal blocks, on the other hand,
      should have hard line breaks and may end in a line break, too.

      This may look funky when Go code is generated to a specific line width, though.
    type: string

Expected Output

// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.

package test

type YamlMultilineDescriptionsYaml struct {
	// I'm a multiline description in a literal block. Literal blocks, on the other
	// hand,
	// should have hard line breaks and may end in a line break, too.
	//
	// This may look funky when Go code is generated to a specific line width, though.
	//
	Bar *string `json:"bar,omitempty" yaml:"bar,omitempty"`

	// I'm a multiline description in a folded block. Folded blocks should not have
	// hard line breaks after parsing. They should also not end in a line break.
	Foo *string `json:"foo,omitempty" yaml:"foo,omitempty"`
}

Actual Output

// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.

package test

type YamlMultilineDescriptionsYaml struct {
	// I'm a multiline description in a literal block. Literal blocks, on the other
	// hand,
	// should have hard line breaks and may end in a line break, too.
	//
	// This may look funky when Go code is generated to a specific line width, though.
	//
	Bar *string `json:"bar,omitempty" yaml:"bar,omitempty"`

	// I'm a multiline description in a folded block. Folded blocks should not have
	// hard line breaks after parsing. They should also not end in a line break.
	//
	Foo *string `json:"foo,omitempty" yaml:"foo,omitempty"`
}
@felixjung
Copy link
Contributor Author

I'm opening a PR to address this. The PR changes the yaml library, which I'm not sure you are happy to do.

@omissis
Copy link
Owner

omissis commented Apr 8, 2023

changes merged in #52

@omissis omissis closed this as completed Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants