Is it possible to add methods to OpenAPI?

Viewed 107

I have a question: is it possible to add methods with some logic to DTO, generated by open-api.

For example I have an openapi DTO:

CarDTO:
   type: object
   properties:
     id:
       type: string
       format: uuid
     isEngineWorks:
       type: boolean
       default: false
     isFuelFull:
       type: boolean
       default: false

I use maven plugin (openapi-generator-maven-plugin) and it generates me a java class:

public class CarDTO {
    @JsonProperty("id")
    @Valid
    private UUID id;

    @JsonProperty("isEngineWorks")
    private Boolean isEngineWorks = false;

    @JsonProperty("isFuelFull")
    private Boolean isFuelFull = false;
}

Is it possible to add a method in openapi, so it will be generated in my DTO? as a result, I want to have:

public class CarDTO {
    @JsonProperty("id")
    @Valid
    private UUID id;

    @JsonProperty("isEngineWorks")
    private Boolean isEngineWorks = false;

    @JsonProperty("isFuelFull")
    private Boolean isFuelFull = false;
    
    public boolean isCarReadyToDrive {
        return isEngineWorks && isFuelFull;  
    }

}
1 Answers
Related