go-jsonschema
go-jsonschema copied to clipboard
Folded blocks in YAML cause extra line breaks
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"`
}
I'm opening a PR to address this. The PR changes the yaml library, which I'm not sure you are happy to do.
changes merged in #52