Skip to content

Commit

Permalink
[java][okhttp] Add CI tests for streaming (#10678)
Browse files Browse the repository at this point in the history
* add ci tests for streaming

* use spaces instead of tabs

* update samples
  • Loading branch information
wing328 committed Oct 24, 2021
1 parent fcef9fa commit 602cffb
Show file tree
Hide file tree
Showing 43 changed files with 4,477 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bin/configs/java-okhttp-gson-streaming.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: java
outputDir: samples/client/others/java/okhttp-gson-streaming
library: okhttp-gson
inputSpec: modules/openapi-generator/src/test/resources/3_0/streaming.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: petstore-okhttp-gson
hideGenerationTimestamp: "true"
supportStreaming: true
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@
<module>samples/client/petstore/java/jersey1</module>
<module>samples/client/petstore/java/jersey2-java8</module>
<module>samples/openapi3/client/petstore/java/jersey2-java8</module>
<module>samples/client/others/java/okhttp-gson-streaming</module>
<module>samples/client/petstore/java/okhttp-gson</module>
<module>samples/client/petstore/java/retrofit2</module>
<module>samples/client/petstore/java/retrofit2rx2</module>
Expand Down
21 changes: 21 additions & 0 deletions samples/client/others/java/okhttp-gson-streaming/.gitignore
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

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

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

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

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

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.gitignore
.travis.yml
README.md
api/openapi.yaml
build.gradle
build.sbt
docs/PingApi.md
docs/SomeObj.md
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/ApiCallback.java
src/main/java/org/openapitools/client/ApiClient.java
src/main/java/org/openapitools/client/ApiException.java
src/main/java/org/openapitools/client/ApiResponse.java
src/main/java/org/openapitools/client/Configuration.java
src/main/java/org/openapitools/client/GzipRequestInterceptor.java
src/main/java/org/openapitools/client/JSON.java
src/main/java/org/openapitools/client/Pair.java
src/main/java/org/openapitools/client/ProgressRequestBody.java
src/main/java/org/openapitools/client/ProgressResponseBody.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/PingApi.java
src/main/java/org/openapitools/client/auth/ApiKeyAuth.java
src/main/java/org/openapitools/client/auth/Authentication.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/SomeObj.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.3.0-SNAPSHOT
22 changes: 22 additions & 0 deletions samples/client/others/java/okhttp-gson-streaming/.travis.yml
Original file line number Diff line number Diff line change
@@ -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
129 changes: 129 additions & 0 deletions samples/client/others/java/okhttp-gson-streaming/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# petstore-okhttp-gson

ping some object
- API version: 1.0

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)


*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)*


## Requirements

Building the API client library requires:
1. Java 1.7+
2. Maven/Gradle

## Installation

To install the API client library to your local Maven repository, simply execute:

```shell
mvn clean install
```

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

```shell
mvn clean deploy
```

Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>petstore-okhttp-gson</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
```

### Gradle users

Add this dependency to your project's build file:

```groovy
compile "org.openapitools:petstore-okhttp-gson:1.0"
```

### Others

At first generate the JAR by executing:

```shell
mvn clean package
```

Then manually install the following JARs:

* `target/petstore-okhttp-gson-1.0.jar`
* `target/lib/*.jar`

## Getting Started

Please follow the [installation](#installation) instruction and execute the following Java code:

```java

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.PingApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:8082");

PingApi apiInstance = new PingApi(defaultClient);
SomeObj someObj = new SomeObj(); // SomeObj |
try {
SomeObj result = apiInstance.postPing(someObj);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PingApi#postPing");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}

```

## Documentation for API Endpoints

All URIs are relative to *http://localhost:8082*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*PingApi* | [**postPing**](docs/PingApi.md#postPing) | **POST** /ping |


## Documentation for Models

- [SomeObj](docs/SomeObj.md)


## Documentation for Authorization

All endpoints do not require authorization.
Authentication schemes defined for the API:

## Recommendation

It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.

## Author



53 changes: 53 additions & 0 deletions samples/client/others/java/okhttp-gson-streaming/api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
openapi: 3.0.1
info:
title: ping some object
version: "1.0"
servers:
- url: http://localhost:8082/
paths:
/ping:
post:
operationId: postPing
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SomeObj'
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/SomeObj'
description: OK
tags:
- ping
x-streaming: true
x-contentType: application/json
x-accepts: application/json
components:
schemas:
SomeObj:
example:
name: name
active: true
$_type: SomeObjIdentifier
id: 0
type: type
properties:
$_type:
default: SomeObjIdentifier
enum:
- SomeObjIdentifier
type: string
id:
format: int64
type: integer
name:
type: string
active:
type: boolean
type:
type: string
type: object

Loading

0 comments on commit 602cffb

Please sign in to comment.