diff --git a/.github/workflows/samples-jdk17.yaml b/.github/workflows/samples-jdk17.yaml index 4df8f468e36..e96bfc1ca29 100644 --- a/.github/workflows/samples-jdk17.yaml +++ b/.github/workflows/samples-jdk17.yaml @@ -9,6 +9,7 @@ on: - samples/client/petstore/spring-http-interface-reactive/** - samples/client/petstore/spring-http-interface/** - samples/client/petstore/java/webclient-jakarta/** + - samples/client/petstore/java/microprofile-rest-client-outer-enum/** # servers - samples/openapi3/server/petstore/springboot-3/** - samples/server/petstore/java-camel/** @@ -23,6 +24,7 @@ on: - samples/client/petstore/spring-http-interface-reactive/** - samples/client/petstore/spring-http-interface/** - samples/client/petstore/java/webclient-jakarta/** + - samples/client/petstore/java/microprofile-rest-client-outer-enum/** # servers - samples/openapi3/server/petstore/springboot-3/** - samples/server/petstore/java-camel/** @@ -43,6 +45,7 @@ jobs: - samples/client/petstore/spring-http-interface-reactive - samples/client/petstore/spring-http-interface - samples/client/petstore/java/webclient-jakarta + - samples/client/petstore/java/microprofile-rest-client-outer-enum # servers - samples/openapi3/server/petstore/springboot-3 - samples/server/petstore/java-camel/ diff --git a/bin/configs/java-microprofile-rest-client-outer-enum.yaml b/bin/configs/java-microprofile-rest-client-outer-enum.yaml new file mode 100644 index 00000000000..c5d0466e4f5 --- /dev/null +++ b/bin/configs/java-microprofile-rest-client-outer-enum.yaml @@ -0,0 +1,8 @@ +generatorName: java +outputDir: samples/client/petstore/java/microprofile-rest-client-outer-enum +library: microprofile +inputSpec: modules/openapi-generator/src/test/resources/3_0/outerEnum.yaml +templateDir: modules/openapi-generator/src/main/resources/Java +additionalProperties: + artifactId: microprofile-rest-client + configKeyFromClassName: true diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/enumOuterClass.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/enumOuterClass.mustache index 0d9f7886f8d..2539064d171 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/enumOuterClass.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/enumOuterClass.mustache @@ -9,6 +9,10 @@ import java.net.URI; /** * {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}} */ +{{#jsonb}} +@JsonbTypeSerializer({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Serializer.class) +@JsonbTypeDeserializer({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Deserializer.class) +{{/jsonb}} {{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { {{#gson}} {{#allowableValues}}{{#enumVars}} @@ -36,6 +40,22 @@ import java.net.URI; return String.valueOf(value); } +{{#jsonb}} + public static final class Deserializer implements JsonbDeserializer<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> { + @Override + public {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { + return fromValue(parser.getString()); + } + } + + public static final class Serializer implements JsonbSerializer<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> { + @Override + public void serialize({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) { + generator.write(obj.value{{#isUri}}.toASCIIString(){{/isUri}}); + } + } + +{{/jsonb}} {{#jackson}} @JsonCreator {{/jackson}} @@ -47,5 +67,4 @@ import java.net.URI; } {{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}} } - } diff --git a/modules/openapi-generator/src/test/resources/3_0/outerEnum.yaml b/modules/openapi-generator/src/test/resources/3_0/outerEnum.yaml new file mode 100644 index 00000000000..e0bd2f31fca --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/outerEnum.yaml @@ -0,0 +1,68 @@ +openapi: 3.0.0 +info: + title: Petstore API + description: API for managing pets in a pet store + version: 1.0.0 +paths: + /dogs: + get: + summary: List all dogs + operationId: listDogs + responses: + '200': + description: A list of dogs + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Dog' + /cats: + get: + summary: List all cats + operationId: listCats + responses: + '200': + description: A list of cats + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Cat' +components: + schemas: + Dog: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + status: + $ref: '#/components/schemas/Status' + required: + - id + - name + - status + Cat: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + status: + $ref: '#/components/schemas/Status' + required: + - id + - name + - status + Status: + type: string + enum: + - available + - pending + - sold diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator-ignore b/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator-ignore @@ -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 diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator/FILES b/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator/FILES new file mode 100644 index 00000000000..697576c5e2f --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator/FILES @@ -0,0 +1,12 @@ +README.md +docs/Cat.md +docs/DefaultApi.md +docs/Dog.md +docs/Status.md +pom.xml +src/main/java/org/openapitools/client/api/ApiException.java +src/main/java/org/openapitools/client/api/ApiExceptionMapper.java +src/main/java/org/openapitools/client/api/DefaultApi.java +src/main/java/org/openapitools/client/model/Cat.java +src/main/java/org/openapitools/client/model/Dog.java +src/main/java/org/openapitools/client/model/Status.java diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator/VERSION b/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator/VERSION new file mode 100644 index 00000000000..6116b14d2c5 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.8.0-SNAPSHOT diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/README.md b/samples/client/petstore/java/microprofile-rest-client-outer-enum/README.md new file mode 100644 index 00000000000..310d4f98793 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/README.md @@ -0,0 +1,9 @@ +# Petstore API - MicroProfile Rest Client & MicroProfile Server + +API for managing pets in a pet store + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. +[MicroProfile Rest Client](https://github.com/eclipse/microprofile-rest-client) is a type-safe way of calling +REST services. The generated client contains an interface which acts as the client, you can inject it into dependent classes. + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Cat.md b/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Cat.md new file mode 100644 index 00000000000..45cd637aca0 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Cat.md @@ -0,0 +1,15 @@ + + +# Cat + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +|**id** | **Long** | | | +|**name** | **String** | | | +|**status** | **Status** | | | + + + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/DefaultApi.md b/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/DefaultApi.md new file mode 100644 index 00000000000..18e1a667f22 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/DefaultApi.md @@ -0,0 +1,130 @@ +# DefaultApi + +All URIs are relative to *http://localhost* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**listCats**](DefaultApi.md#listCats) | **GET** /cats | List all cats | +| [**listDogs**](DefaultApi.md#listDogs) | **GET** /dogs | List all dogs | + + + +## listCats + +> List<Cat> listCats() + +List all cats + +### Example + +```java +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.Configuration; +import org.openapitools.client.models.*; +import org.openapitools.client.api.DefaultApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://localhost"); + + DefaultApi apiInstance = new DefaultApi(defaultClient); + try { + List result = apiInstance.listCats(); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling DefaultApi#listCats"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**List<Cat>**](Cat.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | A list of cats | - | + + +## listDogs + +> List<Dog> listDogs() + +List all dogs + +### Example + +```java +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.Configuration; +import org.openapitools.client.models.*; +import org.openapitools.client.api.DefaultApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://localhost"); + + DefaultApi apiInstance = new DefaultApi(defaultClient); + try { + List result = apiInstance.listDogs(); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling DefaultApi#listDogs"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**List<Dog>**](Dog.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | A list of dogs | - | + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Dog.md b/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Dog.md new file mode 100644 index 00000000000..150f5c27eb2 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Dog.md @@ -0,0 +1,15 @@ + + +# Dog + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +|**id** | **Long** | | | +|**name** | **String** | | | +|**status** | **Status** | | | + + + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Status.md b/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Status.md new file mode 100644 index 00000000000..21c77693273 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/docs/Status.md @@ -0,0 +1,15 @@ + + +# Status + +## Enum + + +* `AVAILABLE` (value: `"available"`) + +* `PENDING` (value: `"pending"`) + +* `SOLD` (value: `"sold"`) + + + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/pom.xml b/samples/client/petstore/java/microprofile-rest-client-outer-enum/pom.xml new file mode 100644 index 00000000000..8d3d986ef9f --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/pom.xml @@ -0,0 +1,177 @@ + + 4.0.0 + org.openapitools + microprofile-rest-client + jar + microprofile-rest-client + API for managing pets in a pet store + 1.0.0 + + src/main/java + + + org.jboss.jandex + jandex-maven-plugin + ${jandex.maven.plugin.version} + + + make-index + + jandex + + + + + + maven-failsafe-plugin + ${maven.failsafe.plugin.version} + + + + integration-test + verify + + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build.helper.maven.plugin.version} + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + + org.eclipse.microprofile.rest.client + microprofile-rest-client-api + ${microprofile.rest.client.api.version} + + + + + jakarta.ws.rs + jakarta.ws.rs-api + ${jakarta.ws.rs.version} + provided + + + + io.smallrye + smallrye-rest-client + ${smallrye.rest.client.version} + test + + + + io.smallrye + smallrye-config + ${smallrye.config.version} + test + + + org.apache.cxf + cxf-rt-rs-extension-providers + ${cxf.rt.rs.extension.providers.version} + + + jakarta.json.bind + jakarta.json.bind-api + ${jakarta.json.bind.version} + + + jakarta.json + jakarta.json-api + ${jakarta.json.version} + + + jakarta.xml.bind + jakarta.xml.bind-api + ${jakarta.xml.bind.version} + + + com.sun.xml.bind + jaxb-core + ${jaxb.core.version} + + + com.sun.xml.bind + jaxb-impl + ${jaxb.impl.version} + + + jakarta.activation + jakarta.activation-api + ${jakarta.activation.version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.jaxrs.version} + + + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation.version} + provided + + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + 1.8 + ${java.version} + ${java.version} + 1.5.18 + 9.2.9.v20150224 + 5.10.2 + 1.4.14 + 3.2.7 + 2.17.1 + 1.2.2 + 1.3.5 + 1.0.2 + 1.1.6 + 2.1.6 + 2.3.3 + 2.0 + 1.2.1 + 1.3.5 + 3.2.6 + 2.2.11 + 2.2.11 + 5.2.2.Final + 1.1.0 + 2.6 + 1.9.1 + UTF-8 + + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/ApiException.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/ApiException.java new file mode 100644 index 00000000000..16976e256ce --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/ApiException.java @@ -0,0 +1,34 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.api; + +import javax.ws.rs.core.Response; + +public class ApiException extends Exception { + + private static final long serialVersionUID = 1L; + private Response response; + + public ApiException() { + super(); + } + + public ApiException(Response response) { + super("Api response has status code " + response.getStatus()); + this.response = response; + } + + public Response getResponse() { + return this.response; + } +} diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/ApiExceptionMapper.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/ApiExceptionMapper.java new file mode 100644 index 00000000000..60b8f915a89 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/ApiExceptionMapper.java @@ -0,0 +1,33 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.api; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper; + +@Provider +public class ApiExceptionMapper + implements ResponseExceptionMapper { + + @Override + public boolean handles(int status, MultivaluedMap headers) { + return status >= 400; + } + + @Override + public ApiException toThrowable(Response response) { + return new ApiException(response); + } +} diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/DefaultApi.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/DefaultApi.java new file mode 100644 index 00000000000..247b26ac6c1 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/api/DefaultApi.java @@ -0,0 +1,61 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.api; + +import org.openapitools.client.model.Cat; +import org.openapitools.client.model.Dog; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.MediaType; +import org.apache.cxf.jaxrs.ext.multipart.*; + + +import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +/** + * Petstore API + * + *

API for managing pets in a pet store + * + */ + +@RegisterRestClient(configKey="default-api") +@RegisterProvider(ApiExceptionMapper.class) +@Path("") +public interface DefaultApi { + + /** + * List all cats + * + */ + @GET + @Path("/cats") + @Produces({ "application/json" }) + List listCats() throws ApiException, ProcessingException; + + /** + * List all dogs + * + */ + @GET + @Path("/dogs") + @Produces({ "application/json" }) + List listDogs() throws ApiException, ProcessingException; +} diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Cat.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Cat.java new file mode 100644 index 00000000000..6d04b341acc --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Cat.java @@ -0,0 +1,126 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.model; + +import org.openapitools.client.model.Status; +import java.lang.reflect.Type; +import javax.json.bind.annotation.JsonbTypeDeserializer; +import javax.json.bind.annotation.JsonbTypeSerializer; +import javax.json.bind.serializer.DeserializationContext; +import javax.json.bind.serializer.JsonbDeserializer; +import javax.json.bind.serializer.JsonbSerializer; +import javax.json.bind.serializer.SerializationContext; +import javax.json.stream.JsonGenerator; +import javax.json.stream.JsonParser; +import javax.json.bind.annotation.JsonbProperty; + + +public class Cat { + + @JsonbProperty("id") + private Long id; + + @JsonbProperty("name") + private String name; + + @JsonbProperty("status") + private Status status; + + /** + * Get id + * @return id + **/ + public Long getId() { + return id; + } + + /** + * Set id + */ + public void setId(Long id) { + this.id = id; + } + + public Cat id(Long id) { + this.id = id; + return this; + } + + /** + * Get name + * @return name + **/ + public String getName() { + return name; + } + + /** + * Set name + */ + public void setName(String name) { + this.name = name; + } + + public Cat name(String name) { + this.name = name; + return this; + } + + /** + * Get status + * @return status + **/ + public Status getStatus() { + return status; + } + + /** + * Set status + */ + public void setStatus(Status status) { + this.status = status; + } + + public Cat status(Status status) { + this.status = status; + return this; + } + + + /** + * Create a string representation of this pojo. + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Cat {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Dog.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Dog.java new file mode 100644 index 00000000000..ae84137c036 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Dog.java @@ -0,0 +1,126 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.model; + +import org.openapitools.client.model.Status; +import java.lang.reflect.Type; +import javax.json.bind.annotation.JsonbTypeDeserializer; +import javax.json.bind.annotation.JsonbTypeSerializer; +import javax.json.bind.serializer.DeserializationContext; +import javax.json.bind.serializer.JsonbDeserializer; +import javax.json.bind.serializer.JsonbSerializer; +import javax.json.bind.serializer.SerializationContext; +import javax.json.stream.JsonGenerator; +import javax.json.stream.JsonParser; +import javax.json.bind.annotation.JsonbProperty; + + +public class Dog { + + @JsonbProperty("id") + private Long id; + + @JsonbProperty("name") + private String name; + + @JsonbProperty("status") + private Status status; + + /** + * Get id + * @return id + **/ + public Long getId() { + return id; + } + + /** + * Set id + */ + public void setId(Long id) { + this.id = id; + } + + public Dog id(Long id) { + this.id = id; + return this; + } + + /** + * Get name + * @return name + **/ + public String getName() { + return name; + } + + /** + * Set name + */ + public void setName(String name) { + this.name = name; + } + + public Dog name(String name) { + this.name = name; + return this; + } + + /** + * Get status + * @return status + **/ + public Status getStatus() { + return status; + } + + /** + * Set status + */ + public void setStatus(Status status) { + this.status = status; + } + + public Dog status(Status status) { + this.status = status; + return this; + } + + + /** + * Create a string representation of this pojo. + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Dog {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Status.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Status.java new file mode 100644 index 00000000000..ec5a12d0b53 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/main/java/org/openapitools/client/model/Status.java @@ -0,0 +1,74 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.model; + +import java.lang.reflect.Type; +import javax.json.bind.annotation.JsonbTypeDeserializer; +import javax.json.bind.annotation.JsonbTypeSerializer; +import javax.json.bind.serializer.DeserializationContext; +import javax.json.bind.serializer.JsonbDeserializer; +import javax.json.bind.serializer.JsonbSerializer; +import javax.json.bind.serializer.SerializationContext; +import javax.json.stream.JsonGenerator; +import javax.json.stream.JsonParser; +import javax.json.bind.annotation.JsonbProperty; + + +/** + * Gets or Sets Status + */ +@JsonbTypeSerializer(Status.Serializer.class) +@JsonbTypeDeserializer(Status.Deserializer.class) +public enum Status { + + AVAILABLE("available"), + + PENDING("pending"), + + SOLD("sold"); + + private String value; + + Status(String value) { + this.value = value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static final class Deserializer implements JsonbDeserializer { + @Override + public Status deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { + return fromValue(parser.getString()); + } + } + + public static final class Serializer implements JsonbSerializer { + @Override + public void serialize(Status obj, JsonGenerator generator, SerializationContext ctx) { + generator.write(obj.value); + } + } + + public static Status fromValue(String text) { + for (Status b : Status.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + text + "'"); + } +} + diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/api/DefaultApiTest.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/api/DefaultApiTest.java new file mode 100644 index 00000000000..01185c52a5d --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/api/DefaultApiTest.java @@ -0,0 +1,81 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.api; + +import org.openapitools.client.model.Cat; +import org.openapitools.client.model.Dog; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; + +import org.eclipse.microprofile.rest.client.RestClientBuilder; + +import java.net.URL; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Petstore API Test + * + * API tests for DefaultApi + */ +public class DefaultApiTest { + + private DefaultApi client; + private String baseUrl = "http://localhost:9080"; + + @BeforeEach + public void setup() throws MalformedURLException { + client = RestClientBuilder.newBuilder() + .baseUrl(new URL(baseUrl)) + .register(ApiException.class) + .build(DefaultApi.class); + } + + + /** + * List all cats + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void listCatsTest() { + // TODO: test validations + //List response = api.listCats(); + //Assertions.assertNotNull(response); + + + } + + /** + * List all dogs + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void listDogsTest() { + // TODO: test validations + //List response = api.listDogs(); + //Assertions.assertNotNull(response); + + + } + +} diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/CatTest.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/CatTest.java new file mode 100644 index 00000000000..4a9f33402c2 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/CatTest.java @@ -0,0 +1,59 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import org.openapitools.client.model.Status; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for Cat + */ +class CatTest { + private final Cat model = new Cat(); + + /** + * Model tests for Cat + */ + @Test + void testCat() { + // TODO: test Cat + } + + /** + * Test the property 'id' + */ + @Test + void idTest() { + // TODO: test id + } + + /** + * Test the property 'name' + */ + @Test + void nameTest() { + // TODO: test name + } + + /** + * Test the property 'status' + */ + @Test + void statusTest() { + // TODO: test status + } + +} diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/DogTest.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/DogTest.java new file mode 100644 index 00000000000..fcab257e074 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/DogTest.java @@ -0,0 +1,59 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import org.openapitools.client.model.Status; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for Dog + */ +class DogTest { + private final Dog model = new Dog(); + + /** + * Model tests for Dog + */ + @Test + void testDog() { + // TODO: test Dog + } + + /** + * Test the property 'id' + */ + @Test + void idTest() { + // TODO: test id + } + + /** + * Test the property 'name' + */ + @Test + void nameTest() { + // TODO: test name + } + + /** + * Test the property 'status' + */ + @Test + void statusTest() { + // TODO: test status + } + +} diff --git a/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/StatusTest.java b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/StatusTest.java new file mode 100644 index 00000000000..7838492b053 --- /dev/null +++ b/samples/client/petstore/java/microprofile-rest-client-outer-enum/src/test/java/org/openapitools/client/model/StatusTest.java @@ -0,0 +1,32 @@ +/** + * Petstore API + * API for managing pets in a pet store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for Status + */ +class StatusTest { + /** + * Model tests for Status + */ + @Test + void testStatus() { + // TODO: test Status + } + +}