Skip to content

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

@mjparme

Description

@mjparme

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions