Skip to content

Commit

Permalink
Merge branch 'master' into rienafairefr-templating
Browse files Browse the repository at this point in the history
* master: (133 commits)
  #2503: fix out-of-memory issue with nested objects with arrays with maxItems set by limiting to max. 5 example items (#2536)
  remove emitDefaultValue option (#2559)
  fix EmitDefaultValue default vallue with false (#2558)
  Added API Key auth to rust-server (#2459)
  remove initialCaps and replace with camelize (#2546)
  Add packageName configuration to maven (#2429)
  [Typescript AngularJS] fix Extra package prefix in api parameters operations (#2522)
  #1023 - [Scala] Use status family during response processing (#1024)
  Generate setters for readonly properties in server code (#1582)
  [JS] fix NPE for null string and improve Travis config file (#2553)
  [elm] Update ISO 8601 library (fixes missing time zone designator) (#2545)
  [csharp] update sample after #2528 (#2550)
  [JavaScript] fix index.js, ApiClient.js and test files generated to incorrect location (#2511)
  Aspnetcore nullable support (#2529)
  Csharp nullable support (#2528)
  [C++] [Qt5] Add enum support for client and server (#2339)
  Fixed typo in migration-from-swagger-codegen.md (#2548)
  [TypeScript Client] fix install Aurelia + fix use deprecated function (#2514)
  [KOTLIN] fix var name not correctly sanitized (#2537)
  Update swagger-parser to '2.0.11-OpenAPITools.org-1' (#2262)
  ...
  • Loading branch information
jimschubert committed Apr 2, 2019
2 parents 765a539 + ec42aca commit da803dc
Show file tree
Hide file tree
Showing 5,352 changed files with 147,462 additions and 69,161 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### PR checklist

- [ ] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
- [ ] Ran the shell script under `./bin/` to update Petstore sample so that CIs can verify the change. (For instance, only need to run `./bin/{LANG}-petstore.sh`, `./bin/openapi3/{LANG}-petstore.sh`, `./bin/security/{LANG}-petstore.sh` and `./bin/openapi3/security/{LANG}-petstore.sh` if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in `.\bin\windows\`.
- [ ] Ran the shell script under `./bin/` to update Petstore sample so that CIs can verify the change. (For instance, only need to run `./bin/{LANG}-petstore.sh`, `./bin/openapi3/{LANG}-petstore.sh` if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in `.\bin\windows\`.
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`~~, `3.4.x`, `4.0.x`~~. Default: `master`.
- [ ] Copied the [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) to review the pull request if your PR is targeting a particular programming language.

Expand Down
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
oracle64-1.8.0.152
oracle64-1.8.0.152
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ after_success:
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
pushd .;
cd modules/openapi-generator-gradle-plugin;
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" publishPlugins -Dgradle.publish.key=$GRADLE_PUBLISH_KEY -Dgradle.publish.secret=$GRADLE_PUBLISH_SECRET --no-daemon;
echo "Finished ./gradlew publishPlugins (plugin portal)";
./gradlew -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
echo "Finished ./gradlew uploadArchives";
popd;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openapitools.client;

import okhttp3.OkHttpClient;
import org.openapitools.client.auth.*;

import java.text.DateFormat;
Expand Down Expand Up @@ -165,7 +166,7 @@ public void testGetAndSetConnectTimeout() {

apiClient.setConnectTimeout(10000);
}

@Test
public void testGetAndSetReadTimeout() {
// read timeout defaults to 10 seconds
Expand All @@ -178,7 +179,7 @@ public void testGetAndSetReadTimeout() {

apiClient.setReadTimeout(10000);
}

@Test
public void testGetAndSetWriteTimeout() {
// write timeout defaults to 10 seconds
Expand All @@ -191,7 +192,7 @@ public void testGetAndSetWriteTimeout() {

apiClient.setWriteTimeout(10000);
}

@Test
public void testParameterToPairWhenNameIsInvalid() throws Exception {
List<Pair> pairs_a = apiClient.parameterToPair(null, new Integer(1));
Expand Down Expand Up @@ -327,4 +328,25 @@ public void testSanitizeFilename() {
assertEquals("sun.gif", apiClient.sanitizeFilename("c:\\var\\tmp\\sun.gif"));
assertEquals("sun.gif", apiClient.sanitizeFilename(".\\sun.gif"));
}


@Test
public void testInterceptorCleanupWithNewClient() {
OkHttpClient oldClient = apiClient.getHttpClient();
assertEquals(1, oldClient.networkInterceptors().size());

OkHttpClient newClient = new OkHttpClient();
apiClient.setHttpClient(newClient);
assertEquals(1, apiClient.getHttpClient().networkInterceptors().size());
apiClient.setHttpClient(newClient);
assertEquals(1, apiClient.getHttpClient().networkInterceptors().size());
}

@Test
public void testInterceptorCleanupWithSameClient() {
OkHttpClient oldClient = apiClient.getHttpClient();
assertEquals(1, oldClient.networkInterceptors().size());
apiClient.setHttpClient(oldClient);
assertEquals(1, apiClient.getHttpClient().networkInterceptors().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -80,10 +83,7 @@ public void testCreateAndGetPet() throws Exception {
api.addPet(pet);

Pet fetched = api.getPetById(pet.getId());
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
assertPetMatches(pet, fetched);
}

@Test
Expand All @@ -95,10 +95,8 @@ public void testCreateAndGetPetWithHttpInfo() throws Exception {
assertEquals(200, resp.getStatusCode());
assertEquals("application/json", resp.getHeaders().get("Content-Type").get(0));
Pet fetched = resp.getData();
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());

assertPetMatches(pet, fetched);
}

@Test
Expand Down Expand Up @@ -146,10 +144,7 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
break;
}
} while (result.isEmpty());
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
assertPetMatches(pet, fetched);

// test getting a nonexistent pet
result.clear();
Expand Down Expand Up @@ -194,6 +189,65 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
assertEquals("application/json", exception.getResponseHeaders().get("Content-Type").get(0));
}

@Test
public void testCreateAndGetMultiplePetsAsync() throws Exception {
Pet pet1 = createPet();
Pet pet2 = createPet();

final CountDownLatch addLatch = new CountDownLatch(2);
final TestApiCallback<Void> addCallback1 = new TestApiCallback<Void>(addLatch);
final TestApiCallback<Void> addCallback2 = new TestApiCallback<Void>(addLatch);

// Make 2 simultaneous calls
api.addPetAsync(pet1, addCallback1);
api.addPetAsync(pet2, addCallback2);

// wait for both asynchronous calls to finish (at most 10 seconds)
assertTrue(addLatch.await(10, TimeUnit.SECONDS));

assertTrue(addCallback1.isDone());
assertTrue(addCallback2.isDone());

if (!addCallback1.isSuccess()) throw addCallback1.getException();
if (!addCallback2.isSuccess()) throw addCallback2.getException();

assertValidProgress(addCallback1.getUploadProgress());
assertValidProgress(addCallback2.getUploadProgress());

final CountDownLatch getLatch = new CountDownLatch(3);
final TestApiCallback<Pet> getCallback1 = new TestApiCallback<Pet>(getLatch);
final TestApiCallback<Pet> getCallback2 = new TestApiCallback<Pet>(getLatch);
final TestApiCallback<Pet> getCallback3 = new TestApiCallback<Pet>(getLatch);

api.getPetByIdAsync(pet1.getId(), getCallback1);
api.getPetByIdAsync(pet2.getId(), getCallback2);
// Get nonexistent pet
api.getPetByIdAsync(-10000L, getCallback3);

// wait for all asynchronous calls to finish (at most 10 seconds)
assertTrue(getLatch.await(10, TimeUnit.SECONDS));

assertTrue(getCallback1.isDone());
assertTrue(getCallback2.isDone());
assertTrue(getCallback3.isDone());

if (!getCallback1.isSuccess()) throw getCallback1.getException();
if (!getCallback2.isSuccess()) throw getCallback2.getException();

assertPetMatches(pet1, getCallback1.getResult());
assertPetMatches(pet2, getCallback2.getResult());

assertValidProgress(getCallback1.getDownloadProgress());
assertValidProgress(getCallback2.getDownloadProgress());

// Last callback should fail with ApiException
assertFalse(getCallback3.isSuccess());
final ApiException exception = getCallback3.getException();
assertNotNull(exception);
assertEquals(404, exception.getCode());
}


@Test
public void testUpdatePet() throws Exception {
Pet pet = createPet();
Expand All @@ -202,10 +256,7 @@ public void testUpdatePet() throws Exception {
api.updatePet(pet);

Pet fetched = api.getPetById(pet.getId());
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
assertPetMatches(pet, fetched);
}

@Test
Expand Down Expand Up @@ -233,6 +284,7 @@ public void testFindPetsByStatus() throws Exception {
}

@Test
@Ignore
public void testFindPetsByTags() throws Exception {
Pet pet = createPet();
pet.setName("monster");
Expand Down Expand Up @@ -355,4 +407,127 @@ private String serializeJson(Object o, ApiClient apiClient) {
private <T> T deserializeJson(String json, Type type, ApiClient apiClient) {
return (T) apiClient.getJSON().deserialize(json, type);
}

private void assertPetMatches(Pet expected, Pet actual) {
assertNotNull(actual);
assertEquals(expected.getId(), actual.getId());
assertNotNull(actual.getCategory());
assertEquals(expected.getCategory().getName(),
actual.getCategory().getName());
}

/**
* Assert that the given upload/download progress list satisfies the
* following constraints:
*
* - List is not empty
* - Byte count should be nondecreasing
* - The last element, and only the last element, should have done=true
*/
private void assertValidProgress(List<Progress> progressList) {
assertFalse(progressList.isEmpty());

Progress prev = null;
int index = 0;
for (Progress progress : progressList) {
if (prev != null) {
if (prev.done || prev.bytes > progress.bytes) {
fail("Progress list out of order at index " + index
+ ": " + progressList);
}
}
prev = progress;
index += 1;
}

if (!prev.done) {
fail("Last progress item should have done=true: " + progressList);
}
}

private static class TestApiCallback<T> implements ApiCallback<T> {

private final CountDownLatch latch;
private final ConcurrentLinkedQueue<Progress> uploadProgress =
new ConcurrentLinkedQueue<Progress>();
private final ConcurrentLinkedQueue<Progress> downloadProgress =
new ConcurrentLinkedQueue<Progress>();

private boolean done;
private boolean success;
private ApiException exception;
private T result;

public TestApiCallback(CountDownLatch latch) {
this.latch = latch;
this.done = false;
}

@Override
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
exception = e;
this.done = true;
this.success = false;
latch.countDown();
}

@Override
public void onSuccess(T result, int statusCode, Map<String, List<String>> responseHeaders) {
this.result = result;
this.done = true;
this.success = true;
latch.countDown();
}

@Override
public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {
uploadProgress.add(new Progress(bytesWritten, contentLength, done));
}

@Override
public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {
downloadProgress.add(new Progress(bytesRead, contentLength, done));
}

public boolean isDone() {
return done;
}

public boolean isSuccess() {
return success;
}

public ApiException getException() {
return exception;
}

public T getResult() {
return result;
}

public List<Progress> getUploadProgress() {
return new ArrayList<Progress>(uploadProgress);
}

public List<Progress> getDownloadProgress() {
return new ArrayList<Progress>(downloadProgress);
}
}

private static class Progress {
public final long bytes;
public final long contentLength;
public final boolean done;

public Progress(long bytes, long contentLength, boolean done) {
this.bytes = bytes;
this.contentLength = contentLength;
this.done = done;
}

@Override
public String toString() {
return "<Progress " + bytes + " " + contentLength + " " + done + ">";
}
}
}
Loading

0 comments on commit da803dc

Please sign in to comment.