Skip to content

[JaxRS-Spec] add openApiSpecFileLocation parameter#3344

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
jmini:issue809_configuration_openapi_spec
Jul 14, 2019
Merged

[JaxRS-Spec] add openApiSpecFileLocation parameter#3344
wing328 merged 2 commits intoOpenAPITools:masterfrom
jmini:issue809_configuration_openapi_spec

Conversation

@jmini
Copy link
Member

@jmini jmini commented Jul 11, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language. Java: @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04)

Description of the PR

Currently the OpenAPI Spec is generated to src/main/openapi/openapi.yaml. This is not conform with the Eclipse MicroProfile OpenAPI which is the spec that defines how OpenAPI should be used on top of JAX-RS.

This PR introduces a new parameter openApiSpecFileLocation to be able to specify where the generated spec should be generated.

  • Default value: src/main/openapi/openapi.yaml (no change for existing users)
  • Possible value src/main/resources/META-INF/openapi.yaml to be conform with the MP-OpenAPI spec
  • In order to not generate the spec, the value can be set to null or empty string ""

Fixes #809

@jmini jmini force-pushed the issue809_configuration_openapi_spec branch from ef85c04 to 516163b Compare July 12, 2019 05:06
"openapi.yaml")
);
if(StringUtils.isNotEmpty(openApiSpecFileLocation)) {
int index = openApiSpecFileLocation.lastIndexOf('/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmini shall we use File.separator instead of / so that the option also works in Windows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even on windows the users will use openApiSpecFileLocation = some/location/openapi.yaml as input.
(think of a maven/gradle build that works on both windows and linux/macos)

That will result of creating a file at output-folder\some\location\openapi.yaml.

As you can see I have a test:

@Test
public void testGeneratePingAlternativeLocation1() throws Exception {
Map<String, Object> properties = new HashMap<>();
properties.put(JavaClientCodegen.JAVA8_MODE, true);
properties.put(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION, "src/main/resources/META-INF/openapi.yaml");
File output = Files.createTempDirectory("test").toFile();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("jaxrs-spec")
.setAdditionalProperties(properties)
.setInputSpec("src/test/resources/3_0/ping.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
final ClientOptInput clientOptInput = configurator.toClientOptInput();
MockDefaultGenerator generator = new MockDefaultGenerator();
generator.opts(clientOptInput).generate();
Map<String, String> generatedFiles = generator.getFiles();
TestUtils.ensureContainsFile(generatedFiles, output, "src/main/resources/META-INF/openapi.yaml");

Line 240 the variable is set to "src/main/resources/META-INF/openapi.yaml"
Line 255 there is a check that the file is created.

This is already working on windows (appveyor CI is green)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even on windows the users will use openApiSpecFileLocation = some/location/openapi.yaml as input.

👌 Let's see.

@wing328 wing328 added this to the 4.1.0 milestone Jul 14, 2019
@wing328 wing328 merged commit 41d5750 into OpenAPITools:master Jul 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JAXRS-spec] Make path for openapi.yaml configurable

2 participants

Comments