Skip to content

@JsonProperty name ignored in OpenAPI metadata when @Schema present as well  #787

@oujesky

Description

@oujesky

Expected Behavior

@JsonProperty specified name of the field will be used in generated OpenAPI metadata

...
components:
  schemas:
    ExampleModel:
      type: object
      properties:
        nameInJson:
          type: string
          description: example field

Actual Behaviour

Class field name is used in generated OpenAPI metadata and the value in @JsonProperty is ignored

...
components:
  schemas:
    ExampleModel:
      type: object
      properties:
        nameInPojo:
          type: string
          description: example field
      description: ""

Steps To Reproduce

  1. Controller returning simple Pojo
@Controller("/api/example")
public class ExampleController {
    @Get
    public ExampleModel getExample() {
        return new ExampleModel();
    }
}
  1. Pojo with field annotated with both @JsonProperty & @Schema
@Introspected
public class ExampleModel {
    @JsonProperty("nameInJson")
    @Schema(description = "example field")
    private String nameInPojo;

    public String getNameInPojo() {
        return nameInPojo;
    }
}
  1. Compile code which generates the OpenAPI metadata

Additional notes:

Environment Information

  • Windows 10
  • JDK 17

Example Application

https://github.com/oujesky/micronaut-openapi-model-bug

Version

3.6.0

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