Skip to content

Commit

Permalink
Issue OpenAPITools#795: Add microprofile OpenAPI annotations for quar…
Browse files Browse the repository at this point in the history
…kus library in JaxRsSpec
  • Loading branch information
Nuno Borges authored and Nuno Borges committed May 2, 2023
1 parent 998fd0e commit d2ce117
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ void generateApis(List<File> files, List<OperationsMap> allOperations, List<Mode
operation.put("importPath", config.toApiImport(tag));
operation.put("classFilename", config.toApiFilename(tag));
operation.put("strictSpecBehavior", config.isStrictSpecBehavior());
Optional.ofNullable(openAPI.getInfo()).map(Info::getLicense).ifPresent(license -> operation.put("license", license));
Optional.ofNullable(openAPI.getInfo()).map(Info::getContact).ifPresent(contact -> operation.put("contact", contact));

if (allModels == null || allModels.isEmpty()) {
operation.put("hasModel", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ import java.util.List;
{{#useBeanValidation}}import {{javaxPackage}}.validation.constraints.*;
import {{javaxPackage}}.validation.Valid;{{/useBeanValidation}}

{{#useMicroProfileOpenAPIAnnotations}}@OpenAPIDefinition(info = @Info(title = "{{{tagName}}}", version="{{{version}}}", description="{{{tagDescription}}}")){{/useMicroProfileOpenAPIAnnotations}}{{#useSwaggerAnnotations}}
{{#useMicroProfileOpenAPIAnnotations}}@OpenAPIDefinition(
info = @Info(
title = "{{{tagName}}}", version="{{{version}}}", description="{{{tagDescription}}}"{{#license}},
license = @License(name = "{{{name}}}", url = "{{{url}}}"){{/license}}{{#contact}},
contact = @Contact(name = "{{{name}}}", email = "{{{email}}}"){{/contact}}
),
tags = {
@Tag(name="{{{tagName}}}", description="{{{tagDescription}}}")
}){{/useMicroProfileOpenAPIAnnotations}}{{#useSwaggerAnnotations}}
@Api(description = "the {{{baseName}}} API"){{/useSwaggerAnnotations}}
@Path("{{commonPath}}"){{#hasConsumes}}
@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
@ApiResponses(value = { {{#responses}}
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}){{^-last}},{{/-last}}{{/responses}} }){{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}}
{{#hasAuthMethods}}@SecurityRequirements(value={
{{#authMethods}}{{#isOAuth}}@SecurityRequirement(name = "{{name}}", scopes = { {{#scopes}} "{{scope}}"{{^-last}},{{/-last}} {{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}}{{^isOAuth}}
@SecurityRequirement(name = "{{name}}"){{^-last}},{{/-last}}{{/isOAuth}}{{/authMethods}} }){{/hasAuthMethods}}
{{#authMethods}}{{#isOAuth}}@SecurityRequirement(name = "{{name}}", scopes = { {{#scopes}} "{{scope}}"{{^-last}},{{/-last}} {{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}}{{^isOAuth}} @SecurityRequirement(name = "{{name}}"){{^-last}},{{/-last}}{{/isOAuth}}
{{/authMethods}} }){{/hasAuthMethods}}
@Operation(operationId = "{{{operationId}}}", summary = "{{{summary}}}", description = "{{{notes}}}")
{{#vendorExtensions.x-tags}}@Tag(name="{{tag}}"){{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}}{{#hasProduces}}
@APIResponses(value = { {{#responses}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}}
}){{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}}
{{#hasAuthMethods}}@SecurityRequirements(value={
{{#authMethods}}{{#isOAuth}}@SecurityRequirement(name = "{{name}}", scopes = { {{#scopes}} "{{scope}}"{{^-last}},{{/-last}} {{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}}{{^isOAuth}}
@SecurityRequirement(name = "{{name}}"){{^-last}},{{/-last}}{{/isOAuth}}{{/authMethods}} }){{/hasAuthMethods}}
{{#authMethods}}{{#isOAuth}}@SecurityRequirement(name = "{{name}}", scopes = { {{#scopes}} "{{scope}}"{{^-last}},{{/-last}} {{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}}{{^isOAuth}} @SecurityRequirement(name = "{{name}}"){{^-last}},{{/-last}}{{/isOAuth}}
{{/authMethods}} }){{/hasAuthMethods}}
@Operation(operationId = "{{{operationId}}}", summary = "{{{summary}}}", description = "{{{notes}}}")
{{#vendorExtensions.x-tags}}@Tag(name="{{tag}}"){{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}}{{#hasProduces}}
@APIResponses(value = { {{#responses}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,18 +825,21 @@ public void generateSpecInterfaceWithMicroprofileOpenApiAnnotations() throws Exc
//And the generated interfaces contains CompletionStage
TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/PetApi.java");
assertFileContains(output.toPath().resolve("src/gen/java/org/openapitools/api/PetApi.java"),
"@OpenAPIDefinition(info = @Info(title = \"pet\", version=\"1.0.0\", description=\"Everything about your Pets\"))"
);
"@OpenAPIDefinition(\n" +
" info = @Info(\n" +
" title = \"pet\", version=\"1.0.0\", description=\"Everything about your Pets\",");

TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/StoreApi.java");
assertFileContains(output.toPath().resolve("src/gen/java/org/openapitools/api/StoreApi.java"),
"@OpenAPIDefinition(info = @Info(title = \"store\", version=\"1.0.0\", description=\"Access to Petstore orders\"))"
);
"@OpenAPIDefinition(\n" +
" info = @Info(\n" +
" title = \"store\", version=\"1.0.0\", description=\"Access to Petstore orders\",");

TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/UserApi.java");
assertFileContains(output.toPath().resolve("src/gen/java/org/openapitools/api/UserApi.java"),
"@OpenAPIDefinition(info = @Info(title = \"user\", version=\"1.0.0\", description=\"Operations about user\"))"
);
"@OpenAPIDefinition(\n" +
" info = @Info(\n" +
" title = \"user\", version=\"1.0.0\", description=\"Operations about user\",");
}

@Test
Expand Down Expand Up @@ -868,17 +871,20 @@ public void generateSpecNonInterfaceWithMicroprofileOpenApiAnnotations() throws
//And the generated interfaces contains CompletionStage
TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/PetApi.java");
assertFileContains(output.toPath().resolve("src/gen/java/org/openapitools/api/PetApi.java"),
"@OpenAPIDefinition(info = @Info(title = \"pet\", version=\"1.0.0\", description=\"Everything about your Pets\"))"
);
"@OpenAPIDefinition(\n" +
" info = @Info(\n" +
" title = \"pet\", version=\"1.0.0\", description=\"Everything about your Pets\",");

TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/StoreApi.java");
assertFileContains(output.toPath().resolve("src/gen/java/org/openapitools/api/StoreApi.java"),
"@OpenAPIDefinition(info = @Info(title = \"store\", version=\"1.0.0\", description=\"Access to Petstore orders\"))"
);
"@OpenAPIDefinition(\n" +
" info = @Info(\n" +
" title = \"store\", version=\"1.0.0\", description=\"Access to Petstore orders\",");

TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/UserApi.java");
assertFileContains(output.toPath().resolve("src/gen/java/org/openapitools/api/UserApi.java"),
"@OpenAPIDefinition(info = @Info(title = \"user\", version=\"1.0.0\", description=\"Operations about user\"))"
);
"@OpenAPIDefinition(\n" +
" info = @Info(\n" +
" title = \"user\", version=\"1.0.0\", description=\"Operations about user\",");
}
}

0 comments on commit d2ce117

Please sign in to comment.