Skip to content

[BUG] Go Code Generator do not strip out {} in oneOf #13166

@mariotoffia

Description

@mariotoffia
Description

The GoClientCodeGen.java do incorrectly render the typeToName. The problem seems to be in

private String typeToName(String content) {
        content = content.trim().replace("[]", "array_of_");
        content = content.trim().replace("[", "map_of_");
        content = content.trim().replace("]", "");
        return camelize(content);
    }

where the content is (in my case) map[string]interface{} and the curly braces are not stripped.

openapi-generator version

Version 6.0.1

OpenAPI declaration file content or url
DataPoint:
  oneOf:
    - type: object
    - type:
      $ref: '#/SimpleDataPoint'
SimpleDataPoint:
  properties:
    v:
      type: number
    t:
      type: integer
  required:
    - v
    - t

Will generate the following struct where the MapmapOfStringinterface{} occurs.

type DataPoint struct {
	SimpleDataPoint *SimpleDataPoint
	MapmapOfStringinterface{} *map[string]interface{}
}

(🎃As a sidenote, the anyOf (mustache template) will never even try to use #lambda.type-to-name and therefore instead it will render the map[string]interface{} *map[string]interface{}.)

Steps to reproduce

generate the above snippet

Suggest a fix

Just replace {} with empty string before camelize.

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