Skip to content

Java attribute of type object is incorrectly mapped to an OpenApi property of type object #4457

@Santobert

Description

@Santobert

Related: OpenAPITools/openapi-generator#16110

Description

A Java attribute of type object can be any instance of an object, e.g. String, Boolean, Long and so on. However, the resulting OpenApi specification assigns this attribute to an object of type object, which must be a JSON object, that is a map.

Example

The following java class can be used as a minimal example:

public class Pet{
	private Long id;

	@Schema(description = "A string, a number or a boolean", anyOf = { String.class, Number.class, Boolean.class })
	private Object name;
}

This generates the following openapi.yaml:

...
    properties:
      name:
        type: object
        description: "A string, a number or a boolean"
        anyOf:
        - type: string
        - type: integer
          format: int64
        - type: number
          format: double
        - type: boolean
...

whereas the following would be correct:

...
    properties:
      name:
        description: "A string, a number or a boolean"
        anyOf:
        - type: string
        - type: integer
          format: int64
        - type: number
          format: double
        - type: boolean
...

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