Skip to content

Strings.ToRawInfo generate empty node #24

Description

@Encorpluptit

Hello,

Issue

The ToRawInfo method on openapiv3.Strings return an empty node without writing actual content.

                    type: array
                    items:
                        discriminator:
                            propertyName: type
                            mapping: {}  # <------ Empty node
                        anyOf:
                            - $ref: '...'

Current implementation:

// ToRawInfo returns a description of Strings suitable for JSON or YAML export.
func (m *Strings) ToRawInfo() *yaml.Node {
info := compiler.NewMappingNode()
if m == nil {
return info
}
// &{Name:additionalProperties Type:NamedString StringEnumValues:[] MapType:string Repeated:true Pattern: Implicit:true Description:}
return info
}


Fix:

// ToRawInfo returns a description of Strings suitable for JSON or YAML export.
func (m *Strings) ToRawInfo() *yaml.Node {
	info := compiler.NewMappingNode()
	if m == nil {
		return info
	}
	// &{Name:additionalProperties Type:NamedString StringEnumValues:[] MapType:string Repeated:true Pattern: Implicit:true Description:}
	for _, p := range m.AdditionalProperties {
		info.Content = append(info.Content, compiler.NewScalarNodeForString(p.Name))
		info.Content = append(info.Content, compiler.NewScalarNodeForString(p.Value))
	}
	return info
}

Produces:

                        discriminator:
                            propertyName: type
                            mapping:
                                name_example: 'value_example'
                                # ...
                        anyOf:
                            - $ref: '...'

Made this PR to fix it

Hope you see this soon !

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions