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 9, 2023
1 parent d4eee01 commit 7ff1431
Show file tree
Hide file tree
Showing 73 changed files with 13,664 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/samples-jaxrs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- samples/server/petstore/jaxrs-cxf-annotated-base-path
- samples/server/petstore/jaxrs-cxf-cdi
- samples/server/petstore/jaxrs-cxf-non-spring-app
- samples/server/petstore/jaxrs-spec-microprofile-openapi-annotations
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
generatorName: jaxrs-spec
outputDir: samples/server/petstore/jaxrs-spec-microprofile-openapi-annotations
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/spec
additionalProperties:
artifactId: jaxrs-spec-petstore-server
serializableModel: "true"
hideGenerationTimestamp: "true"
implicitHeadersRegex: (api_key|enum_header_string)
generateBuilders: "true"
useMicroProfileOpenAPIAnnotations: "true"
library: "quarkus"
useJakartaEe: "true"
dateLibrary: "java8-localdatetime"
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,14 @@ void generateApis(List<File> files, List<OperationsMap> allOperations, List<Mode
.filter(Objects::nonNull)
.filter(tag::equalsIgnoreCase)
.findFirst()
.ifPresent(tagName -> operation.put("operationTagName", tagName));
.ifPresent(tagName -> operation.put("operationTagName", config.escapeText(tagName)));
operation.put("operationTagDescription", "");
Optional.ofNullable(openAPI.getTags()).orElseGet(Collections::emptyList).stream()
.filter(t -> tag.equalsIgnoreCase(t.getName()))
.map(Tag::getDescription)
.filter(Objects::nonNull)
.findFirst()
.ifPresent(description -> operation.put("operationTagDescription", description));
.ifPresent(description -> operation.put("operationTagDescription", config.escapeText(description)));
Optional.ofNullable(config.additionalProperties().get("appVersion")).ifPresent(version -> operation.put("version", version));
operation.put("apiPackage", config.apiPackage());
operation.put("modelPackage", config.modelPackage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package {{invokerPackage}};

import {{javaxPackage}}.ws.rs.ApplicationPath;
import {{javaxPackage}}.ws.rs.core.Application;

{{#useMicroProfileOpenAPIAnnotations}}{{#openAPI}}{{#info}}@org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition(
{{#useMicroProfileOpenAPIAnnotations}}{{#openAPI}}{{#info}}
@org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition(
info = @org.eclipse.microprofile.openapi.annotations.info.Info(
title = "{{{title}}}", version="{{{version}}}", description="{{{description}}}"
{{#license}},license = @org.eclipse.microprofile.openapi.annotations.info.License(name = "{{{name}}}", url = "{{{url}}}"){{/license}}
{{#contact}},contact = @org.eclipse.microprofile.openapi.annotations.info.Contact(name = "{{{name}}}", email = "{{{email}}}"){{/contact}}
version="{{{appVersion}}}"
{{#appName}},title = "{{{.}}}"{{/appName}}
{{#appDescription}},description = "{{{.}}}"{{/appDescription}}
{{#license}},license = @org.eclipse.microprofile.openapi.annotations.info.License(name = "{{{licenseInfo}}}", url = "{{{licenseUrl}}}"){{/license}}
{{#contact}},contact = @org.eclipse.microprofile.openapi.annotations.info.Contact(name = "{{{infoName}}}", email = "{{{infoEmail}}}"){{/contact}}
)){{/info}}{{/openAPI}}{{/useMicroProfileOpenAPIAnnotations}}
@ApplicationPath(RestResourceRoot.APPLICATION_PATH)
public class RestApplication extends Application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {{javaxPackage}}.validation.Valid;{{/useBeanValidation}}
{{#useMicroProfileOpenAPIAnnotations}}@org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition(
info = @org.eclipse.microprofile.openapi.annotations.info.Info(
title = "{{{operationTagName}}}", version="{{{version}}}", description="{{{operationTagDescription}}}"{{#license}},
license = @org.eclipse.microprofile.openapi.annotations.info.License(name = "{{{name}}}", url = "{{{url}}}"){{/license}}{{#contact}},
license = @org.eclipse.microprofile.openapi.annotations.info.License(name = "{{{licenseInfo}}}", url = "{{{licenseUrl}}}"){{/license}}{{#contact}},
contact = @org.eclipse.microprofile.openapi.annotations.info.Contact(name = "{{{name}}}", email = "{{{email}}}"){{/contact}}
),
tags = @org.eclipse.microprofile.openapi.annotations.tags.Tag(name="{{{operationTagName}}}", description="{{{operationTagDescription}}}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<javax.ws.rs-version>2.1.1</javax.ws.rs-version>
<javax.annotation-api-version>1.3.2</javax.annotation-api-version>
{{/useJakartaEe}}
{{#useSwaggerAnnotations}}
<io.swagger.annotations.version>1.6.10</io.swagger.annotations.version>
{{/useSwaggerAnnotations}}
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -74,30 +77,38 @@
</dependency>
{{#useJakartaEe}}
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jakarta.ws.rs-version}</version>
<scope>provided</scope>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jakarta.ws.rs-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.annotation-api-version}</version>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.annotation-api-version}</version>
</dependency>
{{/useJakartaEe}}
{{^useJakartaEe}}
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs-version}</version>
<scope>provided</scope>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotation-api-version}</version>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotation-api-version}</version>
</dependency>
{{/useJakartaEe}}
{{#useSwaggerAnnotations}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${io.swagger.annotations.version}</version>
<scope>provided</scope>
</dependency>
{{/useSwaggerAnnotations}}
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{#description}}/**
* {{.}}
**/{{/description}}
{{#useSwaggerAnnotations}}{{#description}}@ApiModel(description = "{{{.}}}"){{/description}}{{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}}@org.eclipse.microprofile.openapi.annotations.media.Schema(title="{{title}}", description="{{description}}"){{/useMicroProfileOpenAPIAnnotations}}
{{#useSwaggerAnnotations}}{{#description}}@ApiModel(description = "{{{.}}}"){{/description}}{{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}}
@org.eclipse.microprofile.openapi.annotations.media.Schema({{#title}}title="{{{.}}}", {{/title}}{{#description}}description="{{{.}}}"{{/description}}{{^description}}description=""{{/description}}){{/useMicroProfileOpenAPIAnnotations}}
@JsonTypeName("{{name}}")
{{>generatedAnnotation}}{{>additionalModelTypeAnnotations}}
{{#vendorExtensions.x-class-extra-annotation}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.dockerignore
README.md
pom.xml
src/gen/java/org/openapitools/api/AnotherFakeApi.java
src/gen/java/org/openapitools/api/FakeApi.java
src/gen/java/org/openapitools/api/FakeClassnameTestApi.java
src/gen/java/org/openapitools/api/PetApi.java
src/gen/java/org/openapitools/api/RestApplication.java
src/gen/java/org/openapitools/api/RestResourceRoot.java
src/gen/java/org/openapitools/api/StoreApi.java
src/gen/java/org/openapitools/api/UserApi.java
src/gen/java/org/openapitools/model/AdditionalPropertiesAnyType.java
src/gen/java/org/openapitools/model/AdditionalPropertiesArray.java
src/gen/java/org/openapitools/model/AdditionalPropertiesBoolean.java
src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java
src/gen/java/org/openapitools/model/AdditionalPropertiesInteger.java
src/gen/java/org/openapitools/model/AdditionalPropertiesNumber.java
src/gen/java/org/openapitools/model/AdditionalPropertiesObject.java
src/gen/java/org/openapitools/model/AdditionalPropertiesString.java
src/gen/java/org/openapitools/model/Animal.java
src/gen/java/org/openapitools/model/ArrayOfArrayOfNumberOnly.java
src/gen/java/org/openapitools/model/ArrayOfNumberOnly.java
src/gen/java/org/openapitools/model/ArrayTest.java
src/gen/java/org/openapitools/model/BigCat.java
src/gen/java/org/openapitools/model/BigCatAllOf.java
src/gen/java/org/openapitools/model/Capitalization.java
src/gen/java/org/openapitools/model/Cat.java
src/gen/java/org/openapitools/model/CatAllOf.java
src/gen/java/org/openapitools/model/Category.java
src/gen/java/org/openapitools/model/ClassModel.java
src/gen/java/org/openapitools/model/Client.java
src/gen/java/org/openapitools/model/Dog.java
src/gen/java/org/openapitools/model/DogAllOf.java
src/gen/java/org/openapitools/model/EnumArrays.java
src/gen/java/org/openapitools/model/EnumClass.java
src/gen/java/org/openapitools/model/EnumTest.java
src/gen/java/org/openapitools/model/FileSchemaTestClass.java
src/gen/java/org/openapitools/model/FormatTest.java
src/gen/java/org/openapitools/model/HasOnlyReadOnly.java
src/gen/java/org/openapitools/model/MapTest.java
src/gen/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClass.java
src/gen/java/org/openapitools/model/Model200Response.java
src/gen/java/org/openapitools/model/ModelApiResponse.java
src/gen/java/org/openapitools/model/ModelFile.java
src/gen/java/org/openapitools/model/ModelList.java
src/gen/java/org/openapitools/model/ModelReturn.java
src/gen/java/org/openapitools/model/Name.java
src/gen/java/org/openapitools/model/NumberOnly.java
src/gen/java/org/openapitools/model/Order.java
src/gen/java/org/openapitools/model/OuterComposite.java
src/gen/java/org/openapitools/model/OuterEnum.java
src/gen/java/org/openapitools/model/Pet.java
src/gen/java/org/openapitools/model/ReadOnlyFirst.java
src/gen/java/org/openapitools/model/SpecialModelName.java
src/gen/java/org/openapitools/model/Tag.java
src/gen/java/org/openapitools/model/TypeHolderDefault.java
src/gen/java/org/openapitools/model/TypeHolderExample.java
src/gen/java/org/openapitools/model/User.java
src/gen/java/org/openapitools/model/XmlItem.java
src/main/docker/Dockerfile.jvm
src/main/docker/Dockerfile.native
src/main/openapi/openapi.yaml
src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.6.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# JAX-RS server with OpenAPI using Quarkus

## Overview
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using an
[OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.

This is an example of building a OpenAPI-enabled JAX-RS server.
This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework and
the [Eclipse-MicroProfile-OpenAPI](https://github.com/eclipse/microprofile-open-api) addition.

The pom file is configured to use [Quarkus](https://quarkus.io/) as application server.


To start the server in dev mode, run this maven command:

```bash
mvn compile quarkus:dev
```

You can then call your server endpoints under:

```
http://localhost:8080/
```

In dev-mode, you can open Swagger-UI at:

```
http://localhost:8080/swagger-ui/
```

Read more in the [Quarkus OpenAPI guide](https://quarkus.io/guides/openapi-swaggerui-guide).

Loading

0 comments on commit 7ff1431

Please sign in to comment.