The World’s Largest Online Community for Developers

'; java - How to get micronaut generate OpenAPI schema properties for Value.Immutable classes? - LavOzs.Com

I am using Value.Immutable classes as the rest api request/response. The generated OpenAPI doc does not show the properties of the immutable class. It looks like the OpenAPI generator does not understand these beans as there are no getters and setters in the immutable abstract definition.

How could I properly generate the OpenAPI doc when I use Value.Immutable classes?

Here's a simple example --

The Value.Immutable class:

@JsonSerialize(as = ImmutableCity.class)
@JsonDeserialize(as = ImmutableCity.class)
@Schema(implementation = ImmutableCity.class, name = "City", description = "City model")
    passAnnotations = {Schema.class},
    visibility = ImplementationVisibility.PUBLIC)
public abstract class City {

    public abstract String name();

    public abstract String description();

The controller:

public class CityController {

     * Persist a city
     * @param city
     * @return the persisted city
    @Tag(name = "city")
    public HttpResponse<City> save(
        @Body City city) {
        // persist it...
        return HttpResponse.created(city);

The generated OpenAPI schema for City has no properties:

      type: object
      description: City model

If I change to not use immutables but to have getters/setters, the properties are generated:

      type: object
      description: City model
          minLength: 1
          type: string
          type: string
How do I test a private function or a class that has private methods, fields or inner classes?
How to generate a random alpha-numeric string?
How do I generate random integers within a specific range in Java?
How can I generate an MD5 hash?
How to create a generic array in Java?
How to get an enum value from a string value in Java?
Get generic type of class at runtime
How do I get a class instance of generic type T?
Generate a property as schema definition in OpenApi 3.0