Skip to content

Commit

Permalink
fix(specs): ignorePlurals can be a boolean string (#3620)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp committed Aug 30, 2024
1 parent 0eda99a commit 3d07a1e
Show file tree
Hide file tree
Showing 23 changed files with 178 additions and 664 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ module.exports = {
},
{
files: ['*.json'],

plugins: ['json-format'],
parserOptions: {
extraFileExtensions: ['.json'],
},
extends: ["plugin:json/recommended-legacy"]
},
{
files: ['templates/**/*.mustache'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def convert_to_type(data, return_type)
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
end
else
# models (e.g. Pet) or oneOf
# models (e.g. Pet), enum, or oneOf
klass = Algolia.const_get(return_type)
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
end
Expand Down
3 changes: 2 additions & 1 deletion eslint/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
},
"include": [
"src/**/*.ts",
"tests/**/*.ts"
"tests/**/*.ts",
"package.json",
],
"exclude": [
"node_modules",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen {
"basesearchresponse",
"batchrequest",
"batchwriteparams",
"booleanstring",
"condition",
"configuration",
"consequence",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsdoc": "50.2.2",
"eslint-plugin-json-format": "2.0.1",
"eslint-plugin-json": "4.0.1",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-unused-imports": "3.2.0",
"eslint-plugin-yml": "1.14.0",
Expand Down
7 changes: 7 additions & 0 deletions specs/common/schemas/IndexSettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ ignorePlurals:
This overrides languages you set with `queryLanguages`.
items:
$ref: '#/supportedLanguage'
- $ref: '#/booleanString'
- type: boolean
description: |
If true, `ignorePlurals` is active for all languages included in `queryLanguages`, or for all supported languages, if `queryLanguges` is empty.
Expand Down Expand Up @@ -1168,3 +1169,9 @@ supportedLanguage:
- ur
- uz
- zh

booleanString:
type: string
enum:
- 'true'
- 'false'
2 changes: 1 addition & 1 deletion templates/go/tests/e2e/e2e.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}E2E_{{#lambda
err = json.Unmarshal([]byte(expectedBodyRaw), &expectedBody)
require.NoError(t, err)

unionBody := tests.Union(expectedBody, rawBodyMap)
unionBody := tests.Union(t, expectedBody, rawBodyMap)
unionBodyRaw, err := json.Marshal(unionBody)
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
BaseSearchParams,
BaseSearchParamsWithoutQuery,
BaseSearchResponse,
BooleanString,
Condition,
Consequence,
ConsequenceHide,
Expand Down Expand Up @@ -104,6 +105,7 @@ export {
BaseSearchParams,
BaseSearchParamsWithoutQuery,
BaseSearchResponse,
BooleanString,
Condition,
Consequence,
ConsequenceHide,
Expand Down
24 changes: 0 additions & 24 deletions templates/ruby/partial_model_generic.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,6 @@
attr_accessor :additional_properties

{{/getAdditionalPropertiesIsAnyType}}
{{#hasEnums}}
class EnumAttributeValidator
attr_reader :datatype
attr_reader :allowable_values

def initialize(datatype, allowable_values)
@allowable_values = allowable_values.map do |value|
case datatype.to_s
when /Integer/i
value.to_i
when /Float/i
value.to_f
else
value
end
end
end

def valid?(value)
!value || allowable_values.include?(value)
end
end

{{/hasEnums}}
# Attribute mapping from ruby-style variable name to JSON key.
def self.attribute_map
{
Expand Down
8 changes: 6 additions & 2 deletions templates/ruby/partial_oneof_module.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,16 @@
else # model
const = {{moduleName}}::{{modelModule}}.const_get(klass)
if const
if const.respond_to?(:openapi_one_of) # nested oneOf model
if const.respond_to?(:openapi_one_of)
# nested oneOf model
model = const.build(data)
else
elsif const.respond_to?(:acceptable_attributes)
# raise if data contains keys that are not known to the model
raise unless (data.keys - const.acceptable_attributes).empty?
model = const.build_from_hash(data)
else
# maybe it's an enum
model = const.build_from_hash(data)
end

return model if model
Expand Down
35 changes: 32 additions & 3 deletions tests/CTS/requests/search/getRule.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
[
{
"parameters": {
"indexName": "indexName",
"objectID": "id1"
"indexName": "cts_e2e_browse",
"objectID": "qr-1725004648916"
},
"request": {
"path": "/1/indexes/indexName/rules/id1",
"path": "/1/indexes/cts_e2e_browse/rules/qr-1725004648916",
"method": "GET"
},
"response": {
"statusCode": 200,
"body": {
"description": "test_rule",
"enabled": true,
"objectID": "qr-1725004648916",
"conditions": [
{
"alternatives": true,
"anchoring": "contains",
"pattern": "zorro"
}
],
"consequence": {
"params": {
"ignorePlurals": "true"
},
"filterPromotes": true,
"promote": [
{
"objectIDs": [
"\u00C6on Flux"
],
"position": 0
}
]
}
}
}
}
]
44 changes: 40 additions & 4 deletions tests/CTS/requests/search/searchRules.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
[
{
"parameters": {
"indexName": "indexName",
"indexName": "cts_e2e_browse",
"searchRulesParams": {
"query": "something"
"query": "zorro"
}
},
"request": {
"path": "/1/indexes/indexName/rules/search",
"path": "/1/indexes/cts_e2e_browse/rules/search",
"method": "POST",
"body": {
"query": "something"
"query": "zorro"
}
},
"response": {
"statusCode": 200,
"body": {
"hits": [
{
"conditions": [
{
"alternatives": true,
"anchoring": "contains",
"pattern": "zorro"
}
],
"consequence": {
"params": {
"ignorePlurals": "true"
},
"filterPromotes": true,
"promote": [
{
"objectIDs": [
"\u00C6on Flux"
],
"position": 0
}
]
},
"description": "test_rule",
"enabled": true,
"objectID": "qr-1725004648916"
}
],
"nbHits": 1,
"nbPages": 1,
"page": 0
}
}
}
Expand Down
68 changes: 0 additions & 68 deletions tests/output/csharp/src/generated/e2e/Analytics.test.cs

This file was deleted.

61 changes: 0 additions & 61 deletions tests/output/go/tests/e2e/analytics_test.go

This file was deleted.

Loading

0 comments on commit 3d07a1e

Please sign in to comment.