Skip to content

[BUG] [KOTLIN] Invalid quotation for String default values #5772

Closed
@chemist777

Description

@chemist777

Version: 4.3.0 and master branch.

AbstractKotlinCodegen.java uses invalid quotation for default values of Strings.

It uses single quotes instead of double quotes. Kotlin only supports string literals surrounded by double quotes as plain Java codegen.
It prevents the use of default values in code generation.

Line: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java#L943

This is a fragment of toDefaultValue method:

...
        } else if (ModelUtils.isStringSchema(p)) {
            if (p.getDefault() != null) {
                return "'" + p.getDefault() + "'";
            }
        }

It should be replaced with:

...
        } else if (ModelUtils.isStringSchema(p)) {
            if (p.getDefault() != null) {
                return "\"" + p.getDefault() + "\"";
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions