diff --git a/.github/workflows/test-java.yml b/.github/workflows/test-java.yml index 332bf1bb..8b305209 100644 --- a/.github/workflows/test-java.yml +++ b/.github/workflows/test-java.yml @@ -13,9 +13,9 @@ jobs: with: distribution: temurin java-version: 11 - - name: Run Gradle Tests + - name: Run gradle test uses: gradle/gradle-build-action@v2 with: gradle-version: 7.1.1 build-root-directory: ./clients/java - arguments: test + arguments: test --info diff --git a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java index 6d6a732c..af1f8770 100644 --- a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java +++ b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java @@ -137,6 +137,15 @@ public void localeDownloadTest() throws ApiException, IOException, InterruptedEx mockBackend.enqueue(mockResponse); + + Map nestedFormatOptionsMap = new HashMap<>(); + nestedFormatOptionsMap.put("nested_option", "sub_option"); + + Map formatOptionsMap = new HashMap<>(); + formatOptionsMap.put("omit_separator_space", "true"); + formatOptionsMap.put("fallback_language", "en"); + formatOptionsMap.put("more_options", nestedFormatOptionsMap); + String projectId = "MY_PROJECT_ID"; String id = "MY_ID"; String xPhraseAppOTP = null; @@ -151,7 +160,7 @@ public void localeDownloadTest() throws ApiException, IOException, InterruptedEx Boolean includeTranslatedKeys = null; Boolean keepNotranslateTags = null; Boolean convertEmoji = null; - Object formatOptions = null; + Object formatOptions = formatOptionsMap; String encoding = null; Boolean skipUnverifiedTranslations = null; Boolean includeUnverifiedTranslations = null; @@ -164,7 +173,8 @@ public void localeDownloadTest() throws ApiException, IOException, InterruptedEx Assert.assertEquals("Correct file contents", fileContents, body); RecordedRequest recordedRequest = mockBackend.takeRequest(); - Assert.assertEquals("Request path", "//projects/MY_PROJECT_ID/locales/MY_ID/download", recordedRequest.getPath()); + // for some reason with deep nested query params, ordering of query params change + Assert.assertEquals("Request path", "//projects/MY_PROJECT_ID/locales/MY_ID/download?format_options%5Bomit_separator_space%5D=true&format_options%5Bmore_options%5D%5Bnested_option%5D=sub_option&format_options%5Bfallback_language%5D=en", recordedRequest.getPath()); } /** diff --git a/doc/compiled.json b/doc/compiled.json index 7464b507..5c62104c 100644 --- a/doc/compiled.json +++ b/doc/compiled.json @@ -7450,7 +7450,9 @@ "schema": { "type": "object", "properties": {} - } + }, + "style": "deepObject", + "explode": true }, { "description": "Enforces a specific encoding on the file contents. Valid options are \"UTF-8\", \"UTF-16\" and \"ISO-8859-1\".", diff --git a/openapi-generator/templates/java/build.gradle.mustache b/openapi-generator/templates/java/build.gradle.mustache index 17eb378a..8b449e45 100644 --- a/openapi-generator/templates/java/build.gradle.mustache +++ b/openapi-generator/templates/java/build.gradle.mustache @@ -122,7 +122,7 @@ if(hasProperty('target') && target == 'android') { main = System.getProperty('mainClass') classpath = sourceSets.main.runtimeClasspath } - + task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource @@ -177,6 +177,12 @@ dependencies { testCompile "junit:junit:$junit_version" } +test { + testLogging { + outputs.upToDateWhen {false} + showStandardStreams = true + } +} publishing { publications { diff --git a/openapi-generator/templates/java/libraries/okhttp-gson/ApiClient.mustache b/openapi-generator/templates/java/libraries/okhttp-gson/ApiClient.mustache index 3969c08d..44f1275d 100644 --- a/openapi-generator/templates/java/libraries/okhttp-gson/ApiClient.mustache +++ b/openapi-generator/templates/java/libraries/okhttp-gson/ApiClient.mustache @@ -654,6 +654,27 @@ public class ApiClient { } } + public List mappedParameterToPairs(String name, Object parameter){ + List params = new ArrayList(); + + if(parameter instanceof Map){ + Map mappedParameter = (Map) parameter; + + for(Map.Entry entry : mappedParameter.entrySet()){ + String key = name + "[" + entry.getKey() + "]"; + Object value = entry.getValue(); + + {{! TODO check why nested params ordering is different }} + params.addAll(parsedMappedParams(key, value, new ArrayList())); + } + + } + + + return params; + } + + /** * Formats the specified query parameter to a list containing a single {@code Pair} object. * @@ -1445,4 +1466,21 @@ public class ApiClient { throw new AssertionError(e); } } + + private List parsedMappedParams(String key, Object value, List params){ + if(value instanceof Map){ + Map mappedValue = (Map) value; + + for(Map.Entry entry : mappedValue.entrySet()){ + String nestedKey = key + "[" + entry.getKey() + "]"; + parsedMappedParams(nestedKey, entry.getValue(), params); + } + } + else{ + params.add(new Pair(key, parameterToString(value))); + } + + return params; + } + } diff --git a/openapi-generator/templates/java/libraries/okhttp-gson/api.mustache b/openapi-generator/templates/java/libraries/okhttp-gson/api.mustache index bbbca63b..6481de25 100644 --- a/openapi-generator/templates/java/libraries/okhttp-gson/api.mustache +++ b/openapi-generator/templates/java/libraries/okhttp-gson/api.mustache @@ -100,7 +100,12 @@ public class {{classname}} { {{javaUtilPrefix}}List localVarCollectionQueryParams = new {{javaUtilPrefix}}ArrayList(); {{#queryParams}} if ({{paramName}} != null) { + {{#isDeepObject}} + localVarQueryParams.addAll(localVarApiClient.mappedParameterToPairs("{{baseName}}", {{paramName}})); + {{/isDeepObject}} + {{^isDeepObject}} {{#collectionFormat}}localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(localVarApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); + {{/isDeepObject}} } {{/queryParams}} diff --git a/paths/locales/download.yaml b/paths/locales/download.yaml index 456daabb..97b052a0 100644 --- a/paths/locales/download.yaml +++ b/paths/locales/download.yaml @@ -73,6 +73,8 @@ parameters: schema: type: object properties: {} + style: deepObject + explode: true - description: Enforces a specific encoding on the file contents. Valid options are "UTF-8", "UTF-16" and "ISO-8859-1". example: name: encoding