Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][Maven] Maven plugin ignores generateApis #4506

Open
chrylis opened this issue Nov 17, 2019 · 6 comments
Open

[BUG][Maven] Maven plugin ignores generateApis #4506

chrylis opened this issue Nov 17, 2019 · 6 comments

Comments

@chrylis
Copy link

chrylis commented Nov 17, 2019

Note: This bug is encountered when using the Maven plugin, but it may be that it's a bug in the generator itself; I'm not sure whether the plugin is invoking it correctly.

Description

The Maven plugin version 4.2.1 ignores the documented generateApis and generateModels configuration parameters.

I am trying to separate the data types and the generated REST client into Maven modules, using these parameters to generate the code in the appropriate place. However, the Maven plugin appears not to inspect them at all.

This is not related to any specific spec file but is a matter of the generator invocation itself.

openapi-generator version

org.openapitools:openapi-generator-maven-plugin:4.2.1:generate

Steps to reproduce

I used the following POM plugin declaration:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>4.2.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/openapi/equipment.yaml</inputSpec>
                <generatorName>java</generatorName>
                <modelPackage>com.foo.equipment.api.openapi</modelPackage>
                <generateApis>false</generateApis>
                <apiPackage>foo</apiPackage>
                <configOptions>
                    <library>resttemplate</library>
                    <java8>true</java8>
                    <dateLibrary>java8</dateLibrary>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

When running using mvn -X, the mojo configuration model reflects the documented parameters:

<configuration>
  <!-- snip -->
  <configOptions>
    <library>resttemplate</library>
    <java8>true</java8>
    <dateLibrary>java8</dateLibrary>
  </configOptions>
  <!-- snip -->
  <generateApiDocumentation>${openapi.generator.maven.plugin.generateApiDocumentation}</generateApiDocumentation>
  <generateApiTests>${openapi.generator.maven.plugin.generateApiTests}</generateApiTests>
  <generateApis>false</generateApis>
  <generateModelDocumentation>${openapi.generator.maven.plugin.generateModelDocumentation}</generateModelDocumentation>
  <generateModelTests>${openapi.generator.maven.plugin.generateModelTests}</generateModelTests>
  <generateModels>${openapi.generator.maven.plugin.generateModels}</generateModels>
  <generateSupportingFiles>${openapi.generator.maven.plugin.generateSupportingFiles}</generateSupportingFiles>
  <generatorName>java</generatorName>
  <!-- snip -->
</configuration>

The configurator applies the generateApis setting:

[DEBUG] Configuring mojo 'org.openapitools:openapi-generator-maven-plugin:4.2.1:generate' with basic configurator -->
[DEBUG]   (f) addCompileSourceRoot = true
[DEBUG]   (f) additionalProperties = []
[DEBUG]   (f) configOptions = {dateLibrary=java8, java8=true, library=resttemplate}
[DEBUG]   (f) engine = mustache
[DEBUG]   (f) generateApis = false
[DEBUG]   (f) generatorName = java
[DEBUG]   (f) importMappings = []
[DEBUG]   (f) inputSpec = <redacted>
[DEBUG]   (f) instantiationTypes = []
[DEBUG]   (f) languageSpecificPrimitives = []
[DEBUG]   (f) modelPackage = com.foo.equipment.api.openapi
[DEBUG]   (f) output = <redacted>
[DEBUG]   (f) project = <redacted>
[DEBUG]   (f) reservedWordsMappings = []
[DEBUG]   (f) serverVariableOverrides = []
[DEBUG]   (f) skip = false
[DEBUG]   (f) skipIfSpecIsUnchanged = false
[DEBUG]   (f) typeMappings = []
[DEBUG]   (f) verbose = false
[DEBUG] -- end configuration --

Nevertheless, the generator generates a REST client (using an incorrectly "derived" package name):

[INFO] OpenAPI Generator: java (client)
[INFO] Generator 'java' is considered stable.
[INFO] Environment variable JAVA_POST_PROCESS_FILE not defined so the Java code may not be properly formatted. To define it, try 'export JAVA_POST_PROCESS_FILE="/usr/local/bin/clang-format -i"' (Linux/Mac)
[INFO] NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[INFO] Invoker Package Name, originally not set, is now derived from model package name: com.foo.equipment.api

and the build fails because of missing dependencies.

The inverse does not seem to be true; i.e., the generateModels=false setting is respected.

Suggest a fix

It would be useful for the Maven plugin to log the exact config it is passing to DefaultGenerator at DEBUG; even using mvn -X does not provide output useful to debugging this problem.

@chrylis chrylis changed the title [BUG][Maven] Maven plugin ignores generateApis and geneateModels [BUG][Maven] Maven plugin ignores generateApis Nov 17, 2019
@janweinschenker
Copy link
Contributor

To prevent the contents of the package invalidPackageName from being generated, add the option <generateSupportingFiles>false</generateSupportingFiles>.

Using the options

<generateApis>false</generateApis>
<generateSupportingFiles>false</generateSupportingFiles>

will do what you intend, if I understood you correctly, i.e. will just generate the models.

Maybe this is just an issue of naming things?

@ndup0nt
Copy link

ndup0nt commented Jun 3, 2020

You can workaround this by using properties in your pom.xml :

<properties> 
 <openapi.generator.maven.plugin.generateApis>false</openapi.generator.maven.plugin.generateApis> 
</properties>

frodank added a commit to navikt/pensjon-brev-bestilling that referenced this issue Sep 11, 2020
@iWantUss
Copy link
Contributor

org.openapitools.codegen.DefaultGenerator:208

generateApis = GlobalSettings.getProperty(CodegenConstants.APIS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.APIS, null);

This condition result always returns Boolean.TRUE

Please, look at my solution in PR #14126

@wing328
Copy link
Member

wing328 commented May 16, 2023

closed via #14126

@wing328 wing328 closed this as completed May 16, 2023
@wing328 wing328 reopened this May 21, 2023
@wing328
Copy link
Member

wing328 commented May 21, 2023

Regression reported in #14119. Will revert the fix.

@martin-mfg
Copy link
Contributor

It would be useful for the Maven plugin to log the exact config it is passing to DefaultGenerator at DEBUG; even using mvn -X does not provide output useful to debugging this problem.

The latest snapshot version of OpenAPI Generator prints most of the config. It currently looks like this:

[DEBUG] GeneratorSettings#build: GeneratorSettings{generatorName='java', apiPackage='null', modelPackage='null', invokerPackage='null', packageName='null', apiNameSuffix='null', modelNamePrefix='null', modelNameSuffix='null', groupId='null', artifactId='null', artifactVersion='null', library='native', instantiationTypes={}, typeMappings={}, additionalProperties={gitHost=dummyGitHost, releaseNote=Minor update, gitUserId=GIT_USER_ID, gitRepoId=GIT_REPO_ID}, importMappings={}, languageSpecificPrimitives=[], reservedWordsMappings={dummyKey=dummyValue}, gitHost='dummyGitHost', gitUserId='GIT_USER_ID', gitRepoId='GIT_REPO_ID', releaseNote='Minor update', httpUserAgent='null'}
[DEBUG] WorkflowSettings#build: WorkflowSettings{inputSpec='C:\Users\margebe\Desktop\openapi-generator-input.json', outputDir='C:\Users\margebe\Desktop\Issue15203\target\generated-sources\openapi', verbose=false, skipOverwrite=false, removeOperationIdPrefix=false, logToStderr=false, validateSpec=true, enablePostProcessFile=false, enableMinimalUpdate=false, strictSpecBehavior=true, templateDir='null', templatingEngineName='mustache', ignoreFileOverride='null', globalProperties={apis=dummyType1,dummyType2}, generateAliasAsModel=false}

To add the (as far as I can see) last piece of information to the debug logs, I created #16961. This PR will add logging of "GlobalSettings", i.e. mostly environment variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants