swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

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

Open Santobert opened this issue 1 year ago • 1 comments

Related: https://github.com/OpenAPITools/openapi-generator/issues/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
...

Santobert avatar Jul 19 '23 08:07 Santobert

Related:

  • https://github.com/swagger-api/swagger-core/issues/4014
  • https://github.com/swagger-api/swagger-core/issues/3834

Santobert avatar Jan 30 '24 09:01 Santobert