diff --git a/.github/workflows/samples-java-client-echo-api-jdk11.yaml b/.github/workflows/samples-java-client-echo-api-jdk11.yaml index b165d677d5c..12813b63500 100644 --- a/.github/workflows/samples-java-client-echo-api-jdk11.yaml +++ b/.github/workflows/samples-java-client-echo-api-jdk11.yaml @@ -18,6 +18,7 @@ jobs: # clients - samples/client/echo_api/java/apache-httpclient - samples/client/echo_api/java/native + - samples/client/echo_api/java/feign-gson steps: - uses: actions/checkout@v3 - uses: actions/setup-java@v3 diff --git a/bin/configs/java-feign-gson-echo-api.yaml b/bin/configs/java-feign-gson-echo-api.yaml new file mode 100644 index 00000000000..d765eb41c02 --- /dev/null +++ b/bin/configs/java-feign-gson-echo-api.yaml @@ -0,0 +1,9 @@ +generatorName: java +outputDir: samples/client/echo_api/java/feign-gson +library: feign +inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml +templateDir: modules/openapi-generator/src/main/resources/Java +additionalProperties: + serializationLibrary: gson + artifactId: echo-api-feign-json + hideGenerationTimestamp: "true" diff --git a/docs/generators/java.md b/docs/generators/java.md index 43a723d2ed5..89cc2f2c33e 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -56,7 +56,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null| |invokerPackage|root package for generated code| |org.openapitools.client| |legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|
**true**
The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
**false**
The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true| -|library|library template (sub-template) to use|
**jersey1**
HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey3' or other HTTP libraries instead.
**jersey2**
HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x
**jersey3**
HTTP client: Jersey client 3.x. JSON processing: Jackson 2.x
**feign**
HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x.
**okhttp-gson**
[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
**retrofit2**
HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)
**resttemplate**
HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x
**webclient**
HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x
**resteasy**
HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.9.x
**vertx**
HTTP client: VertX client 3.x. JSON processing: Jackson 2.9.x
**google-api-client**
HTTP client: Google API client 1.x. JSON processing: Jackson 2.9.x
**rest-assured**
HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.10.x. Only for Java 8
**native**
HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+
**microprofile**
HTTP client: Microprofile client 1.x. JSON processing: JSON-B
**apache-httpclient**
HTTP client: Apache httpclient 4.x
|okhttp-gson| +|library|library template (sub-template) to use|
**jersey1**
HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey3' or other HTTP libraries instead.
**jersey2**
HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x
**jersey3**
HTTP client: Jersey client 3.x. JSON processing: Jackson 2.x
**feign**
HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x. or Gson 2.x
**okhttp-gson**
[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
**retrofit2**
HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)
**resttemplate**
HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x
**webclient**
HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x
**resteasy**
HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.9.x
**vertx**
HTTP client: VertX client 3.x. JSON processing: Jackson 2.9.x
**google-api-client**
HTTP client: Google API client 1.x. JSON processing: Jackson 2.9.x
**rest-assured**
HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.10.x. Only for Java 8
**native**
HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+
**microprofile**
HTTP client: Microprofile client 1.x. JSON processing: JSON-B
**apache-httpclient**
HTTP client: Apache httpclient 4.x
|okhttp-gson| |licenseName|The name of the license| |Unlicense| |licenseUrl|The URL of the license| |http://unlicense.org| |microprofileFramework|Framework for microprofile. Possible values "kumuluzee"| |null| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index fba5de02c16..33498a66bb0 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -211,7 +211,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen supportedLibraries.put(JERSEY1, "HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey3' or other HTTP libraries instead."); supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x"); supportedLibraries.put(JERSEY3, "HTTP client: Jersey client 3.x. JSON processing: Jackson 2.x"); - supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x."); + supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x. or Gson 2.x"); supportedLibraries.put(OKHTTP_GSON, "[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'."); supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)"); supportedLibraries.put(RESTTEMPLATE, "HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x"); @@ -485,7 +485,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen apiDocTemplateFiles.remove("api_doc.mustache"); //Templates to decode response headers supportingFiles.add(new SupportingFile("model/ApiResponse.mustache", modelsFolder, "ApiResponse.java")); - supportingFiles.add(new SupportingFile("ApiResponseDecoder.mustache", invokerFolder, "ApiResponseDecoder.java")); // TODO remove "file" from reserved word list as feign client doesn't support using `baseName` // as the parameter name yet @@ -503,8 +502,14 @@ public class JavaClientCodegen extends AbstractJavaCodegen } if (FEIGN.equals(getLibrary())) { - forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON); - supportingFiles.add(new SupportingFile("ParamExpander.mustache", invokerFolder, "ParamExpander.java")); + if (getSerializationLibrary() == null) { + LOGGER.info("No serializationLibrary configured, using '{}' as fallback", SERIALIZATION_LIBRARY_JACKSON); + setSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON); + } + if (SERIALIZATION_LIBRARY_JACKSON.equals(getSerializationLibrary())) { + supportingFiles.add(new SupportingFile("ApiResponseDecoder.mustache", invokerFolder, "ApiResponseDecoder.java")); + supportingFiles.add(new SupportingFile("ParamExpander.mustache", invokerFolder, "ParamExpander.java")); + } supportingFiles.add(new SupportingFile("EncodingUtils.mustache", invokerFolder, "EncodingUtils.java")); supportingFiles.add(new SupportingFile("auth/DefaultApi20Impl.mustache", authFolder, "DefaultApi20Impl.java")); } else if (OKHTTP_GSON.equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) { diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache index cc9599940f9..74ab1d02756 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache @@ -5,29 +5,40 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +{{#jackson}} import feign.okhttp.OkHttpClient; - import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; {{#openApiNullable}} import org.openapitools.jackson.nullable.JsonNullableModule; {{/openApiNullable}} +{{/jackson}} {{#joda}} import com.fasterxml.jackson.datatype.joda.JodaModule; {{/joda}} +{{#jackson}} import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +{{/jackson}} import feign.Feign; import feign.RequestInterceptor; import feign.form.FormEncoder; +{{#jackson}} import feign.jackson.JacksonDecoder; import feign.jackson.JacksonEncoder; +{{/jackson}} +{{#gson}} +import feign.gson.GsonDecoder; +import feign.gson.GsonEncoder; +{{/gson}} import feign.slf4j.Slf4jLogger; import {{invokerPackage}}.auth.HttpBasicAuth; import {{invokerPackage}}.auth.HttpBearerAuth; import {{invokerPackage}}.auth.ApiKeyAuth; +{{#jackson}} import {{invokerPackage}}.ApiResponseDecoder; +{{/jackson}} {{#hasOAuthMethods}} import {{invokerPackage}}.auth.ApiErrorDecoder; @@ -45,14 +56,17 @@ public class ApiClient { public interface Api {} + {{#jackson}} protected ObjectMapper objectMapper; + {{/jackson}} private String basePath = "{{{basePath}}}"; private Map apiAuthorizations; private Feign.Builder feignBuilder; public ApiClient() { - objectMapper = createObjectMapper(); apiAuthorizations = new LinkedHashMap(); + {{#jackson}} + objectMapper = createObjectMapper(); feignBuilder = Feign.builder() .client(new OkHttpClient()) .encoder(new FormEncoder(new JacksonEncoder(objectMapper))) @@ -62,6 +76,17 @@ public class ApiClient { .retryer(new Retryer.Default(0, 0, 2)) {{/hasOAuthMethods}} .logger(new Slf4jLogger()); + {{/jackson}} + {{#gson}} + feignBuilder = Feign.builder() + .encoder(new FormEncoder(new GsonEncoder())) + .decoder(new GsonDecoder()) + {{#hasOAuthMethods}} + .errorDecoder(new ApiErrorDecoder()) + .retryer(new Retryer.Default(0, 0, 2)) + {{/hasOAuthMethods}} + .logger(new Slf4jLogger()); + {{/gson}} } public ApiClient(String[] authNames) { @@ -140,6 +165,7 @@ public class ApiClient { return this; } + {{#jackson}} private ObjectMapper createObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); @@ -158,6 +184,7 @@ public class ApiClient { {{/openApiNullable}} return objectMapper; } + {{/jackson}} {{#hasOAuthMethods}} private RequestInterceptor buildOauthRequestInterceptor(OAuthFlow flow, String authorizationUrl, String tokenUrl, String scopes) { @@ -172,6 +199,8 @@ public class ApiClient { } {{/hasOAuthMethods}} + + {{#jackson}} public ObjectMapper getObjectMapper(){ return objectMapper; } @@ -179,6 +208,7 @@ public class ApiClient { public void setObjectMapper(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } + {{/jackson}} /** * Creates a feign client for given API interface. diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache index 5a122b32118..be8b951bb79 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache @@ -234,11 +234,20 @@ feign-core ${feign-version} + {{#jackson}} io.github.openfeign feign-jackson ${feign-version} + {{/jackson}} + {{#gson}} + + io.github.openfeign + feign-gson + ${feign-version} + + {{/gson}} io.github.openfeign feign-slf4j @@ -255,6 +264,7 @@ ${feign-version} + {{#jackson}} com.fasterxml.jackson.core @@ -271,6 +281,14 @@ jackson-databind ${jackson-databind-version} + {{/jackson}} + {{#gson}} + + com.google.code.gson + gson + ${gson-version} + + {{/gson}} {{#openApiNullable}} org.openapitools @@ -293,11 +311,13 @@ ${jackson-version} {{/joda}} + {{#jackson}} com.fasterxml.jackson.datatype jackson-datatype-jsr310 ${jackson-version} + {{/jackson}} com.github.scribejava scribejava-core @@ -356,7 +376,12 @@ 1.6.6 10.11 3.8.0 + {{#jackson}} 2.13.4 + {{/jackson}} + {{#gson}} + 2.8.6 + {{/gson}} {{#openApiNullable}} 0.2.4 {{/openApiNullable}} diff --git a/samples/client/echo_api/java/feign-gson/.github/workflows/maven.yml b/samples/client/echo_api/java/feign-gson/.github/workflows/maven.yml new file mode 100644 index 00000000000..aa75c116424 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/.github/workflows/maven.yml @@ -0,0 +1,30 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven +# +# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech) + +name: Java CI with Maven + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + build: + name: Build Echo Server API + runs-on: ubuntu-latest + strategy: + matrix: + java: [ '8' ] + steps: + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --no-transfer-progress --file pom.xml diff --git a/samples/client/echo_api/java/feign-gson/.gitignore b/samples/client/echo_api/java/feign-gson/.gitignore new file mode 100644 index 00000000000..a530464afa1 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/.gitignore @@ -0,0 +1,21 @@ +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# exclude jar for gradle wrapper +!gradle/wrapper/*.jar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# build files +**/target +target +.gradle +build diff --git a/samples/client/echo_api/java/feign-gson/.openapi-generator-ignore b/samples/client/echo_api/java/feign-gson/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/.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/echo_api/java/feign-gson/.openapi-generator/FILES b/samples/client/echo_api/java/feign-gson/.openapi-generator/FILES new file mode 100644 index 00000000000..abf25d9240e --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/.openapi-generator/FILES @@ -0,0 +1,33 @@ +.github/workflows/maven.yml +.gitignore +.travis.yml +README.md +api/openapi.yaml +build.gradle +build.sbt +git_push.sh +gradle.properties +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +pom.xml +settings.gradle +src/main/AndroidManifest.xml +src/main/java/org/openapitools/client/ApiClient.java +src/main/java/org/openapitools/client/EncodingUtils.java +src/main/java/org/openapitools/client/ServerConfiguration.java +src/main/java/org/openapitools/client/ServerVariable.java +src/main/java/org/openapitools/client/StringUtil.java +src/main/java/org/openapitools/client/api/BodyApi.java +src/main/java/org/openapitools/client/api/PathApi.java +src/main/java/org/openapitools/client/api/QueryApi.java +src/main/java/org/openapitools/client/auth/ApiKeyAuth.java +src/main/java/org/openapitools/client/auth/DefaultApi20Impl.java +src/main/java/org/openapitools/client/auth/HttpBasicAuth.java +src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +src/main/java/org/openapitools/client/model/ApiResponse.java +src/main/java/org/openapitools/client/model/Category.java +src/main/java/org/openapitools/client/model/Pet.java +src/main/java/org/openapitools/client/model/Tag.java +src/main/java/org/openapitools/client/model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.java diff --git a/samples/client/echo_api/java/feign-gson/.openapi-generator/VERSION b/samples/client/echo_api/java/feign-gson/.openapi-generator/VERSION new file mode 100644 index 00000000000..d6b4ec4aa78 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/echo_api/java/feign-gson/.travis.yml b/samples/client/echo_api/java/feign-gson/.travis.yml new file mode 100644 index 00000000000..1b6741c083c --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/.travis.yml @@ -0,0 +1,22 @@ +# +# Generated by OpenAPI Generator: https://openapi-generator.tech +# +# Ref: https://docs.travis-ci.com/user/languages/java/ +# +language: java +jdk: + - openjdk12 + - openjdk11 + - openjdk10 + - openjdk9 + - openjdk8 +before_install: + # ensure gradlew has proper permission + - chmod a+x ./gradlew +script: + # test using maven + #- mvn test + # test using gradle + - gradle test + # test using sbt + # - sbt test diff --git a/samples/client/echo_api/java/feign-gson/README.md b/samples/client/echo_api/java/feign-gson/README.md new file mode 100644 index 00000000000..8ef33276017 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/README.md @@ -0,0 +1,77 @@ +# echo-api-feign-json + +## Requirements + +Building the API client library requires [Maven](https://maven.apache.org/) to be installed. + +## Installation & Usage + +To install the API client library to your local Maven repository, simply execute: + +```shell +mvn install +``` + +To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: + +```shell +mvn deploy +``` + +Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information. + +After the client library is installed/deployed, you can use it in your Maven project by adding the following to your *pom.xml*: + +```xml + + org.openapitools + echo-api-feign-json + 0.1.0 + compile + + +``` + +And to use the api you can follow the examples bellow: + +```java + + //Set bearer token manually + ApiClient apiClient = new ApiClient("petstore_auth_client"); + apiClient.setBasePath("https://localhost:8243/petstore/1/"); + apiClient.setAccessToken("TOKEN", 10000); + + //Use api key + ApiClient apiClient = new ApiClient("api_key", "API KEY"); + apiClient.setBasePath("https://localhost:8243/petstore/1/"); + + //Use http basic authentication + ApiClient apiClient = new ApiClient("basicAuth"); + apiClient.setBasePath("https://localhost:8243/petstore/1/"); + apiClient.setCredentials("username", "password"); + + //Oauth password + ApiClient apiClient = new ApiClient("oauth_password"); + apiClient.setBasePath("https://localhost:8243/petstore/1/"); + apiClient.setOauthPassword("username", "password", "client_id", "client_secret"); + + //Oauth client credentials flow + ApiClient apiClient = new ApiClient("oauth_client_credentials"); + apiClient.setBasePath("https://localhost:8243/petstore/1/"); + apiClient.setClientCredentials("client_id", "client_secret"); + + PetApi petApi = apiClient.buildClient(PetApi.class); + Pet petById = petApi.getPetById(12345L); + + System.out.println(petById); + } +``` + +## Recommendation + +It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. + +## Author + +team@openapitools.org + diff --git a/samples/client/echo_api/java/feign-gson/api/openapi.yaml b/samples/client/echo_api/java/feign-gson/api/openapi.yaml new file mode 100644 index 00000000000..4dd00e16318 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/api/openapi.yaml @@ -0,0 +1,242 @@ +openapi: 3.0.3 +info: + contact: + email: team@openapitools.org + description: Echo Server API + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + title: Echo Server API + version: 0.1.0 +servers: +- url: http://localhost:3000/ +paths: + /path/string/{path_string}/integer/{path_integer}: + get: + description: Test path parameter(s) + operationId: "tests/path/string/{path_string}/integer/{path_integer}" + parameters: + - explode: false + in: path + name: path_string + required: true + schema: + type: string + style: simple + - explode: false + in: path + name: path_integer + required: true + schema: + type: integer + style: simple + responses: + "200": + content: + text/plain: + schema: + type: string + description: Successful operation + summary: Test path parameter(s) + tags: + - path + x-accepts: text/plain + /query/integer/boolean/string: + get: + description: Test query parameter(s) + operationId: test/query/integer/boolean/string + parameters: + - explode: true + in: query + name: integer_query + required: false + schema: + type: integer + style: form + - explode: true + in: query + name: boolean_query + required: false + schema: + type: boolean + style: form + - explode: true + in: query + name: string_query + required: false + schema: + type: string + style: form + responses: + "200": + content: + text/plain: + schema: + type: string + description: Successful operation + summary: Test query parameter(s) + tags: + - query + x-accepts: text/plain + /query/style_form/explode_true/array_string: + get: + description: Test query parameter(s) + operationId: test/query/style_form/explode_true/array_string + parameters: + - explode: true + in: query + name: query_object + required: false + schema: + $ref: '#/components/schemas/test_query_style_form_explode_true_array_string_query_object_parameter' + style: form + responses: + "200": + content: + text/plain: + schema: + type: string + description: Successful operation + summary: Test query parameter(s) + tags: + - query + x-accepts: text/plain + /query/style_form/explode_true/object: + get: + description: Test query parameter(s) + operationId: test/query/style_form/explode_true/object + parameters: + - explode: true + in: query + name: query_object + required: false + schema: + $ref: '#/components/schemas/Pet' + style: form + responses: + "200": + content: + text/plain: + schema: + type: string + description: Successful operation + summary: Test query parameter(s) + tags: + - query + x-accepts: text/plain + /echo/body/Pet: + post: + description: Test body parameter(s) + operationId: test/echo/body/Pet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Successful operation + summary: Test body parameter(s) + tags: + - body + x-content-type: application/json + x-accepts: application/json +components: + requestBodies: + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + schemas: + Category: + example: + name: Dogs + id: 1 + properties: + id: + example: 1 + format: int64 + type: integer + name: + example: Dogs + type: string + type: object + xml: + name: category + Tag: + example: + name: name + id: 0 + properties: + id: + format: int64 + type: integer + name: + type: string + type: object + xml: + name: tag + Pet: + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 10 + category: + name: Dogs + id: 1 + tags: + - name: name + id: 0 + - name: name + id: 0 + status: available + properties: + id: + example: 10 + format: int64 + type: integer + name: + example: doggie + type: string + category: + $ref: '#/components/schemas/Category' + photoUrls: + items: + type: string + xml: + name: photoUrl + type: array + xml: + wrapped: true + tags: + items: + $ref: '#/components/schemas/Tag' + type: array + xml: + wrapped: true + status: + description: pet status in the store + enum: + - available + - pending + - sold + type: string + required: + - name + - photoUrls + type: object + xml: + name: pet + test_query_style_form_explode_true_array_string_query_object_parameter: + properties: + values: + items: + type: string + type: array + type: object + diff --git a/samples/client/echo_api/java/feign-gson/build.gradle b/samples/client/echo_api/java/feign-gson/build.gradle new file mode 100644 index 00000000000..81c595e5349 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/build.gradle @@ -0,0 +1,139 @@ +apply plugin: 'idea' +apply plugin: 'eclipse' + +group = 'org.openapitools' +version = '0.1.0' + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.3.+' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + } +} + +repositories { + mavenCentral() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 25 + buildToolsVersion '25.0.2' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 25 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + + dependencies { + provided "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version" + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven-publish' + + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + + publishing { + publications { + maven(MavenPublication) { + artifactId = 'echo-api-feign-json' + from components.java + } + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +test { + useJUnitPlatform() +} + +ext { + swagger_annotations_version = "1.5.24" + jackson_version = "2.13.4" + jackson_databind_version = "2.13.4.2" + jackson_databind_nullable_version = "0.2.4" + jakarta_annotation_version = "1.3.5" + feign_version = "10.11" + feign_form_version = "3.8.0" + junit_version = "5.7.0" + scribejava_version = "8.0.0" +} + +dependencies { + implementation "io.swagger:swagger-annotations:$swagger_annotations_version" + implementation "com.google.code.findbugs:jsr305:3.0.2" + implementation "io.github.openfeign:feign-core:$feign_version" + implementation "io.github.openfeign:feign-jackson:$feign_version" + implementation "io.github.openfeign:feign-slf4j:$feign_version" + implementation "io.github.openfeign:feign-okhttp:$feign_version" + implementation "io.github.openfeign.form:feign-form:$feign_form_version" + implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version" + implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" + implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version" + implementation "org.openapitools:jackson-databind-nullable:$jackson_databind_nullable_version" + implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version" + implementation "com.brsanthu:migbase64:2.2" + implementation "com.github.scribejava:scribejava-core:$scribejava_version" + implementation "com.brsanthu:migbase64:2.2" + implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version" + testImplementation "org.junit.jupiter:junit-jupiter:$junit_version" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version" + testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version" + testImplementation "com.github.tomakehurst:wiremock-jre8:2.27.2" + testImplementation "org.hamcrest:hamcrest:2.2" + testImplementation "commons-io:commons-io:2.8.0" + testImplementation "ch.qos.logback:logback-classic:1.2.3" +} diff --git a/samples/client/echo_api/java/feign-gson/build.sbt b/samples/client/echo_api/java/feign-gson/build.sbt new file mode 100644 index 00000000000..99e885e78ca --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/build.sbt @@ -0,0 +1,34 @@ +lazy val root = (project in file(".")). + settings( + organization := "org.openapitools", + name := "echo-api-feign-json", + version := "0.1.0", + scalaVersion := "2.11.4", + scalacOptions ++= Seq("-feature"), + javacOptions in compile ++= Seq("-Xlint:deprecation"), + publishArtifact in (Compile, packageDoc) := false, + resolvers += Resolver.mavenLocal, + libraryDependencies ++= Seq( + "io.swagger" % "swagger-annotations" % "1.5.24" % "compile", + "com.google.code.findbugs" % "jsr305" % "3.0.2" % "compile", + "io.github.openfeign" % "feign-core" % "10.11" % "compile", + "io.github.openfeign" % "feign-jackson" % "10.11" % "compile", + "io.github.openfeign" % "feign-slf4j" % "10.11" % "compile", + "io.github.openfeign.form" % "feign-form" % "3.8.0" % "compile", + "io.github.openfeign" % "feign-okhttp" % "10.11" % "compile", + "com.fasterxml.jackson.core" % "jackson-core" % "2.13.4" % "compile", + "com.fasterxml.jackson.core" % "jackson-annotations" % "2.13.4" % "compile", + "com.fasterxml.jackson.core" % "jackson-databind" % "2.13.4.2" % "compile", + "com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.9.10" % "compile", + "com.github.joschi.jackson" % "jackson-datatype-threetenbp" % "2.9.10" % "compile", + "com.github.scribejava" % "scribejava-core" % "8.0.0" % "compile", + "com.brsanthu" % "migbase64" % "2.2" % "compile", + "jakarta.annotation" % "jakarta.annotation-api" % "1.3.5" % "compile", + "org.junit.jupiter" % "junit-jupiter" % "5.7.0" % "test", + "org.junit.jupiter" % "junit-jupiter-params" % "5.7.0" % "test", + "com.github.tomakehurst" % "wiremock-jre8" % "2.27.2" % "test", + "org.hamcrest" % "hamcrest" % "2.2" % "test", + "commons-io" % "commons-io" % "2.8.0" % "test", + "com.novocode" % "junit-interface" % "0.10" % "test" + ) + ) diff --git a/samples/client/echo_api/java/feign-gson/git_push.sh b/samples/client/echo_api/java/feign-gson/git_push.sh new file mode 100644 index 00000000000..f53a75d4fab --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/samples/client/echo_api/java/feign-gson/gradle.properties b/samples/client/echo_api/java/feign-gson/gradle.properties new file mode 100644 index 00000000000..a3408578278 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/gradle.properties @@ -0,0 +1,6 @@ +# This file is automatically generated by OpenAPI Generator (https://github.com/openAPITools/openapi-generator). +# To include other gradle properties as part of the code generation process, please use the `gradleProperties` option. +# +# Gradle properties reference: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties +# For example, uncomment below to build for Android +#target = android diff --git a/samples/client/echo_api/java/feign-gson/gradle/wrapper/gradle-wrapper.jar b/samples/client/echo_api/java/feign-gson/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..7454180f2ae Binary files /dev/null and b/samples/client/echo_api/java/feign-gson/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/client/echo_api/java/feign-gson/gradle/wrapper/gradle-wrapper.properties b/samples/client/echo_api/java/feign-gson/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..ffed3a254e9 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/client/echo_api/java/feign-gson/gradlew b/samples/client/echo_api/java/feign-gson/gradlew new file mode 100644 index 00000000000..005bcde0428 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/samples/client/echo_api/java/feign-gson/gradlew.bat b/samples/client/echo_api/java/feign-gson/gradlew.bat new file mode 100644 index 00000000000..6a68175eb70 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS=-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/client/echo_api/java/feign-gson/pom.xml b/samples/client/echo_api/java/feign-gson/pom.xml new file mode 100644 index 00000000000..4a36787dd00 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/pom.xml @@ -0,0 +1,320 @@ + + 4.0.0 + org.openapitools + echo-api-feign-json + jar + echo-api-feign-json + 0.1.0 + https://github.com/openapitools/openapi-generator + OpenAPI Java + + scm:git:git@github.com:openapitools/openapi-generator.git + scm:git:git@github.com:openapitools/openapi-generator.git + https://github.com/openapitools/openapi-generator + + + + + Unlicense + http://www.apache.org/licenses/LICENSE-2.0.html + repo + + + + + + OpenAPI-Generator Contributors + team@openapitools.org + OpenAPITools.org + http://openapitools.org + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M1 + + + enforce-maven + + enforce + + + + + 2.2.0 + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + + + loggerPath + conf/log4j.properties + + + -Xms512m -Xmx1500m + methods + 10 + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory}/lib + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + jar + test-jar + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.10 + + + add_sources + generate-sources + + add-source + + + + src/main/java + + + + + add_test_sources + generate-test-sources + + add-test-source + + + + src/test/java + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + true + 128m + 512m + + -Xlint:all + -J-Xss4m + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.2 + + none + 1.8 + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + + + + sign-artifacts + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + + + + + + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + + + io.github.openfeign + feign-core + ${feign-version} + + + io.github.openfeign + feign-gson + ${feign-version} + + + io.github.openfeign + feign-slf4j + ${feign-version} + + + io.github.openfeign.form + feign-form + ${feign-form-version} + + + io.github.openfeign + feign-okhttp + ${feign-version} + + + + com.google.code.gson + gson + ${gson-version} + + + org.openapitools + jackson-databind-nullable + ${jackson-databind-nullable-version} + + + com.github.scribejava + scribejava-core + ${scribejava-version} + + + jakarta.annotation + jakarta.annotation-api + ${jakarta-annotation-version} + provided + + + + + ch.qos.logback + logback-classic + 1.2.10 + test + + + org.junit.jupiter + junit-jupiter + ${junit-version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit-version} + test + + + org.hamcrest + hamcrest + 2.2 + test + + + com.github.tomakehurst + wiremock-jre8 + 2.27.2 + test + + + commons-io + commons-io + 2.8.0 + test + + + + UTF-8 + 1.8 + ${java.version} + ${java.version} + 1.6.6 + 10.11 + 3.8.0 + 2.8.6 + 0.2.4 + 2.13.4.2 + 1.3.5 + 5.7.0 + 1.0.0 + 8.0.0 + + diff --git a/samples/client/echo_api/java/feign-gson/settings.gradle b/samples/client/echo_api/java/feign-gson/settings.gradle new file mode 100644 index 00000000000..83d1d03203f --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "echo-api-feign-json" \ No newline at end of file diff --git a/samples/client/echo_api/java/feign-gson/src/main/AndroidManifest.xml b/samples/client/echo_api/java/feign-gson/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..54fbcb3da1e --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ApiClient.java new file mode 100644 index 00000000000..b122f0e05eb --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ApiClient.java @@ -0,0 +1,196 @@ +package org.openapitools.client; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + + +import feign.Feign; +import feign.RequestInterceptor; +import feign.form.FormEncoder; +import feign.gson.GsonDecoder; +import feign.gson.GsonEncoder; +import feign.slf4j.Slf4jLogger; +import org.openapitools.client.auth.HttpBasicAuth; +import org.openapitools.client.auth.HttpBearerAuth; +import org.openapitools.client.auth.ApiKeyAuth; + + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class ApiClient { + private static final Logger log = Logger.getLogger(ApiClient.class.getName()); + + public interface Api {} + + private String basePath = "http://localhost:3000"; + private Map apiAuthorizations; + private Feign.Builder feignBuilder; + + public ApiClient() { + apiAuthorizations = new LinkedHashMap(); + feignBuilder = Feign.builder() + .encoder(new FormEncoder(new GsonEncoder())) + .decoder(new GsonDecoder()) + .logger(new Slf4jLogger()); + } + + public ApiClient(String[] authNames) { + this(); + for(String authName : authNames) { + log.log(Level.FINE, "Creating authentication {0}", authName); + throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); + } + } + + /** + * Basic constructor for single auth name + * @param authName + */ + public ApiClient(String authName) { + this(new String[]{authName}); + } + + /** + * Helper constructor for single api key + * @param authName + * @param apiKey + */ + public ApiClient(String authName, String apiKey) { + this(authName); + this.setApiKey(apiKey); + } + + public String getBasePath() { + return basePath; + } + + public ApiClient setBasePath(String basePath) { + this.basePath = basePath; + return this; + } + + public Map getApiAuthorizations() { + return apiAuthorizations; + } + + public void setApiAuthorizations(Map apiAuthorizations) { + this.apiAuthorizations = apiAuthorizations; + } + + public Feign.Builder getFeignBuilder() { + return feignBuilder; + } + + public ApiClient setFeignBuilder(Feign.Builder feignBuilder) { + this.feignBuilder = feignBuilder; + return this; + } + + + + + /** + * Creates a feign client for given API interface. + * + * Usage: + * ApiClient apiClient = new ApiClient(); + * apiClient.setBasePath("http://localhost:8080"); + * XYZApi api = apiClient.buildClient(XYZApi.class); + * XYZResponse response = api.someMethod(...); + * @param Type + * @param clientClass Client class + * @return The Client + */ + public T buildClient(Class clientClass) { + return feignBuilder.target(clientClass, basePath); + } + + /** + * Select the Accept header's value from the given accepts array: + * if JSON exists in the given array, use it; + * otherwise use all of them (joining into a string) + * + * @param accepts The accepts array to select from + * @return The Accept header to use. If the given array is empty, + * null will be returned (not to set the Accept header explicitly). + */ + public String selectHeaderAccept(String[] accepts) { + if (accepts.length == 0) return null; + if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json"; + return StringUtil.join(accepts, ","); + } + + /** + * Select the Content-Type header's value from the given array: + * if JSON exists in the given array, use it; + * otherwise use the first one of the array. + * + * @param contentTypes The Content-Type array to select from + * @return The Content-Type header to use. If the given array is empty, + * JSON will be used. + */ + public String selectHeaderContentType(String[] contentTypes) { + if (contentTypes.length == 0) return "application/json"; + if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json"; + return contentTypes[0]; + } + + /** + * Helper method to configure the bearer token. + * @param bearerToken the bearer token. + */ + public void setBearerToken(String bearerToken) { + HttpBearerAuth apiAuthorization = getAuthorization(HttpBearerAuth.class); + apiAuthorization.setBearerToken(bearerToken); + } + + /** + * Helper method to configure the first api key found + * @param apiKey API key + */ + public void setApiKey(String apiKey) { + ApiKeyAuth apiAuthorization = getAuthorization(ApiKeyAuth.class); + apiAuthorization.setApiKey(apiKey); + } + + /** + * Helper method to configure the username/password for basic auth + * @param username Username + * @param password Password + */ + public void setCredentials(String username, String password) { + HttpBasicAuth apiAuthorization = getAuthorization(HttpBasicAuth.class); + apiAuthorization.setCredentials(username, password); + } + + /** + * Gets request interceptor based on authentication name + * @param authName Authentication name + * @return Request Interceptor + */ + public RequestInterceptor getAuthorization(String authName) { + return apiAuthorizations.get(authName); + } + + /** + * Adds an authorization to be used by the client + * @param authName Authentication name + * @param authorization Request interceptor + */ + public void addAuthorization(String authName, RequestInterceptor authorization) { + if (apiAuthorizations.containsKey(authName)) { + throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations"); + } + apiAuthorizations.put(authName, authorization); + feignBuilder.requestInterceptor(authorization); + } + + private T getAuthorization(Class type) { + return (T) apiAuthorizations.values() + .stream() + .filter(requestInterceptor -> type.isAssignableFrom(requestInterceptor.getClass())) + .findFirst() + .orElseThrow(() -> new RuntimeException("No Oauth authentication or OAuth configured!")); + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/EncodingUtils.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/EncodingUtils.java new file mode 100644 index 00000000000..c5a76a97857 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/EncodingUtils.java @@ -0,0 +1,86 @@ +package org.openapitools.client; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** +* Utilities to support Swagger encoding formats in Feign. +*/ +public final class EncodingUtils { + + /** + * Private constructor. Do not construct this class. + */ + private EncodingUtils() {} + + /** + *

Encodes a collection of query parameters according to the Swagger + * collection format.

+ * + *

Of the various collection formats defined by Swagger ("csv", "tsv", + * etc), Feign only natively supports "multi". This utility generates the + * other format types so it will be properly processed by Feign.

+ * + *

Note, as part of reformatting, it URL encodes the parameters as + * well.

+ * @param parameters The collection object to be formatted. This object will + * not be changed. + * @param collectionFormat The Swagger collection format (eg, "csv", "tsv", + * "pipes"). See the + * + * OpenAPI Spec for more details. + * @return An object that will be correctly formatted by Feign. + */ + public static Object encodeCollection(Collection parameters, + String collectionFormat) { + if (parameters == null) { + return parameters; + } + List stringValues = new ArrayList<>(parameters.size()); + for (Object parameter : parameters) { + // ignore null values (same behavior as Feign) + if (parameter != null) { + stringValues.add(encode(parameter)); + } + } + // Feign natively handles single-element lists and the "multi" format. + if (stringValues.size() < 2 || "multi".equals(collectionFormat)) { + return stringValues; + } + // Otherwise return a formatted String + String[] stringArray = stringValues.toArray(new String[0]); + switch (collectionFormat) { + case "csv": + default: + return StringUtil.join(stringArray, ","); + case "ssv": + return StringUtil.join(stringArray, " "); + case "tsv": + return StringUtil.join(stringArray, "\t"); + case "pipes": + return StringUtil.join(stringArray, "|"); + } + } + + /** + * URL encode a single query parameter. + * @param parameter The query parameter to encode. This object will not be + * changed. + * @return The URL encoded string representation of the parameter. If the + * parameter is null, returns null. + */ + public static String encode(Object parameter) { + if (parameter == null) { + return null; + } + try { + return URLEncoder.encode(parameter.toString(), "UTF-8").replaceAll("\\+", "%20"); + } catch (UnsupportedEncodingException e) { + // Should never happen, UTF-8 is always supported + throw new RuntimeException(e); + } + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ServerConfiguration.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ServerConfiguration.java new file mode 100644 index 00000000000..59edc528a44 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ServerConfiguration.java @@ -0,0 +1,58 @@ +package org.openapitools.client; + +import java.util.Map; + +/** + * Representing a Server configuration. + */ +public class ServerConfiguration { + public String URL; + public String description; + public Map variables; + + /** + * @param URL A URL to the target host. + * @param description A description of the host designated by the URL. + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ + public ServerConfiguration(String URL, String description, Map variables) { + this.URL = URL; + this.description = description; + this.variables = variables; + } + + /** + * Format URL template using given variables. + * + * @param variables A map between a variable name and its value. + * @return Formatted URL. + */ + public String URL(Map variables) { + String url = this.URL; + + // go through variables and replace placeholders + for (Map.Entry variable: this.variables.entrySet()) { + String name = variable.getKey(); + ServerVariable serverVariable = variable.getValue(); + String value = serverVariable.defaultValue; + + if (variables != null && variables.containsKey(name)) { + value = variables.get(name); + if (serverVariable.enumValues.size() > 0 && !serverVariable.enumValues.contains(value)) { + throw new IllegalArgumentException("The variable " + name + " in the server URL has invalid value " + value + "."); + } + } + url = url.replace("{" + name + "}", value); + } + return url; + } + + /** + * Format URL template using default server variables. + * + * @return Formatted URL. + */ + public String URL() { + return URL(null); + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ServerVariable.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ServerVariable.java new file mode 100644 index 00000000000..c2f13e21666 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ServerVariable.java @@ -0,0 +1,23 @@ +package org.openapitools.client; + +import java.util.HashSet; + +/** + * Representing a Server Variable for server URL template substitution. + */ +public class ServerVariable { + public String description; + public String defaultValue; + public HashSet enumValues = null; + + /** + * @param description A description for the server variable. + * @param defaultValue The default value to use for substitution. + * @param enumValues An enumeration of string values to be used if the substitution options are from a limited set. + */ + public ServerVariable(String description, String defaultValue, HashSet enumValues) { + this.description = description; + this.defaultValue = defaultValue; + this.enumValues = enumValues; + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/StringUtil.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/StringUtil.java new file mode 100644 index 00000000000..d6c3fc8a968 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/StringUtil.java @@ -0,0 +1,83 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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; + +import java.util.Collection; +import java.util.Iterator; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class StringUtil { + /** + * Check if the given array contains the given value (with case-insensitive comparison). + * + * @param array The array + * @param value The value to search + * @return true if the array contains the value + */ + public static boolean containsIgnoreCase(String[] array, String value) { + for (String str : array) { + if (value == null && str == null) { + return true; + } + if (value != null && value.equalsIgnoreCase(str)) { + return true; + } + } + return false; + } + + /** + * Join an array of strings with the given separator. + *

+ * Note: This might be replaced by utility method from commons-lang or guava someday + * if one of those libraries is added as dependency. + *

+ * + * @param array The array of strings + * @param separator The separator + * @return the resulting string + */ + public static String join(String[] array, String separator) { + int len = array.length; + if (len == 0) { + return ""; + } + + StringBuilder out = new StringBuilder(); + out.append(array[0]); + for (int i = 1; i < len; i++) { + out.append(separator).append(array[i]); + } + return out.toString(); + } + + /** + * Join a list of strings with the given separator. + * + * @param list The list of strings + * @param separator The separator + * @return the resulting string + */ + public static String join(Collection list, String separator) { + Iterator iterator = list.iterator(); + StringBuilder out = new StringBuilder(); + if (iterator.hasNext()) { + out.append(iterator.next()); + } + while (iterator.hasNext()) { + out.append(separator).append(iterator.next()); + } + return out.toString(); + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/BodyApi.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/BodyApi.java new file mode 100644 index 00000000000..c9750387366 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/BodyApi.java @@ -0,0 +1,47 @@ +package org.openapitools.client.api; + +import org.openapitools.client.ApiClient; +import org.openapitools.client.EncodingUtils; +import org.openapitools.client.model.ApiResponse; + +import org.openapitools.client.model.Pet; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import feign.*; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public interface BodyApi extends ApiClient.Api { + + + /** + * Test body parameter(s) + * Test body parameter(s) + * @param pet Pet object that needs to be added to the store (optional) + * @return Pet + */ + @RequestLine("POST /echo/body/Pet") + @Headers({ + "Content-Type: application/json", + "Accept: application/json", + }) + Pet testEchoBodyPet(Pet pet); + + /** + * Test body parameter(s) + * Similar to testEchoBodyPet but it also returns the http response headers . + * Test body parameter(s) + * @param pet Pet object that needs to be added to the store (optional) + * @return A ApiResponse that wraps the response boyd and the http headers. + */ + @RequestLine("POST /echo/body/Pet") + @Headers({ + "Content-Type: application/json", + "Accept: application/json", + }) + ApiResponse testEchoBodyPetWithHttpInfo(Pet pet); + + +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/PathApi.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/PathApi.java new file mode 100644 index 00000000000..94d6038547c --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/PathApi.java @@ -0,0 +1,46 @@ +package org.openapitools.client.api; + +import org.openapitools.client.ApiClient; +import org.openapitools.client.EncodingUtils; +import org.openapitools.client.model.ApiResponse; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import feign.*; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public interface PathApi extends ApiClient.Api { + + + /** + * Test path parameter(s) + * Test path parameter(s) + * @param pathString (required) + * @param pathInteger (required) + * @return String + */ + @RequestLine("GET /path/string/{pathString}/integer/{pathInteger}") + @Headers({ + "Accept: text/plain", + }) + String testsPathStringPathStringIntegerPathInteger(@Param("pathString") String pathString, @Param("pathInteger") Integer pathInteger); + + /** + * Test path parameter(s) + * Similar to testsPathStringPathStringIntegerPathInteger but it also returns the http response headers . + * Test path parameter(s) + * @param pathString (required) + * @param pathInteger (required) + * @return A ApiResponse that wraps the response boyd and the http headers. + */ + @RequestLine("GET /path/string/{pathString}/integer/{pathInteger}") + @Headers({ + "Accept: text/plain", + }) + ApiResponse testsPathStringPathStringIntegerPathIntegerWithHttpInfo(@Param("pathString") String pathString, @Param("pathInteger") Integer pathInteger); + + +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/QueryApi.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/QueryApi.java new file mode 100644 index 00000000000..c4daf6833bb --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/api/QueryApi.java @@ -0,0 +1,266 @@ +package org.openapitools.client.api; + +import org.openapitools.client.ApiClient; +import org.openapitools.client.EncodingUtils; +import org.openapitools.client.model.ApiResponse; + +import org.openapitools.client.model.Pet; +import org.openapitools.client.model.TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import feign.*; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public interface QueryApi extends ApiClient.Api { + + + /** + * Test query parameter(s) + * Test query parameter(s) + * @param integerQuery (optional) + * @param booleanQuery (optional) + * @param stringQuery (optional) + * @return String + */ + @RequestLine("GET /query/integer/boolean/string?integer_query={integerQuery}&boolean_query={booleanQuery}&string_query={stringQuery}") + @Headers({ + "Accept: text/plain", + }) + String testQueryIntegerBooleanString(@Param("integerQuery") Integer integerQuery, @Param("booleanQuery") Boolean booleanQuery, @Param("stringQuery") String stringQuery); + + /** + * Test query parameter(s) + * Similar to testQueryIntegerBooleanString but it also returns the http response headers . + * Test query parameter(s) + * @param integerQuery (optional) + * @param booleanQuery (optional) + * @param stringQuery (optional) + * @return A ApiResponse that wraps the response boyd and the http headers. + */ + @RequestLine("GET /query/integer/boolean/string?integer_query={integerQuery}&boolean_query={booleanQuery}&string_query={stringQuery}") + @Headers({ + "Accept: text/plain", + }) + ApiResponse testQueryIntegerBooleanStringWithHttpInfo(@Param("integerQuery") Integer integerQuery, @Param("booleanQuery") Boolean booleanQuery, @Param("stringQuery") String stringQuery); + + + /** + * Test query parameter(s) + * Test query parameter(s) + * Note, this is equivalent to the other testQueryIntegerBooleanString method, + * but with the query parameters collected into a single Map parameter. This + * is convenient for services with optional query parameters, especially when + * used with the {@link TestQueryIntegerBooleanStringQueryParams} class that allows for + * building up this map in a fluent style. + * @param queryParams Map of query parameters as name-value pairs + *

The following elements may be specified in the query map:

+ *
    + *
  • integerQuery - (optional)
  • + *
  • booleanQuery - (optional)
  • + *
  • stringQuery - (optional)
  • + *
+ * @return String + */ + @RequestLine("GET /query/integer/boolean/string?integer_query={integerQuery}&boolean_query={booleanQuery}&string_query={stringQuery}") + @Headers({ + "Accept: text/plain", + }) + String testQueryIntegerBooleanString(@QueryMap(encoded=true) Map queryParams); + + /** + * Test query parameter(s) + * Test query parameter(s) + * Note, this is equivalent to the other testQueryIntegerBooleanString that receives the query parameters as a map, + * but this one also exposes the Http response headers + * @param queryParams Map of query parameters as name-value pairs + *

The following elements may be specified in the query map:

+ *
    + *
  • integerQuery - (optional)
  • + *
  • booleanQuery - (optional)
  • + *
  • stringQuery - (optional)
  • + *
+ * @return String + */ + @RequestLine("GET /query/integer/boolean/string?integer_query={integerQuery}&boolean_query={booleanQuery}&string_query={stringQuery}") + @Headers({ + "Accept: text/plain", + }) + ApiResponse testQueryIntegerBooleanStringWithHttpInfo(@QueryMap(encoded=true) Map queryParams); + + + /** + * A convenience class for generating query parameters for the + * testQueryIntegerBooleanString method in a fluent style. + */ + public static class TestQueryIntegerBooleanStringQueryParams extends HashMap { + public TestQueryIntegerBooleanStringQueryParams integerQuery(final Integer value) { + put("integer_query", EncodingUtils.encode(value)); + return this; + } + public TestQueryIntegerBooleanStringQueryParams booleanQuery(final Boolean value) { + put("boolean_query", EncodingUtils.encode(value)); + return this; + } + public TestQueryIntegerBooleanStringQueryParams stringQuery(final String value) { + put("string_query", EncodingUtils.encode(value)); + return this; + } + } + + /** + * Test query parameter(s) + * Test query parameter(s) + * @param queryObject (optional) + * @return String + */ + @RequestLine("GET /query/style_form/explode_true/array_string?query_object={queryObject}") + @Headers({ + "Accept: text/plain", + }) + String testQueryStyleFormExplodeTrueArrayString(@Param("queryObject") TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter queryObject); + + /** + * Test query parameter(s) + * Similar to testQueryStyleFormExplodeTrueArrayString but it also returns the http response headers . + * Test query parameter(s) + * @param queryObject (optional) + * @return A ApiResponse that wraps the response boyd and the http headers. + */ + @RequestLine("GET /query/style_form/explode_true/array_string?query_object={queryObject}") + @Headers({ + "Accept: text/plain", + }) + ApiResponse testQueryStyleFormExplodeTrueArrayStringWithHttpInfo(@Param("queryObject") TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter queryObject); + + + /** + * Test query parameter(s) + * Test query parameter(s) + * Note, this is equivalent to the other testQueryStyleFormExplodeTrueArrayString method, + * but with the query parameters collected into a single Map parameter. This + * is convenient for services with optional query parameters, especially when + * used with the {@link TestQueryStyleFormExplodeTrueArrayStringQueryParams} class that allows for + * building up this map in a fluent style. + * @param queryParams Map of query parameters as name-value pairs + *

The following elements may be specified in the query map:

+ *
    + *
  • queryObject - (optional)
  • + *
+ * @return String + */ + @RequestLine("GET /query/style_form/explode_true/array_string?query_object={queryObject}") + @Headers({ + "Accept: text/plain", + }) + String testQueryStyleFormExplodeTrueArrayString(@QueryMap(encoded=true) Map queryParams); + + /** + * Test query parameter(s) + * Test query parameter(s) + * Note, this is equivalent to the other testQueryStyleFormExplodeTrueArrayString that receives the query parameters as a map, + * but this one also exposes the Http response headers + * @param queryParams Map of query parameters as name-value pairs + *

The following elements may be specified in the query map:

+ *
    + *
  • queryObject - (optional)
  • + *
+ * @return String + */ + @RequestLine("GET /query/style_form/explode_true/array_string?query_object={queryObject}") + @Headers({ + "Accept: text/plain", + }) + ApiResponse testQueryStyleFormExplodeTrueArrayStringWithHttpInfo(@QueryMap(encoded=true) Map queryParams); + + + /** + * A convenience class for generating query parameters for the + * testQueryStyleFormExplodeTrueArrayString method in a fluent style. + */ + public static class TestQueryStyleFormExplodeTrueArrayStringQueryParams extends HashMap { + public TestQueryStyleFormExplodeTrueArrayStringQueryParams queryObject(final TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter value) { + put("query_object", EncodingUtils.encode(value)); + return this; + } + } + + /** + * Test query parameter(s) + * Test query parameter(s) + * @param queryObject (optional) + * @return String + */ + @RequestLine("GET /query/style_form/explode_true/object?query_object={queryObject}") + @Headers({ + "Accept: text/plain", + }) + String testQueryStyleFormExplodeTrueObject(@Param("queryObject") Pet queryObject); + + /** + * Test query parameter(s) + * Similar to testQueryStyleFormExplodeTrueObject but it also returns the http response headers . + * Test query parameter(s) + * @param queryObject (optional) + * @return A ApiResponse that wraps the response boyd and the http headers. + */ + @RequestLine("GET /query/style_form/explode_true/object?query_object={queryObject}") + @Headers({ + "Accept: text/plain", + }) + ApiResponse testQueryStyleFormExplodeTrueObjectWithHttpInfo(@Param("queryObject") Pet queryObject); + + + /** + * Test query parameter(s) + * Test query parameter(s) + * Note, this is equivalent to the other testQueryStyleFormExplodeTrueObject method, + * but with the query parameters collected into a single Map parameter. This + * is convenient for services with optional query parameters, especially when + * used with the {@link TestQueryStyleFormExplodeTrueObjectQueryParams} class that allows for + * building up this map in a fluent style. + * @param queryParams Map of query parameters as name-value pairs + *

The following elements may be specified in the query map:

+ *
    + *
  • queryObject - (optional)
  • + *
+ * @return String + */ + @RequestLine("GET /query/style_form/explode_true/object?query_object={queryObject}") + @Headers({ + "Accept: text/plain", + }) + String testQueryStyleFormExplodeTrueObject(@QueryMap(encoded=true) Map queryParams); + + /** + * Test query parameter(s) + * Test query parameter(s) + * Note, this is equivalent to the other testQueryStyleFormExplodeTrueObject that receives the query parameters as a map, + * but this one also exposes the Http response headers + * @param queryParams Map of query parameters as name-value pairs + *

The following elements may be specified in the query map:

+ *
    + *
  • queryObject - (optional)
  • + *
+ * @return String + */ + @RequestLine("GET /query/style_form/explode_true/object?query_object={queryObject}") + @Headers({ + "Accept: text/plain", + }) + ApiResponse testQueryStyleFormExplodeTrueObjectWithHttpInfo(@QueryMap(encoded=true) Map queryParams); + + + /** + * A convenience class for generating query parameters for the + * testQueryStyleFormExplodeTrueObject method in a fluent style. + */ + public static class TestQueryStyleFormExplodeTrueObjectQueryParams extends HashMap { + public TestQueryStyleFormExplodeTrueObjectQueryParams queryObject(final Pet value) { + put("query_object", EncodingUtils.encode(value)); + return this; + } + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/ApiKeyAuth.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/ApiKeyAuth.java new file mode 100644 index 00000000000..44511e4641c --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/ApiKeyAuth.java @@ -0,0 +1,43 @@ +package org.openapitools.client.auth; + +import feign.RequestInterceptor; +import feign.RequestTemplate; + +public class ApiKeyAuth implements RequestInterceptor { + private final String location; + private final String paramName; + + private String apiKey; + + public ApiKeyAuth(String location, String paramName) { + this.location = location; + this.paramName = paramName; + } + + public String getLocation() { + return location; + } + + public String getParamName() { + return paramName; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + @Override + public void apply(RequestTemplate template) { + if ("query".equals(location)) { + template.query(paramName, apiKey); + } else if ("header".equals(location)) { + template.header(paramName, apiKey); + } else if ("cookie".equals(location)) { + template.header("Cookie", String.format("%s=%s", paramName, apiKey)); + } + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/DefaultApi20Impl.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/DefaultApi20Impl.java new file mode 100644 index 00000000000..80db21111f9 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/DefaultApi20Impl.java @@ -0,0 +1,47 @@ +package org.openapitools.client.auth; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class DefaultApi20Impl extends DefaultApi20 { + + private final String accessTokenEndpoint; + private final String authorizationBaseUrl; + + protected DefaultApi20Impl(String authorizationBaseUrl, String accessTokenEndpoint) { + this.authorizationBaseUrl = authorizationBaseUrl; + this.accessTokenEndpoint = accessTokenEndpoint; + } + + @Override + public String getAccessTokenEndpoint() { + return accessTokenEndpoint; + } + + @Override + protected String getAuthorizationBaseUrl() { + return authorizationBaseUrl; + } + + @Override + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } +} \ No newline at end of file diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBasicAuth.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBasicAuth.java new file mode 100644 index 00000000000..9fc0358f10c --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBasicAuth.java @@ -0,0 +1,41 @@ +package org.openapitools.client.auth; + +import feign.RequestInterceptor; +import feign.RequestTemplate; +import feign.auth.BasicAuthRequestInterceptor; + +/** + * An interceptor that adds the request header needed to use HTTP basic authentication. + */ +public class HttpBasicAuth implements RequestInterceptor { + + private String username; + private String password; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setCredentials(String username, String password) { + this.username = username; + this.password = password; + } + + @Override + public void apply(RequestTemplate template) { + RequestInterceptor requestInterceptor = new BasicAuthRequestInterceptor(username, password); + requestInterceptor.apply(template); + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java new file mode 100644 index 00000000000..d4c9cbe6361 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -0,0 +1,43 @@ +package org.openapitools.client.auth; + +import feign.RequestInterceptor; +import feign.RequestTemplate; + +/** + * An interceptor that adds the request header needed to use HTTP bearer authentication. + */ +public class HttpBearerAuth implements RequestInterceptor { + private final String scheme; + private String bearerToken; + + public HttpBearerAuth(String scheme) { + this.scheme = scheme; + } + + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + */ + public String getBearerToken() { + return bearerToken; + } + + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + */ + public void setBearerToken(String bearerToken) { + this.bearerToken = bearerToken; + } + + @Override + public void apply(RequestTemplate template) { + if(bearerToken == null) { + return; + } + + template.header("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken); + } + + private static String upperCaseBearer(String scheme) { + return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme; + } +} diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/ApiResponse.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/ApiResponse.java new file mode 100644 index 00000000000..a0d44e724c5 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/ApiResponse.java @@ -0,0 +1,43 @@ +package org.openapitools.client.model; + +import java.util.Map; +import java.util.List; + +public class ApiResponse{ + + final private int statusCode; + final private Map> headers; + final private T data; + + /** + * @param statusCode The status code of HTTP response + * @param headers The headers of HTTP response + */ + public ApiResponse(int statusCode, Map> headers) { + this(statusCode, headers, null); + } + + /** + * @param statusCode The status code of HTTP response + * @param headers The headers of HTTP response + * @param data The object deserialized from response bod + */ + public ApiResponse(int statusCode, Map> headers, T data) { + this.statusCode = statusCode; + this.headers = headers; + this.data = data; + } + + public int getStatusCode() { + return statusCode; + } + + public Map> getHeaders() { + return headers; + } + + public T getData() { + return data; + } + +} \ No newline at end of file diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Category.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Category.java new file mode 100644 index 00000000000..236c8190bb8 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Category.java @@ -0,0 +1,125 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +/** + * Category + */ +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class Category { + public static final String SERIALIZED_NAME_ID = "id"; + @SerializedName(SERIALIZED_NAME_ID) + private Long id; + + public static final String SERIALIZED_NAME_NAME = "name"; + @SerializedName(SERIALIZED_NAME_NAME) + private String name; + + public Category() { + } + + public Category id(Long id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public Category name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @javax.annotation.Nullable + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Category category = (Category) o; + return Objects.equals(this.id, category.id) && + Objects.equals(this.name, category.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Category {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).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 String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Pet.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Pet.java new file mode 100644 index 00000000000..0f511d550b7 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Pet.java @@ -0,0 +1,303 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.openapitools.client.model.Category; +import org.openapitools.client.model.Tag; + +/** + * Pet + */ +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class Pet { + public static final String SERIALIZED_NAME_ID = "id"; + @SerializedName(SERIALIZED_NAME_ID) + private Long id; + + public static final String SERIALIZED_NAME_NAME = "name"; + @SerializedName(SERIALIZED_NAME_NAME) + private String name; + + public static final String SERIALIZED_NAME_CATEGORY = "category"; + @SerializedName(SERIALIZED_NAME_CATEGORY) + private Category category; + + public static final String SERIALIZED_NAME_PHOTO_URLS = "photoUrls"; + @SerializedName(SERIALIZED_NAME_PHOTO_URLS) + private List photoUrls = new ArrayList<>(); + + public static final String SERIALIZED_NAME_TAGS = "tags"; + @SerializedName(SERIALIZED_NAME_TAGS) + private List tags = null; + + /** + * pet status in the store + */ + @JsonAdapter(StatusEnum.Adapter.class) + public enum StatusEnum { + AVAILABLE("available"), + + PENDING("pending"), + + SOLD("sold"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + + public static class Adapter extends TypeAdapter { + @Override + public void write(final JsonWriter jsonWriter, final StatusEnum enumeration) throws IOException { + jsonWriter.value(enumeration.getValue()); + } + + @Override + public StatusEnum read(final JsonReader jsonReader) throws IOException { + String value = jsonReader.nextString(); + return StatusEnum.fromValue(value); + } + } + } + + public static final String SERIALIZED_NAME_STATUS = "status"; + @SerializedName(SERIALIZED_NAME_STATUS) + private StatusEnum status; + + public Pet() { + } + + public Pet id(Long id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public Pet name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @javax.annotation.Nonnull + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public Pet category(Category category) { + + this.category = category; + return this; + } + + /** + * Get category + * @return category + **/ + @javax.annotation.Nullable + + public Category getCategory() { + return category; + } + + + public void setCategory(Category category) { + this.category = category; + } + + + public Pet photoUrls(List photoUrls) { + + this.photoUrls = photoUrls; + return this; + } + + public Pet addPhotoUrlsItem(String photoUrlsItem) { + this.photoUrls.add(photoUrlsItem); + return this; + } + + /** + * Get photoUrls + * @return photoUrls + **/ + @javax.annotation.Nonnull + + public List getPhotoUrls() { + return photoUrls; + } + + + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + + public Pet tags(List tags) { + + this.tags = tags; + return this; + } + + public Pet addTagsItem(Tag tagsItem) { + if (this.tags == null) { + this.tags = new ArrayList<>(); + } + this.tags.add(tagsItem); + return this; + } + + /** + * Get tags + * @return tags + **/ + @javax.annotation.Nullable + + public List getTags() { + return tags; + } + + + public void setTags(List tags) { + this.tags = tags; + } + + + public Pet status(StatusEnum status) { + + this.status = status; + return this; + } + + /** + * pet status in the store + * @return status + **/ + @javax.annotation.Nullable + + public StatusEnum getStatus() { + return status; + } + + + public void setStatus(StatusEnum status) { + this.status = status; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pet pet = (Pet) o; + return Objects.equals(this.id, pet.id) && + Objects.equals(this.name, pet.name) && + Objects.equals(this.category, pet.category) && + Objects.equals(this.photoUrls, pet.photoUrls) && + Objects.equals(this.tags, pet.tags) && + Objects.equals(this.status, pet.status); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, category, photoUrls, tags, status); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pet {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" category: ").append(toIndentedString(category)).append("\n"); + sb.append(" photoUrls: ").append(toIndentedString(photoUrls)).append("\n"); + sb.append(" tags: ").append(toIndentedString(tags)).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 String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Tag.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Tag.java new file mode 100644 index 00000000000..7bfaa5ea05c --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Tag.java @@ -0,0 +1,125 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +/** + * Tag + */ +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class Tag { + public static final String SERIALIZED_NAME_ID = "id"; + @SerializedName(SERIALIZED_NAME_ID) + private Long id; + + public static final String SERIALIZED_NAME_NAME = "name"; + @SerializedName(SERIALIZED_NAME_NAME) + private String name; + + public Tag() { + } + + public Tag id(Long id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public Tag name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @javax.annotation.Nullable + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Tag tag = (Tag) o; + return Objects.equals(this.id, tag.id) && + Objects.equals(this.name, tag.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Tag {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).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 String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.java new file mode 100644 index 00000000000..433e40e1376 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.java @@ -0,0 +1,107 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter + */ +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter { + public static final String SERIALIZED_NAME_VALUES = "values"; + @SerializedName(SERIALIZED_NAME_VALUES) + private List values = null; + + public TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter() { + } + + public TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter values(List values) { + + this.values = values; + return this; + } + + public TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter addValuesItem(String valuesItem) { + if (this.values == null) { + this.values = new ArrayList<>(); + } + this.values.add(valuesItem); + return this; + } + + /** + * Get values + * @return values + **/ + @javax.annotation.Nullable + + public List getValues() { + return values; + } + + + public void setValues(List values) { + this.values = values; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter testQueryStyleFormExplodeTrueArrayStringQueryObjectParameter = (TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter) o; + return Objects.equals(this.values, testQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.values); + } + + @Override + public int hashCode() { + return Objects.hash(values); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter {\n"); + sb.append(" values: ").append(toIndentedString(values)).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 String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/BodyApiTest.java b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/BodyApiTest.java new file mode 100644 index 00000000000..24c71b36076 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/BodyApiTest.java @@ -0,0 +1,42 @@ +package org.openapitools.client.api; + +import org.openapitools.client.ApiClient; +import org.openapitools.client.model.Pet; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + +import java.time.LocalDate; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * API tests for BodyApi + */ +class BodyApiTest { + + private BodyApi api; + + @BeforeEach + public void setup() { + api = new ApiClient().buildClient(BodyApi.class); + } + + + /** + * Test body parameter(s) + * + * Test body parameter(s) + */ + @Test + void testEchoBodyPetTest() { + Pet pet = null; + // Pet response = api.testEchoBodyPet(pet); + + // TODO: test validations + } + + +} diff --git a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/PathApiTest.java b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/PathApiTest.java new file mode 100644 index 00000000000..8f39b053aa4 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/PathApiTest.java @@ -0,0 +1,42 @@ +package org.openapitools.client.api; + +import org.openapitools.client.ApiClient; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + +import java.time.LocalDate; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * API tests for PathApi + */ +class PathApiTest { + + private PathApi api; + + @BeforeEach + public void setup() { + api = new ApiClient().buildClient(PathApi.class); + } + + + /** + * Test path parameter(s) + * + * Test path parameter(s) + */ + @Test + void testsPathStringPathStringIntegerPathIntegerTest() { + String pathString = null; + Integer pathInteger = null; + // String response = api.testsPathStringPathStringIntegerPathInteger(pathString, pathInteger); + + // TODO: test validations + } + + +} diff --git a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/QueryApiTest.java b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/QueryApiTest.java new file mode 100644 index 00000000000..b55588a0406 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/QueryApiTest.java @@ -0,0 +1,123 @@ +package org.openapitools.client.api; + +import org.openapitools.client.ApiClient; +import org.openapitools.client.model.Pet; +import org.openapitools.client.model.TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + +import java.time.LocalDate; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * API tests for QueryApi + */ +class QueryApiTest { + + private QueryApi api; + + @BeforeEach + public void setup() { + api = new ApiClient().buildClient(QueryApi.class); + } + + + /** + * Test query parameter(s) + * + * Test query parameter(s) + */ + @Test + void testQueryIntegerBooleanStringTest() { + Integer integerQuery = null; + Boolean booleanQuery = null; + String stringQuery = null; + // String response = api.testQueryIntegerBooleanString(integerQuery, booleanQuery, stringQuery); + + // TODO: test validations + } + + /** + * Test query parameter(s) + * + * Test query parameter(s) + * + * This tests the overload of the method that uses a Map for query parameters instead of + * listing them out individually. + */ + @Test + void testQueryIntegerBooleanStringTestQueryMap() { + QueryApi.TestQueryIntegerBooleanStringQueryParams queryParams = new QueryApi.TestQueryIntegerBooleanStringQueryParams() + .integerQuery(null) + .booleanQuery(null) + .stringQuery(null); + // String response = api.testQueryIntegerBooleanString(queryParams); + + // TODO: test validations + } + + /** + * Test query parameter(s) + * + * Test query parameter(s) + */ + @Test + void testQueryStyleFormExplodeTrueArrayStringTest() { + TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter queryObject = null; + // String response = api.testQueryStyleFormExplodeTrueArrayString(queryObject); + + // TODO: test validations + } + + /** + * Test query parameter(s) + * + * Test query parameter(s) + * + * This tests the overload of the method that uses a Map for query parameters instead of + * listing them out individually. + */ + @Test + void testQueryStyleFormExplodeTrueArrayStringTestQueryMap() { + QueryApi.TestQueryStyleFormExplodeTrueArrayStringQueryParams queryParams = new QueryApi.TestQueryStyleFormExplodeTrueArrayStringQueryParams() + .queryObject(null); + // String response = api.testQueryStyleFormExplodeTrueArrayString(queryParams); + + // TODO: test validations + } + + /** + * Test query parameter(s) + * + * Test query parameter(s) + */ + @Test + void testQueryStyleFormExplodeTrueObjectTest() { + Pet queryObject = null; + // String response = api.testQueryStyleFormExplodeTrueObject(queryObject); + + // TODO: test validations + } + + /** + * Test query parameter(s) + * + * Test query parameter(s) + * + * This tests the overload of the method that uses a Map for query parameters instead of + * listing them out individually. + */ + @Test + void testQueryStyleFormExplodeTrueObjectTestQueryMap() { + QueryApi.TestQueryStyleFormExplodeTrueObjectQueryParams queryParams = new QueryApi.TestQueryStyleFormExplodeTrueObjectQueryParams() + .queryObject(null); + // String response = api.testQueryStyleFormExplodeTrueObject(queryParams); + + // TODO: test validations + } + +} diff --git a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/CategoryTest.java b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/CategoryTest.java new file mode 100644 index 00000000000..ab5409ab270 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/CategoryTest.java @@ -0,0 +1,55 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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 com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import org.junit.jupiter.api.Test; + + +/** + * Model tests for Category + */ +class CategoryTest { + private final Category model = new Category(); + + /** + * Model tests for Category + */ + @Test + void testCategory() { + // TODO: test Category + } + + /** + * Test the property 'id' + */ + @Test + void idTest() { + // TODO: test id + } + + /** + * Test the property 'name' + */ + @Test + void nameTest() { + // TODO: test name + } + +} diff --git a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/PetTest.java b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/PetTest.java new file mode 100644 index 00000000000..886e8dee6c0 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/PetTest.java @@ -0,0 +1,91 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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 com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.openapitools.client.model.Category; +import org.openapitools.client.model.Tag; +import org.junit.jupiter.api.Test; + + +/** + * Model tests for Pet + */ +class PetTest { + private final Pet model = new Pet(); + + /** + * Model tests for Pet + */ + @Test + void testPet() { + // TODO: test Pet + } + + /** + * Test the property 'id' + */ + @Test + void idTest() { + // TODO: test id + } + + /** + * Test the property 'name' + */ + @Test + void nameTest() { + // TODO: test name + } + + /** + * Test the property 'category' + */ + @Test + void categoryTest() { + // TODO: test category + } + + /** + * Test the property 'photoUrls' + */ + @Test + void photoUrlsTest() { + // TODO: test photoUrls + } + + /** + * Test the property 'tags' + */ + @Test + void tagsTest() { + // TODO: test tags + } + + /** + * Test the property 'status' + */ + @Test + void statusTest() { + // TODO: test status + } + +} diff --git a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/TagTest.java b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/TagTest.java new file mode 100644 index 00000000000..033deaceb70 --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/TagTest.java @@ -0,0 +1,55 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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 com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import org.junit.jupiter.api.Test; + + +/** + * Model tests for Tag + */ +class TagTest { + private final Tag model = new Tag(); + + /** + * Model tests for Tag + */ + @Test + void testTag() { + // TODO: test Tag + } + + /** + * Test the property 'id' + */ + @Test + void idTest() { + // TODO: test id + } + + /** + * Test the property 'name' + */ + @Test + void nameTest() { + // TODO: test name + } + +} diff --git a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterTest.java b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterTest.java new file mode 100644 index 00000000000..3633d8e2cef --- /dev/null +++ b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterTest.java @@ -0,0 +1,49 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * 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 com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; + + +/** + * Model tests for TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter + */ +class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterTest { + private final TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter model = new TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(); + + /** + * Model tests for TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter + */ + @Test + void testTestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter() { + // TODO: test TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter + } + + /** + * Test the property 'values' + */ + @Test + void valuesTest() { + // TODO: test values + } + +} diff --git a/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiClient.java index 89305984908..41b1d1e5cf8 100644 --- a/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiClient.java @@ -6,7 +6,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import feign.okhttp.OkHttpClient; - import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -43,8 +42,8 @@ public class ApiClient { private Feign.Builder feignBuilder; public ApiClient() { - objectMapper = createObjectMapper(); apiAuthorizations = new LinkedHashMap(); + objectMapper = createObjectMapper(); feignBuilder = Feign.builder() .client(new OkHttpClient()) .encoder(new FormEncoder(new JacksonEncoder(objectMapper))) @@ -141,6 +140,7 @@ public class ApiClient { } } + public ObjectMapper getObjectMapper(){ return objectMapper; } diff --git a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/ApiClient.java index b7116f494f2..0923b7f67d5 100644 --- a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/ApiClient.java @@ -6,7 +6,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import feign.okhttp.OkHttpClient; - import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -44,8 +43,8 @@ public class ApiClient { private Feign.Builder feignBuilder; public ApiClient() { - objectMapper = createObjectMapper(); apiAuthorizations = new LinkedHashMap(); + objectMapper = createObjectMapper(); feignBuilder = Feign.builder() .client(new OkHttpClient()) .encoder(new FormEncoder(new JacksonEncoder(objectMapper))) @@ -148,6 +147,7 @@ public class ApiClient { } } + public ObjectMapper getObjectMapper(){ return objectMapper; }