Home > Mobile >  How to change packaging structure in open api code generator input yml file
How to change packaging structure in open api code generator input yml file

Time:01-25

I am using open api generator tool to generate spring code using petstore.yaml from swagger as input file and I want to change the default packing structure while generating code. Can i change packaging structure if yes which mustache file need modify

I want packaging like this enter image description here

CodePudding user response:

I am assuming that you are using openapi-generator-maven-plugin to generate. You can specify output locations and package names (model and api) by using the plugin config in your project POM file as follows. A full list is of parameters here

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>${openapi-generator-maven-plugin-version}</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/yaml/yamlfilename.yaml</inputSpec>
                <output>${project.build.directory}/generated-sources</output>
                <apiPackage>${default.package}.handler</apiPackage>
                <modelPackage>${default.package}.model</modelPackage>
                <invokerPackage>${default.package}.handler</invokerPackage>
            </configuration>
        </execution>
    </executions>

</plugin>

CodePudding user response:

If you are using the openapi-generator cli you can specify output locations and package names (model and api) with command line arguments. The following will allow control of the package structure:

-o path/to/generated/code
--api-package foo.bar.api
--model-package foo.bar.model
--invoker-package foo.bar.client
--additional-properties <additional properties>

eg from npx

npx @openapitools/openapi-generator-cli generate -i api.json -g spring --additional-properties=library=spring-cloud -o ./ --api-package foo.bar.api --model-package foo.bar.model

eg from Java jar

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i api.json -g spring --additional-properties=library=spring-cloud -o ./ --api-package foo.bar.api --model-package foo.bar.model

A full list is of parameters is here. You need to turn the camelCase into kebab-case to use from command line.

  • Related