From 6e3d1e211f27011dbf9442c9045f25bcdef3e45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Fri, 22 Apr 2022 14:31:01 +0200 Subject: [PATCH 01/12] fix(javascript): add missing descriptions --- templates/javascript/model.mustache | 46 +++++++++-------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/templates/javascript/model.mustache b/templates/javascript/model.mustache index 9fc02af87c..4e965c3987 100644 --- a/templates/javascript/model.mustache +++ b/templates/javascript/model.mustache @@ -1,47 +1,29 @@ -{{#models}} -{{#model}} +{{#models}}{{#model}} {{#tsImports}} import { {{classname}} } from '{{filename}}'; {{/tsImports}} {{! We handle types that depend on other interfaces }} {{#interfaces.size}} -export type {{classname}} = {{#oneOf}}{{.}} {{^-last}}|{{/-last}} {{/oneOf}}{{#allOf}}{{.}} {{^-last}}&{{/-last}} {{/allOf}}; -{{/interfaces.size}} - -{{^interfaces}} {{#description}} /** * {{{description}}} -*/ -{{/description}} -{{^isEnum}} -export type {{classname}} = {{#parent}} {{{.}}} & {{/parent}} { -{{#vars}} +*/{{/description}} +export type {{classname}} = {{#oneOf}}{{{.}}} {{^-last}}|{{/-last}} {{/oneOf}}{{#allOf}}{{{.}}} {{^-last}}&{{/-last}} {{/allOf}}; +{{/interfaces.size}}{{^interfaces.size}} {{#description}} +/** +* {{{description}}} +*/{{/description}}{{^isEnum}} +export type {{classname}} = {{#parent}} {{{.}}} & {{/parent}} { +{{#vars}}{{#description}} /** * {{{description}}} - */ -{{/description}} - {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{classname}}{{{nameInCamelCase}}}{{#isArray}}[]{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}; -{{/vars}} + */{{/description}} + {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{classname}}{{{nameInCamelCase}}}{{#isArray}}[]{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};{{/vars}} } - -{{#hasEnums}} -{{#vars}} -{{#isEnum}} -export type {{classname}}{{nameInCamelCase}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}} - -{{/isEnum}} -{{/vars}} -{{/hasEnums}} -{{/isEnum}} - -{{#isEnum}} -export type {{classname}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}} - {{/isEnum}} +{{#hasEnums}}{{#vars}}{{#isEnum}}export type {{classname}}{{nameInCamelCase}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}}{{/isEnum}}{{/vars}}{{/hasEnums}} +{{#isEnum}}export type {{classname}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}}{{/isEnum}} -{{/interfaces}} -{{/model}} -{{/models}} +{{/interfaces.size}}{{/model}}{{/models}} From d2d08d8120a2ac2cc70fe83acb9d6377800f16eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Fri, 22 Apr 2022 16:51:58 +0200 Subject: [PATCH 02/12] fix(spec): better filters type --- .../codegen/cts/ParametersWithDataType.java | 33 ++++++++- specs/common/schemas/SearchParams.yml | 71 +++++++++++++------ specs/search/common/schemas/Hit.yml | 61 +++++++++++----- .../methods/requests/recommend.test.java | 32 ++++++--- 4 files changed, 149 insertions(+), 48 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java index bf93cade72..3efd26af79 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java +++ b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java @@ -6,6 +6,7 @@ import io.swagger.util.Json; import java.util.*; import java.util.Map.Entry; +import org.openapitools.codegen.CodegenComposedSchemas; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenParameter; @@ -205,7 +206,24 @@ private void handleModel( int suffix ) throws CTSException { if (!spec.getHasVars()) { - throw new CTSException("Spec has no vars."); + // In this case we might have a complex `allOf`, we will first check + // if it exists + CodegenComposedSchemas composedSchemas = spec.getComposedSchemas(); + + if (composedSchemas != null) { + List allOf = composedSchemas.getAllOf(); + + if (allOf != null && !allOf.isEmpty()) { + traverseParams(paramName, param, allOf.get(0), parent, suffix); + + return; + } + } + // We only throw if there is no `composedSchemas`, because `oneOf` can also + // be handled below + else { + throw new CTSException("Spec has no vars."); + } } if (spec.getItems() != null) { @@ -466,7 +484,18 @@ private IJsonSchemaValidationProperties findMatchingOneOf( return bestOneOf; } if (param instanceof List) { - // no idea for list + // NICE ---> no idea for list <--- NICE + CodegenComposedSchemas composedSchemas = model.getComposedSchemas(); + + if (composedSchemas != null) { + List oneOf = composedSchemas.getOneOf(); + + // Somehow this is not yet enough + if (oneOf != null && !oneOf.isEmpty()) { + return oneOf.get(0); + } + } + return null; } diff --git a/specs/common/schemas/SearchParams.yml b/specs/common/schemas/SearchParams.yml index 49d7ead6a1..d83e550b5c 100644 --- a/specs/common/schemas/SearchParams.yml +++ b/specs/common/schemas/SearchParams.yml @@ -30,31 +30,14 @@ baseSearchParams: type: string description: Filter the query with numeric, facet and/or tag filters. default: '' - # There could be a pattern for this one (complicated one) facetFilters: - type: array - items: - type: string - description: Filter hits by facet value. - default: [] + $ref: '#/facetFilters' optionalFilters: - type: array - items: - type: string - description: Create filters for ranking purposes, where records that match the filter are ranked higher, or lower in the case of a negative optional filter. - default: [] + $ref: '#/optionalFilters' numericFilters: - type: array - items: - type: string - description: Filter on numeric attributes. - default: [] + $ref: '#/numericFilters' tagFilters: - type: array - items: - type: string - description: Filter hits by tags. - default: [] + $ref: '#/tagFilters' sumOrFiltersScores: type: boolean description: Determines how to calculate the total score for filtering. @@ -164,6 +147,8 @@ baseSearchParams: type: boolean description: Whether this search should use AI Re-Ranking. default: true + reRankingApplyFilter: + $ref: '#/reRankingApplyFilter' searchParamsString: type: object @@ -202,3 +187,47 @@ aroundRadius: aroundRadiusAll: type: string enum: [all] + +# There is duplicated logic here because we want to keep a correct description +# and using `$ref` override everything. +searchFiltersArrayString: + type: array + items: + type: string + +searchFiltersNestedArrayString: + type: array + items: + type: array + items: + type: string + +facetFilters: + description: Filter hits by facet value. + oneOf: + - $ref: '#/searchFiltersArrayString' + - $ref: '#/searchFiltersNestedArrayString' + +reRankingApplyFilter: + description: When Dynamic Re-Ranking is enabled, only records that match these filters will be impacted by Dynamic Re-Ranking. + oneOf: + - $ref: '#/searchFiltersArrayString' + - $ref: '#/searchFiltersNestedArrayString' + +tagFilters: + description: Filter hits by tags. + oneOf: + - $ref: '#/searchFiltersArrayString' + - $ref: '#/searchFiltersNestedArrayString' + +numericFilters: + description: Filter on numeric attributes. + oneOf: + - $ref: '#/searchFiltersArrayString' + - $ref: '#/searchFiltersNestedArrayString' + +optionalFilters: + description: Create filters for ranking purposes, where records that match the filter are ranked higher, or lower in the case of a negative optional filter. + oneOf: + - $ref: '#/searchFiltersArrayString' + - $ref: '#/searchFiltersNestedArrayString' diff --git a/specs/search/common/schemas/Hit.yml b/specs/search/common/schemas/Hit.yml index 2fbf258e75..cbc0c5ab19 100644 --- a/specs/search/common/schemas/Hit.yml +++ b/specs/search/common/schemas/Hit.yml @@ -64,22 +64,9 @@ rankingInfo: type: integer description: Precision used when computing the geo distance, in meters. matchedGeoLocation: - type: object - additionalProperties: - type: object - additionalProperties: false - properties: - lat: - type: number - format: double - description: Latitude of the matched location. - lng: - type: number - format: double - description: Longitude of the matched location. - distance: - type: integer - description: Distance between the matched location and the search location (in meters). + $ref: '#/matchedGeoLocation' + personalization: + $ref: '#/personalization' nbExactWords: type: integer description: Number of exactly matched words. @@ -95,9 +82,21 @@ rankingInfo: userScore: type: integer description: Custom ranking for the object, expressed as a single integer value. - word: + words: type: integer description: Number of matched words, including prefixes and typos. + promotedByReRanking: + type: boolean + description: Wether the record are promoted by the re-ranking strategy. + required: + - promoted + - nbTypos + - firstMatchedWord + - geoDistance + - nbExactWords + - words + - filters + - userScore highlightedValue: type: string @@ -108,3 +107,31 @@ matchLevel: type: string description: Indicates how well the attribute matched the search query. enum: [none, partial, full] + +matchedGeoLocation: + type: object + properties: + lat: + type: number + format: double + description: Latitude of the matched location. + lng: + type: number + format: double + description: Longitude of the matched location. + distance: + type: integer + description: Distance between the matched location and the search location (in meters). + +personalization: + type: object + properties: + filtersScore: + type: integer + description: The score of the filters. + rankingScore: + type: integer + description: The score of the ranking. + score: + type: integer + description: The score of the event. diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java index 1ed96929b5..a520368f5e 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java @@ -234,7 +234,9 @@ void getRecommendationsTest1() { facetFilters4.add(facetFilters_05); } - queryParameters3.setFacetFilters(facetFilters4); + queryParameters3.setFacetFilters( + FacetFilters.ofList(facetFilters4) + ); } requests_02.setQueryParameters(queryParameters3); @@ -250,7 +252,9 @@ void getRecommendationsTest1() { facetFilters4.add(facetFilters_05); } - fallbackParameters3.setFacetFilters(facetFilters4); + fallbackParameters3.setFacetFilters( + FacetFilters.ofList(facetFilters4) + ); } requests_02.setFallbackParameters(fallbackParameters3); } @@ -364,7 +368,9 @@ void getRecommendationsTest3() { facetFilters4.add(facetFilters_05); } - queryParameters3.setFacetFilters(facetFilters4); + queryParameters3.setFacetFilters( + FacetFilters.ofList(facetFilters4) + ); } requests_02.setQueryParameters(queryParameters3); @@ -380,7 +386,9 @@ void getRecommendationsTest3() { facetFilters4.add(facetFilters_05); } - fallbackParameters3.setFacetFilters(facetFilters4); + fallbackParameters3.setFacetFilters( + FacetFilters.ofList(facetFilters4) + ); } requests_02.setFallbackParameters(fallbackParameters3); } @@ -521,7 +529,9 @@ void getRecommendationsTest5() { facetFilters4.add(facetFilters_05); } - queryParameters3.setFacetFilters(facetFilters4); + queryParameters3.setFacetFilters( + FacetFilters.ofList(facetFilters4) + ); } requests_02.setQueryParameters(queryParameters3); @@ -537,7 +547,9 @@ void getRecommendationsTest5() { facetFilters4.add(facetFilters_05); } - fallbackParameters3.setFacetFilters(facetFilters4); + fallbackParameters3.setFacetFilters( + FacetFilters.ofList(facetFilters4) + ); } requests_02.setFallbackParameters(fallbackParameters3); } @@ -580,7 +592,9 @@ void getRecommendationsTest5() { facetFilters4.add(facetFilters_05); } - queryParameters3.setFacetFilters(facetFilters4); + queryParameters3.setFacetFilters( + FacetFilters.ofList(facetFilters4) + ); } requests_12.setQueryParameters(queryParameters3); @@ -596,7 +610,9 @@ void getRecommendationsTest5() { facetFilters4.add(facetFilters_05); } - fallbackParameters3.setFacetFilters(facetFilters4); + fallbackParameters3.setFacetFilters( + FacetFilters.ofList(facetFilters4) + ); } requests_12.setFallbackParameters(fallbackParameters3); } From afa41a2413cbcf8f936e387ea58d281c235cdcb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Mon, 25 Apr 2022 16:49:11 +0200 Subject: [PATCH 03/12] fix CTS gen --- .github/.cache_version | 2 +- .../algolia/codegen/AlgoliaJavaGenerator.java | 6 +-- .../codegen/cts/ParametersWithDataType.java | 18 ++++++-- tests/CTS/methods/requests/search/search.json | 24 +++++++++++ .../templates/java/maybeConvertOneOf.mustache | 2 +- .../methods/requests/recommend.test.java | 16 +++---- .../algolia/methods/requests/search.test.java | 42 ++++++++++++++++++- .../src/methods/requests/search.test.ts | 17 +++++++- 8 files changed, 108 insertions(+), 19 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 7262faa78c..aec5790408 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -8.0.5.2 +76264f26-7ad7-4fae-9bda-5e96b9cd04eb diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java index aa6fb301ac..1dee5bf771 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java @@ -152,7 +152,7 @@ public Map postProcessAllModels(Map objs) { .get(0) .get("model"); if (!model.oneOf.isEmpty()) { - List> listOneOf = new ArrayList(); + List> oneOfList = new ArrayList(); for (String iterateModel : model.oneOf) { HashMap oneOfModel = new HashMap(); @@ -163,11 +163,11 @@ public Map postProcessAllModels(Map objs) { iterateModel.replace("<", "").replace(">", "") ); - listOneOf.add(oneOfModel); + oneOfList.add(oneOfModel); } model.vendorExtensions.put("x-is-one-of-interface", true); - model.vendorExtensions.put("x-is-one-of-list", listOneOf); + model.vendorExtensions.put("x-is-one-of-list", oneOfList); } } diff --git a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java index 3efd26af79..729466fd40 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java +++ b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java @@ -242,12 +242,22 @@ private void handleModel( ); HashMap oneOfModel = new HashMap<>(); + String typeName = getTypeName(match).replace("<", "").replace(">", ""); oneOfModel.put("classname", Utils.capitalize(baseType)); - oneOfModel.put( - "name", - getTypeName(match).replace("<", "").replace(">", "") - ); + + if (typeName.equals("List")) { + Json.prettyPrint(match); + CodegenProperty items = match.getItems(); + + if (items == null) { + throw new CTSException("Unhandled case for empty oneOf List items."); + } + + typeName += getTypeName(items); + } + + oneOfModel.put("name", typeName); testOutput.put("oneOfModel", oneOfModel); return; diff --git a/tests/CTS/methods/requests/search/search.json b/tests/CTS/methods/requests/search/search.json index 59e762fc6e..4f7f0c1317 100644 --- a/tests/CTS/methods/requests/search/search.json +++ b/tests/CTS/methods/requests/search/search.json @@ -1,6 +1,7 @@ [ { "method": "search", + "testName": "search with minimal parameters", "parameters": { "indexName": "indexName", "searchParams": { @@ -14,5 +15,28 @@ "query": "myQuery" } } + }, + { + "method": "search", + "testName": "search with facetFilters", + "parameters": { + "indexName": "indexName", + "searchParams": { + "query": "myQuery", + "facetFilters": [ + "tags:algolia" + ] + } + }, + "request": { + "path": "/1/indexes/indexName/query", + "method": "POST", + "data": { + "query": "myQuery", + "facetFilters": [ + "tags:algolia" + ] + } + } } ] diff --git a/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache b/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache index 8fbf61e976..2b9b0436a5 100644 --- a/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache +++ b/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache @@ -1 +1 @@ -{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}} \ No newline at end of file +{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java index a520368f5e..bbc86aeda7 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java @@ -235,7 +235,7 @@ void getRecommendationsTest1() { facetFilters4.add(facetFilters_05); } queryParameters3.setFacetFilters( - FacetFilters.ofList(facetFilters4) + FacetFilters.ofListString(facetFilters4) ); } requests_02.setQueryParameters(queryParameters3); @@ -253,7 +253,7 @@ void getRecommendationsTest1() { facetFilters4.add(facetFilters_05); } fallbackParameters3.setFacetFilters( - FacetFilters.ofList(facetFilters4) + FacetFilters.ofListString(facetFilters4) ); } requests_02.setFallbackParameters(fallbackParameters3); @@ -369,7 +369,7 @@ void getRecommendationsTest3() { facetFilters4.add(facetFilters_05); } queryParameters3.setFacetFilters( - FacetFilters.ofList(facetFilters4) + FacetFilters.ofListString(facetFilters4) ); } requests_02.setQueryParameters(queryParameters3); @@ -387,7 +387,7 @@ void getRecommendationsTest3() { facetFilters4.add(facetFilters_05); } fallbackParameters3.setFacetFilters( - FacetFilters.ofList(facetFilters4) + FacetFilters.ofListString(facetFilters4) ); } requests_02.setFallbackParameters(fallbackParameters3); @@ -530,7 +530,7 @@ void getRecommendationsTest5() { facetFilters4.add(facetFilters_05); } queryParameters3.setFacetFilters( - FacetFilters.ofList(facetFilters4) + FacetFilters.ofListString(facetFilters4) ); } requests_02.setQueryParameters(queryParameters3); @@ -548,7 +548,7 @@ void getRecommendationsTest5() { facetFilters4.add(facetFilters_05); } fallbackParameters3.setFacetFilters( - FacetFilters.ofList(facetFilters4) + FacetFilters.ofListString(facetFilters4) ); } requests_02.setFallbackParameters(fallbackParameters3); @@ -593,7 +593,7 @@ void getRecommendationsTest5() { facetFilters4.add(facetFilters_05); } queryParameters3.setFacetFilters( - FacetFilters.ofList(facetFilters4) + FacetFilters.ofListString(facetFilters4) ); } requests_12.setQueryParameters(queryParameters3); @@ -611,7 +611,7 @@ void getRecommendationsTest5() { facetFilters4.add(facetFilters_05); } fallbackParameters3.setFacetFilters( - FacetFilters.ofList(facetFilters4) + FacetFilters.ofListString(facetFilters4) ); } requests_12.setFallbackParameters(fallbackParameters3); diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java index c3e9bcdc4a..dafbcceb5e 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java @@ -2098,7 +2098,7 @@ void saveSynonymsTest0() { } @Test - @DisplayName("search") + @DisplayName("search with minimal parameters") void searchTest0() { String indexName0 = "indexName"; @@ -2129,6 +2129,46 @@ void searchTest0() { }); } + @Test + @DisplayName("search with facetFilters") + void searchTest1() { + String indexName0 = "indexName"; + + SearchParamsObject searchParams0 = new SearchParamsObject(); + { + String query1 = "myQuery"; + + searchParams0.setQuery(query1); + + List facetFilters1 = new ArrayList<>(); + { + String facetFilters_02 = "tags:algolia"; + + facetFilters1.add(facetFilters_02); + } + searchParams0.setFacetFilters(FacetFilters.ofListString(facetFilters1)); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.search( + indexName0, + SearchParams.ofSearchParamsObject(searchParams0) + ); + } + ); + + assertEquals(req.getPath(), "/1/indexes/indexName/query"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"query\":\"myQuery\",\"facetFilters\":[\"tags:algolia\"]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + @Test @DisplayName("get searchDictionaryEntries results with minimal parameters") void searchDictionaryEntriesTest0() { diff --git a/tests/output/javascript/src/methods/requests/search.test.ts b/tests/output/javascript/src/methods/requests/search.test.ts index bf914390b5..b06e82288a 100644 --- a/tests/output/javascript/src/methods/requests/search.test.ts +++ b/tests/output/javascript/src/methods/requests/search.test.ts @@ -1011,7 +1011,7 @@ describe('saveSynonyms', () => { }); describe('search', () => { - test('search', async () => { + test('search with minimal parameters', async () => { const req = (await client.search({ indexName: 'indexName', searchParams: { query: 'myQuery' }, @@ -1022,6 +1022,21 @@ describe('search', () => { expect(req.data).toEqual({ query: 'myQuery' }); expect(req.searchParams).toEqual(undefined); }); + + test('search with facetFilters', async () => { + const req = (await client.search({ + indexName: 'indexName', + searchParams: { query: 'myQuery', facetFilters: ['tags:algolia'] }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/indexes/indexName/query'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ + query: 'myQuery', + facetFilters: ['tags:algolia'], + }); + expect(req.searchParams).toEqual(undefined); + }); }); describe('searchDictionaryEntries', () => { From 4c85d84b1f21c2486b82c90b805e8c7980f20d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Mon, 25 Apr 2022 17:57:48 +0200 Subject: [PATCH 04/12] review --- .../java/com/algolia/codegen/cts/ParametersWithDataType.java | 1 - .../methods/requests/templates/java/maybeConvertOneOf.mustache | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java index 729466fd40..f20ef92492 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java +++ b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java @@ -247,7 +247,6 @@ private void handleModel( oneOfModel.put("classname", Utils.capitalize(baseType)); if (typeName.equals("List")) { - Json.prettyPrint(match); CodegenProperty items = match.getItems(); if (items == null) { diff --git a/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache b/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache index 2b9b0436a5..8fbf61e976 100644 --- a/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache +++ b/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache @@ -1 +1 @@ -{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}} +{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}} \ No newline at end of file From 885caa81019d5ce0be6a24b06b485fb1d09f2e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 26 Apr 2022 09:28:34 +0200 Subject: [PATCH 05/12] cache path --- .github/.cache_version | 2 +- .github/workflows/check.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 570b8488eb..65e5f62229 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -8.0.10.9 +8.0.10.11111111 diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e12a123ce9..7f9314a968 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -222,7 +222,7 @@ jobs: with: path: | ${{ format('{0}/algoliasearch-core/src/com/algolia/api/{1}.java', matrix.client.path, matrix.client.api) }} - ${{ format('{0}/{1}/**', matrix.client.path, matrix.client.capitalizedName) }} + ${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.capitalizedName) }} key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( From d8e0de3f4635ccc1d8d4f796161694aa737038d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 26 Apr 2022 09:40:38 +0200 Subject: [PATCH 06/12] cache path part 2 --- .github/.cache_version | 2 +- .github/workflows/check.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 65e5f62229..488e74a676 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -8.0.10.11111111 +8.0.10.11111112 diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7f9314a968..f3e083ae75 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -222,7 +222,7 @@ jobs: with: path: | ${{ format('{0}/algoliasearch-core/src/com/algolia/api/{1}.java', matrix.client.path, matrix.client.api) }} - ${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.capitalizedName) }} + ${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.name) }} key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( From b52c93526a98f54b0c2399506a4a37d43d75dd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 26 Apr 2022 09:54:06 +0200 Subject: [PATCH 07/12] add camlizedName --- .github/workflows/check.yml | 2 +- scripts/ci/createMatrix.ts | 27 +++++++++++++-------------- scripts/cts/utils.ts | 34 +++++++++++++++++++++++++++++----- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index f3e083ae75..5d6fcb27a7 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -222,7 +222,7 @@ jobs: with: path: | ${{ format('{0}/algoliasearch-core/src/com/algolia/api/{1}.java', matrix.client.path, matrix.client.api) }} - ${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.name) }} + ${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.camelizedName) }} key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( diff --git a/scripts/ci/createMatrix.ts b/scripts/ci/createMatrix.ts index a5920bc8f0..74143bd598 100644 --- a/scripts/ci/createMatrix.ts +++ b/scripts/ci/createMatrix.ts @@ -1,5 +1,5 @@ import { CLIENTS, GENERATORS } from '../common'; -import { createClientName } from '../cts/utils'; +import { camelize, createClientName } from '../cts/utils'; import type { Language } from '../types'; import { getNbGitDiff } from './utils'; @@ -16,9 +16,10 @@ type BaseMatrix = { }; type ClientMatrix = BaseMatrix & { - config?: string; - api?: string; - capitalizedName?: string; + config: string; + api: string; + capitalizedName: string; + camelizedName: string; }; type SpecMatrix = BaseMatrix; @@ -56,18 +57,16 @@ async function getClientMatrix({ continue; } - const matchedGenerator: ClientMatrix = { - name: client, - path: output, - }; - const clientName = createClientName(client, language); - matchedGenerator.config = `${clientName}Config`; - matchedGenerator.api = `${clientName}Client`; - matchedGenerator.capitalizedName = clientName; - - matrix.client.push(matchedGenerator); + matrix.client.push({ + name: client, + path: output, + config: `${clientName}Config`, + api: `${clientName}Client`, + capitalizedName: clientName, + camelizedName: camelize(client), + }); } return matrix; diff --git a/scripts/cts/utils.ts b/scripts/cts/utils.ts index 18968d7b20..5871b9976d 100644 --- a/scripts/cts/utils.ts +++ b/scripts/cts/utils.ts @@ -14,23 +14,47 @@ export async function* walk( } } +/** + * Sets the first letter of the given string in capital. + * + * `searchClient` -> `SearchClient`. + */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.slice(1); } -export function createClientName(client: string, language: string): string { - const clientName = client - .split('-') +/** + * Splits a string for a given `delimiter` (defaults to `-`) and capitalize each + * parts except the first letter. + * + * `search-client` -> `searchClient`. + */ +export function camelize(str: string, delimiter: string = '-'): string { + return str + .split(delimiter) .map((part, i) => { - if (language === 'javascript' && i === 0) { + if (i === 0) { return part; } return capitalize(part); }) .join(''); +} + +/** + * Returns the client name with the correct casing for its language. + * + * `search-client`, `java` -> `SearchClient`. + * + * `search-client`, `javascript` -> `searchClient`. + */ +export function createClientName(client: string, language: string): string { + if (language === 'javascript') { + return camelize(client); + } - return clientName; + return capitalize(camelize(client)); } export async function createOutputDir({ From 24cc1145012892d5d901961d13efeaf1ad41f799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 26 Apr 2022 10:07:39 +0200 Subject: [PATCH 08/12] iwillpeterunboulon --- .github/.cache_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/.cache_version b/.github/.cache_version index 488e74a676..641a734e55 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -8.0.10.11111112 +ifYouAreReadingThisItIsTooLate From cced2ebc807468157ef4ad17480d245e09b75d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 26 Apr 2022 10:57:38 +0200 Subject: [PATCH 09/12] test push --- .github/.cache_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/.cache_version b/.github/.cache_version index 641a734e55..7979d80833 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -ifYouAreReadingThisItIsTooLate +ifYouAreReadingThisItIsTooLatePart2 From e7da8d2017badda2e7e8a32d5f8285b2b64cd438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 26 Apr 2022 12:42:54 +0200 Subject: [PATCH 10/12] test build specs --- .github/.cache_version | 2 +- scripts/index.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 7979d80833..16fd70c535 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -ifYouAreReadingThisItIsTooLatePart2 +ifYouAreReadingThisItIsTooLatePart3 diff --git a/scripts/index.ts b/scripts/index.ts index caf2030dab..ff4ca8329b 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -194,12 +194,7 @@ buildCommand clientsTodo = CLIENTS; } // ignore cache when building from cli - await buildSpecs( - clientsTodo, - outputFormat!, - Boolean(verbose), - !skipCache - ); + await buildSpecs(clientsTodo, outputFormat, Boolean(verbose), !skipCache); } ); @@ -227,6 +222,10 @@ ctsCommand language = await promptLanguage(language, interactive); client = await promptClient(client, interactive); + if (CI) { + await buildSpecs(CLIENTS, 'yml', Boolean(verbose), true); + } + await ctsGenerateMany( generatorList({ language, client }), Boolean(verbose) From 4f8d75c87aac651d856ec12d39a85b7675f7df13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 26 Apr 2022 13:16:11 +0200 Subject: [PATCH 11/12] retrieve code from gen branch? --- .github/.cache_version | 2 +- scripts/ci/codegen/pushGeneratedCode.ts | 1 + scripts/index.ts | 4 ---- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 16fd70c535..33a066e8e4 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -ifYouAreReadingThisItIsTooLatePart3 +ifYouAreReadingThisItIsTooLatePart4 diff --git a/scripts/ci/codegen/pushGeneratedCode.ts b/scripts/ci/codegen/pushGeneratedCode.ts index 18c5894ba7..67f7f886b4 100644 --- a/scripts/ci/codegen/pushGeneratedCode.ts +++ b/scripts/ci/codegen/pushGeneratedCode.ts @@ -81,6 +81,7 @@ Co-authored-by: %an <%ae> if (PR_NUMBER) { await run(`git checkout ${baseBranch}`); + await run(`git checkout ${branchToPush} -- ${FOLDERS_TO_CHECK}`); await run(`yarn workspace scripts upsertGenerationComment codegen`); } } diff --git a/scripts/index.ts b/scripts/index.ts index ff4ca8329b..97dc0cab0a 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -222,10 +222,6 @@ ctsCommand language = await promptLanguage(language, interactive); client = await promptClient(client, interactive); - if (CI) { - await buildSpecs(CLIENTS, 'yml', Boolean(verbose), true); - } - await ctsGenerateMany( generatorList({ language, client }), Boolean(verbose) From 7439f69edc309d4b1911511f5892cf9fc98157df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 26 Apr 2022 13:45:55 +0200 Subject: [PATCH 12/12] remove checkout files --- scripts/ci/codegen/pushGeneratedCode.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/ci/codegen/pushGeneratedCode.ts b/scripts/ci/codegen/pushGeneratedCode.ts index 67f7f886b4..18c5894ba7 100644 --- a/scripts/ci/codegen/pushGeneratedCode.ts +++ b/scripts/ci/codegen/pushGeneratedCode.ts @@ -81,7 +81,6 @@ Co-authored-by: %an <%ae> if (PR_NUMBER) { await run(`git checkout ${baseBranch}`); - await run(`git checkout ${branchToPush} -- ${FOLDERS_TO_CHECK}`); await run(`yarn workspace scripts upsertGenerationComment codegen`); } }