Skip to content

[BUG] Maven plugin incorrectly marks inputSpec as a required field #16955

Closed
@jack-handley

Description

@jack-handley

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using the maven plugin, I can specify an Open API Spec file using the <inputSpec>./filename.yaml</inputSpec> tag, or I can specify an <inputSpecRootDirectory>./directory-of-specs/</inputSpecRootDirectory> for it to merge the files before generating the code. When I choose the latter option, I get an error saying inputSpec is required, despite the generator ignoring the input when the inputSpecRootDirectory is specified:

        if (StringUtils.isNotBlank(inputSpecRootDirectory)) {
            inputSpec = new MergedSpecBuilder(inputSpecRootDirectory, mergedFileName)
                .buildMergedSpec();
            LOGGER.info("Merge input spec would be used - {}", inputSpec);
        }

        File inputSpecFile = new File(inputSpec);

As such, the inputSpec parameter should be optional, and validation should check that one of inputSpec or inputSpecRootDirectory is specified (perhaps with a warning if both are given)

openapi-generator version

Latest (7.0.1)

Maven pom.xml
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <!-- RELEASE_VERSION -->
                <version>7.0.1</version>
                <!-- /RELEASE_VERSION -->
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
<!--                            <inputSpec>${project.basedir}/src/main/resources/openapi/api.yaml</inputSpec>-->
                            <inputSpecRootDirectory>${project.basedir}/src/main/resources/openapi</inputSpecRootDirectory>
                            <generatorName>java</generatorName>
                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                            </configOptions>
                            <skipValidateSpec>true</skipValidateSpec>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

https://github.com/fullstack-jack/openapi-generator-maven-plugin-example

Steps to reproduce
  1. Clone example repo: https://github.com/fullstack-jack/openapi-generator-maven-plugin-example
  2. Run mvn generate-sources to see required field error
  3. Edit pom.xml to pass an arbitrary inputSpec e.g. <inputSpec>xxx</inputSpec>
  4. Rerun mvn generate-sources to see it create sources correctly despite useless inputSpec
Related issues/PRs

none

Suggest a fix

I might get round to creating a PR some time this week but support from anyone else is very welcome.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions