Skip to content

Commit

Permalink
fix(specs): consequence is required when saving rules (#4146) (gene…
Browse files Browse the repository at this point in the history
…rated) [skip ci]

Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
  • Loading branch information
algolia-bot and shortcuts committed Nov 26, 2024
1 parent b728c5f commit df93536
Show file tree
Hide file tree
Showing 50 changed files with 580 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public Rule() { }
/// Initializes a new instance of the Rule class.
/// </summary>
/// <param name="objectID">Unique identifier of a rule object. (required).</param>
public Rule(string objectID)
/// <param name="consequence">consequence (required).</param>
public Rule(string objectID, Consequence consequence)
{
ObjectID = objectID ?? throw new ArgumentNullException(nameof(objectID));
Consequence = consequence ?? throw new ArgumentNullException(nameof(consequence));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Rule {
const Rule({
required this.objectID,
this.conditions,
this.consequence,
required this.consequence,
this.description,
this.enabled,
this.validity,
Expand All @@ -29,7 +29,7 @@ final class Rule {
final List<Condition>? conditions;

@JsonKey(name: r'consequence')
final Consequence? consequence;
final Consequence consequence;

/// Description of the rule's purpose to help you distinguish between different rules.
@JsonKey(name: r'description')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 14 additions & 27 deletions clients/algoliasearch-client-go/algolia/search/model_rule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Rule setConsequence(Consequence consequence) {
}

/** Get consequence */
@javax.annotation.Nullable
@javax.annotation.Nonnull
public Consequence getConsequence() {
return consequence;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/lite/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/lite/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Rule = {
*/
conditions?: Array<Condition>;

consequence?: Consequence;
consequence: Consequence;

/**
* Description of the rule\'s purpose to help you distinguish between different rules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,9 @@ export function createSearchClient({
if (!rule.objectID) {
throw new Error('Parameter `rule.objectID` is required when calling `saveRule`.');
}
if (!rule.consequence) {
throw new Error('Parameter `rule.consequence` is required when calling `saveRule`.');
}

const requestPath = '/1/indexes/{indexName}/rules/{objectID}'
.replace('{indexName}', encodeURIComponent(indexName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default [
{
input: 'dist/builds/browser.min.js',
external: ['dom'],
cache: false,
output: {
esModule: false,
file: 'dist/builds/browser.umd.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import kotlinx.serialization.json.*
* Rule object.
*
* @param objectID Unique identifier of a rule object.
* @param conditions Conditions that trigger a rule. Some consequences require specific conditions or don't require any condition. For more information, see [Conditions](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/#conditions).
* @param consequence
* @param conditions Conditions that trigger a rule. Some consequences require specific conditions or don't require any condition. For more information, see [Conditions](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/#conditions).
* @param description Description of the rule's purpose to help you distinguish between different rules.
* @param enabled Whether the rule is active.
* @param validity Time periods when the rule is active.
Expand All @@ -20,11 +20,11 @@ public data class Rule(
/** Unique identifier of a rule object. */
@SerialName(value = "objectID") val objectID: String,

@SerialName(value = "consequence") val consequence: Consequence,

/** Conditions that trigger a rule. Some consequences require specific conditions or don't require any condition. For more information, see [Conditions](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/#conditions). */
@SerialName(value = "conditions") val conditions: List<Condition>? = null,

@SerialName(value = "consequence") val consequence: Consequence? = null,

/** Description of the rule's purpose to help you distinguish between different rules. */
@SerialName(value = "description") val description: String? = null,

Expand Down
2 changes: 1 addition & 1 deletion clients/algoliasearch-client-php/lib/Api/SearchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ public function saveObject($indexName, $body, $requestOptions = [])
* @param array $rule rule (required)
* - $rule['objectID'] => (string) Unique identifier of a rule object. (required)
* - $rule['conditions'] => (array) Conditions that trigger a rule. Some consequences require specific conditions or don't require any condition. For more information, see [Conditions](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/#conditions).
* - $rule['consequence'] => (array)
* - $rule['consequence'] => (array) (required)
* - $rule['description'] => (string) Description of the rule's purpose to help you distinguish between different rules.
* - $rule['enabled'] => (bool) Whether the rule is active.
* - $rule['validity'] => (array) Time periods when the rule is active.
Expand Down
7 changes: 5 additions & 2 deletions clients/algoliasearch-client-php/lib/Model/Search/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public function listInvalidProperties()
if (!isset($this->container['objectID']) || null === $this->container['objectID']) {
$invalidProperties[] = "'objectID' can't be null";
}
if (!isset($this->container['consequence']) || null === $this->container['consequence']) {
$invalidProperties[] = "'consequence' can't be null";
}

return $invalidProperties;
}
Expand Down Expand Up @@ -250,7 +253,7 @@ public function setConditions($conditions)
/**
* Gets consequence.
*
* @return null|Consequence
* @return Consequence
*/
public function getConsequence()
{
Expand All @@ -260,7 +263,7 @@ public function getConsequence()
/**
* Sets consequence.
*
* @param null|Consequence $consequence consequence
* @param Consequence $consequence consequence
*
* @return self
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Rule(BaseModel):
""" Unique identifier of a rule object. """
conditions: Optional[List[Condition]] = None
""" Conditions that trigger a rule. Some consequences require specific conditions or don't require any condition. For more information, see [Conditions](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/#conditions). """
consequence: Optional[Consequence] = None
consequence: Consequence
description: Optional[str] = None
""" Description of the rule's purpose to help you distinguish between different rules. """
enabled: Optional[bool] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def initialize(attributes = {})

if attributes.key?(:consequence)
self.consequence = attributes[:consequence]
else
self.consequence = nil
end

if attributes.key?(:description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ package algoliasearch.search
case class Rule(
objectID: String,
conditions: Option[Seq[Condition]] = scala.None,
consequence: Option[Consequence] = scala.None,
consequence: Consequence,
description: Option[String] = scala.None,
enabled: Option[Boolean] = scala.None,
validity: Option[Seq[TimeRange]] = scala.None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct Rule: Codable, JSONEncodable {
/// For more information, see
/// [Conditions](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/#conditions).
public var conditions: [SearchCondition]?
public var consequence: SearchConsequence?
public var consequence: SearchConsequence
/// Description of the rule's purpose to help you distinguish between different rules.
public var description: String?
/// Whether the rule is active.
Expand All @@ -25,7 +25,7 @@ public struct Rule: Codable, JSONEncodable {
public init(
objectID: String,
conditions: [SearchCondition]? = nil,
consequence: SearchConsequence? = nil,
consequence: SearchConsequence,
description: String? = nil,
enabled: Bool? = nil,
validity: [SearchTimeRange]? = nil
Expand Down Expand Up @@ -53,7 +53,7 @@ public struct Rule: Codable, JSONEncodable {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.objectID, forKey: .objectID)
try container.encodeIfPresent(self.conditions, forKey: .conditions)
try container.encodeIfPresent(self.consequence, forKey: .consequence)
try container.encode(self.consequence, forKey: .consequence)
try container.encodeIfPresent(self.description, forKey: .description)
try container.encodeIfPresent(self.enabled, forKey: .enabled)
try container.encodeIfPresent(self.validity, forKey: .validity)
Expand All @@ -75,7 +75,7 @@ extension Rule: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(self.objectID.hashValue)
hasher.combine(self.conditions?.hashValue)
hasher.combine(self.consequence?.hashValue)
hasher.combine(self.consequence.hashValue)
hasher.combine(self.description?.hashValue)
hasher.combine(self.enabled?.hashValue)
hasher.combine(self.validity?.hashValue)
Expand Down
Loading

0 comments on commit df93536

Please sign in to comment.