Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor @JsonTypeInfo @JsonTypeName #585

Closed
sakibulalam opened this issue Apr 19, 2020 · 1 comment
Closed

Honor @JsonTypeInfo @JsonTypeName #585

sakibulalam opened this issue Apr 19, 2020 · 1 comment

Comments

@sakibulalam
Copy link

sakibulalam commented Apr 19, 2020

Problem/Issue:
I have a class annotated with @JsonTypeInfo to define a wrapper property. But it seems it's not being honored when generating the spec yaml/json. This is a mismatch with the actual API response.

@Schema(name = "ErrorResponse")
@JsonTypeName(value = "error")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
data class ErrorResponse(
    val message: String,
    val details: List<String>? = null
)

The produced output is

...
components:
  schemas:
    ErrorResponse:
      required:
      - message
      type: object
      properties:
        details:
          type: object
        message:
          type: string
...

The expected output should be

...
components:
  schemas:
    ErrorResponse:
      required: 
        - error
      properties:
        error:
          required:
          - message
          type: object
          properties:
            details:
              type: array
              items:
                type: string
            message:
              type: string
...

Solution:
When resolving the schema of the classes, the resolver should honor the @JsonTypeInfo, @JsonTypeName annotation

Alternatives:
Right now the only solution I see is to add an additional wrapper class to get it to generate accurate yaml/json.

@bnasslahsen
Copy link
Collaborator

@sakibulalam,

This request is not related to springdoc-openapi.
There no direct usage of @JsonTypeInfo and @JsonTypeName by the code of springdoc-openapi.

We rely on swagger-core which generates the correct mapping of objects.
There is already know issue about Json wrapper objects:

And you can alternatively, use your workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants