openapi-processor / openapi-processor-spring

an OpenAPI 3.0 & 3.1 interface & model java code generator for Spring Boot
https://docs.openapiprocessor.io
Apache License 2.0
40 stars 9 forks source link

import for the `.class` parameter to an annotation isn't added #271

Closed mjparme closed 5 months ago

mjparme commented 5 months ago

If we have a mapping that aims to add a JsonDeserialize annotation to some of the generated classes, like this:

    - type: SomeClass @ com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.SomeClassDeserializer.class)

The JsonDeserialize annotation is correctly added, however, the import for com.example isn't added. This makes compilation of the generated classes fail.

It is generated like this:

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import jakarta.validation.Valid;
import java.util.List;
import lombok.Builder;

@JsonDeserialize(SomeClassDeserializer.class)
@Builder
@Generated(value = "openapi-processor-spring", version = "2024.3")
public record SomeClass(
    @JsonProperty("foo")
    List<@Valid ArrayOfFoos> foo
) {}

This is almost correct. It just needs to add the import for the class that is in the using parameter.

As it is it doesn't seem possible to generate models from OpenAPI spec with polymorphic types (i.e. specs that use oneOf) that will result in successful parsing.

hauner commented 5 months ago

Yes, that is a a bug. :disappointed:

Thanks for reporting!