[英]Is it possible to add methods to OpenAPI?
I have a question: is it possible to add methods with some logic to DTO, generated by open-api.我有一个问题:是否可以将具有某些逻辑的方法添加到由 open-api 生成的 DTO。
For example I have an openapi DTO:例如我有一个 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:我使用 maven 插件(openapi-generator-maven-plugin),它为我生成了一个 java 类:
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?是否可以在openapi中添加一个方法,所以它将在我的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;
}
}
Sure, it is possibile.当然,这是可能的。
You have to override the pojo.mustache
file related to the OpenAPI generator you are using.您必须覆盖与您正在使用的 OpenAPI 生成器相关的pojo.mustache
文件。
I usually do that, and here is the official OpenAPI customization guide .我通常会这样做,这里是官方的 OpenAPI 定制指南。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.