为什么openapi-generator-maven-plugin会忽略我的xml标签名称?

时间:2019-10-26 12:14:05

标签: java xml swagger openapi openapi-generator

我正在使用openapi-generator-maven-plugin

            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>4.1.3</version>

使用<withXml>true</withXml>选项。

在我的yaml服务定义文件中,用于描述我的REST操作(XML消息)。我有一个这样的架构:

components:
  schemas:
    LoginRequest:
      type: object
      properties:
        customerName:
          type: string
          xml:
            name: customerName
            attribute: false
            wrapped: false
        password:
          type: string
          xml:
            name: hello
            attribute: false
        user:
          type: string
          xml:
            name: user
            attribute: false
            wrapped: false
      title: request
      xml:
        name: request
        attribute: false

和已定义的服务:

paths:
  /session/login:
    post:
      tags:
        - sample-controller
      summary: login
      operationId: loginUsingPOST      
      requestBody:
        content:
          application/xml:
            schema:
              $ref: "#/components/schemas/LoginRequest"
        description: request
        required: true
      responses:
        "200":
          description: OK
          content:
            application/xml:
              schema:
                $ref: "#/components/schemas/LoginResponse"

然后生成客户端代码。但是当我使用它时,发送到http请求的XML使用<LoginRequest>而不是<request>来标记。

生成器似乎没有考虑我的-xml信息。

1 个答案:

答案 0 :(得分:2)

例如,您需要将选项放在configOptions

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <!-- RELEASE_VERSION -->
    <version>4.2.0</version>
    <!-- /RELEASE_VERSION -->
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
                <generatorName>java</generatorName>
                <configOptions>
                   <sourceFolder>src/gen/java/main</sourceFolder>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

参考:https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin#usage