mavenopenapiopenapi-generator

OpenAPI custom generator with Maven plugin fails with ClassNotFoundException


I'm trying to write an OpenAPI custom generator as mentioned at openapi-generator on GitHub. Generated the codegen with below command.

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar meta \
  -o out/generators/my-codegen -n my-codegen -p com.my.company.codegen

In the project, I extended the MyCodegenGenerator from JavaJAXRSCXFCDIServerCodegen and added the required mustache templates. When I tried to build the new codegen project, tests failed. So I skipped the tests and built the project. Then I proceeded with the next steps in the guide to use the custom codegen with the Maven plugin. As mentioned in the guide I used my-codegen as the generatorName:

<generatorName>my-codegen</generatorName>

I'm getting below error:

org.openapitools.codegen.GeneratorNotFoundException:
    Can't load config class with name 'my-codegen'

Tried com.my.company.codegen.MyCodegenGenerator as well as the generatorName and still get a similar error.

Please help me to resolve this issue.


Solution

  • I was able to find the cause of the issue. I had added the below dependency to the dependencies section of the build initially.

    <dependency>
      <groupId>org.openapitools</groupId>
      <artifactId>my-codegen-openapi-generator</artifactId>
      <version>1.0.0</version>
    </dependency>
    

    After adding the dependency to the dependencies section of the plugin configuration, I was able to resolve the issue.