Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why openapi-generator-maven-plugin ignores my xml tag names?

I am using the openapi-generator-maven-plugin

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

with the <withXml>true</withXml> option.

In my yaml service definition file to describe my REST actions (XML messages). I have a schema like this :

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

and the defined service :

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"

And I generate the client code. But when I use it, the XML sent to the http request uses <LoginRequest> has a tag name instead of <request>.

It seems that none of my -xml information are taken in account by the generator.

like image 404
the duck Avatar asked Nov 17 '25 02:11

the duck


1 Answers

You will need to put the option inside configOptions, for example

<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>

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

like image 52
William Cheng Avatar answered Nov 19 '25 17:11

William Cheng