java - 使用实现外部接口的 openapi 生成器创建模型类
问题描述
我正在使用 openapi-generator 生成 java 类。
我希望模型类实现一个尚未由 openapi-generator 生成的外部接口。
是否有可以在模型 yaml 中定义的东西或可以传递给允许这种行为的 openapi-generator-maven-plugin 的属性?
所需行为示例:
package com.example.model;
/**
* ExampleModel
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public class ExampleModel implements com.example.CustomInterface {
@JsonProperty("property1")
private String property1;
@JsonProperty("property2")
private String property2;
解决方案
如果您想以相同的方式修改所有类,我会选择更改模板。在你的情况下,这很可能是这个文件:pojo.mustache
只需将其复制到您的src/main/resources/
文件夹(可能在名为 custom 的子文件夹中)并根据您的需要进行调整。
然后你也需要调整你的pom.xml
:
<configuration>
<!-- The following line is crucial: -->
<templateDirectory>${project.basedir}/src/main/resources/custom</templateDirectory>
<!-- Your other config goes here: -->
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
</configOptions>
</configuration>
另请查看此模板文档以获取有关该主题的更多信息。
推荐阅读
- kubernetes - 来自事件导出器容器的所有“提供的手表的资源版本太旧”警告是什么?
- kubernetes - Minikube 使用 Alpine linux 在执行到 Pod 时崩溃
- javascript - 如何定位重复的 JS 元素 BeautifulSoup Python
- c++ - 原生 WebRTC 丢帧
- php - 在 PHP 中使用会话
- python - Django 重定向到视图进行处理,然后到 outputView
- linux - zsh 替换:(P) 和 ::= 运算符交互
- javascript - JavaScript 类中出现意外的标记“=”
- oracle-apex-5.1 - Oracle APEX:无法编辑交互式网格中的 URL 列
- java - 它不会将所有对象从 List 转移到 Set