[英]OpenAPI Generator does not generate api interfaces openapi-generator-maven-plugin
[英]Openapi generator does not generate @XmlAttribute/@XmlElement annotations
我目前正在擺弄 openapi 並嘗試創建一個使用 XML 文件的端點。 然而,當使用 openapi 創建模型時,我習慣的所有 XML 注釋似乎都丟失了。 這是我正在使用的 openapi.yaml。
openapi: 3.0.1
info:
version: "1.1"
title: xml test
description: some xml test
servers:
- url: 'http://localhost/:8080'
paths:
'/test':
put:
operationId: testMethodNaming
requestBody:
content:
'application/xml':
schema:
$ref: '#/components/schemas/MyRequest'
responses:
'200':
description: 'OK'
components:
schemas:
MyRequest:
type: object
properties:
name:
type: string
xml:
attribute: true
MyRequest
模式是現在有問題的東西。 請注意,我將 name 屬性聲明為 XML 屬性。 生成的 class 看起來像這樣:
/**
* MyRequest
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2019-03-12T15:32:37.070386+01:00[Europe/Berlin]")
public class MyRequest {
@JsonProperty("name")
private String name;
public MyRequest name(String name) {
this.name = name;
return this;
}
/**
* Get name
* @return name
*/
@ApiModelProperty(value = "")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MyRequest myRequest = (MyRequest) o;
return Objects.equals(this.name, myRequest.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class MyRequest {\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
我使用 spring-boot 生成器生成了這個。 我本來希望在名稱字段上方出現@XmlAttribute
注釋。 我還期望在@XmlRootElement
之上會有一個 @XmlRootElement。
由於某種原因,我現在無法運行生成的代碼,但似乎如果我將<MyRequest name="foobar">
發送到端點,它將無法用 model 解析它。
我是否錯過了一些配置選項或任何東西,所以它會生成正確的注釋?
查看openapi的源代碼所需的注釋在那里
對我來說,事情變得越來越清晰:現在,OpenAPITools的生成器以及它的SwaggerCodeGen都將json作為主要目標格式。 Xml支持true,但更多情況下是可選的,坦率地說非常糟糕。 我最近發現了3個錯誤:
為了使其工作,我必須自定義各種胡須模板 ,以具有正確的xml注釋。 解決方法在第一期中進行了描述。
重要提示:還請確保withXml
選項已激活,以便withXml
Pojo模板將生成所需的xml注釋。
祝好運。
您必須在正確的位置使用 configOption“withXML”。 它必須在“configOptions”中定義:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
<execution>
<id>openapi-generator-generate</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>some.yaml</inputSpec>
<output>target/generated-sources</output>
<generatorName>java</generatorName>
<generateApis>true</generateApis>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelTests>false</generateModelTests>
<modelPackage>com.model</modelPackage>
<apiPackage>com.client</apiPackage>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<withXml>true</withXml>
<library>resttemplate</library>
<interfaceOnly>true</interfaceOnly>
<useBeanValidation>true</useBeanValidation>
<!-- <dateLibrary>java8</dateLibrary>-->
<java8>true</java8>
<unhandledException>true</unhandledException>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.