2

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.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
Maduranga Siriwardena
  • 1,341
  • 1
  • 13
  • 27

2 Answers2

3

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.

Maduranga Siriwardena
  • 1,341
  • 1
  • 13
  • 27
1

You don't have to modify the pom.xml. Simply check that in your *Generator class, the overriden method getName() returns the same String as you use in .setGeneratorName(..) method call in your test class.

Also you have to check that the path at .setInputSpec(..) points to a valid yaml file which is out of the box not the case.