SpringCodegen generates class with JsonTypeInfo.As.EXISTING_PROPERTY instead of JsonTypeInfo.As.PROPERTY

533 Views Asked by At

One field is not showing anymore in the deserialization of the json.

It happened because our code generator is transforming the OpenApi definition into this:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true)

Before it was working because it translated into:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)

This code is generated from an openapi: 3.0.2 yml file with SpringCodegen.

Does anyone know if I can tell in the open api definition or in the maven openApi plugin to generate the code to use: JsonTypeInfo.As.PROPERTY?

We are using Java 11

Thank you very much

Regards.

In my local test It worked with JsonTypeInfo.As.PROPERTY and JsonTypeInfo.As.EXTERNAL_PROPERTY but the code is generated with JsonTypeInfo.As.EXISTING_PROPERTY which I cannot change in the generated clases.

1

There are 1 best solutions below

0
iguanito On

As far as I can tell, it is not possible to configure openapi generator's JsonTypeInfo generation. These definitions are hard-coded in mustache templates in openapi generator codebase.

To see how JsonTypeInfo are generated, I would suggest the following:

  • clone openapi-generator repo.
  • checkout the tag corresponding to the version of openapi generator you are using.
  • find the mustache templates. They should be under openapi-generator/modules/openapi-generator/src/main/resources/.
  • find the corresponding generator and look at typeInfoAnnotation.mustache template .

You may want to checkout other tags to find the version that generate the JsonTypeInfo you expect, if any.

Note: I could not find any reference to JsonTypeInfo.As.EXISTING_PROPERTY in openapi generator v3.0.2