Skip to content

Fix ShardFailure.shard incorrectly required causing MissingRequiredPropertyException - #2037

Open
gingeekrishna wants to merge 3 commits into
opensearch-project:mainfrom
gingeekrishna:fix/1799-shardfailure-shard-nullable
Open

Fix ShardFailure.shard incorrectly required causing MissingRequiredPropertyException#2037
gingeekrishna wants to merge 3 commits into
opensearch-project:mainfrom
gingeekrishna:fix/1799-shardfailure-shard-nullable

Conversation

@gingeekrishna

Copy link
Copy Markdown

Description

Fixes #1799

Problem: When OpenSearch returns a ShardFailure without a shard field (which can happen for certain failure types), the Java client throws MissingRequiredPropertyException: Missing required property 'ShardFailure.shard' — masking the real failure that the caller was trying to handle.

Root cause: _common___ShardFailure in opensearch-openapi.yaml listed shard in required. The generated ShardFailure.java used ApiTypeHelper.requireNonNull(builder.shard, ...) which throws when the field is absent in the JSON response.

According to the OpenSearch API, shard is an optional integer — the required fields in a shard failure are primary (bool) and reason (ErrorCause). The shard number may legitimately be absent for certain failure scenarios.

Fix: Remove shard from required in the spec and update the generated ShardFailure.java:

  • Field type: int@Nullable Integer
  • Constructor: requireNonNull → direct assignment
  • Getter: returns @Nullable Integer
  • Serialization: wrapped in null check
  • hashCode/equals: use Objects.hashCode/Objects.equals

Changes

  • java-codegen/opensearch-openapi.yaml — remove shard from _common___ShardFailure.required
  • java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardFailure.java — make shard nullable throughout

@gingeekrishna
gingeekrishna requested a review from reta as a code owner July 5, 2026 07:36
Copilot AI review requested due to automatic review settings July 5, 2026 07:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

gingeekrishna added a commit to gingeekrishna/opensearch-java that referenced this pull request Jul 5, 2026
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
…rsing_exception

The _common___DerivedField schema in opensearch-openapi.yaml included a
required name property. This caused DerivedField.java to serialize a
name key into the JSON mapping body, but the OpenSearch API does not
accept name inside a derived field definition and returns:
  mapper_parsing_exception: unknown parameter [name] on mapper

In the API, the derived field's name is expressed as the map key in the
parent derived object, not as a property inside the field definition.

Remove name from the _common___DerivedField schema (both from
properties and required) and update the generated DerivedField.java
accordingly. The Java client no longer serializes name inside derived
field definitions.

Fixes opensearch-project#1937

Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
…ailure

ShardFailure.shard was marked as required in the spec, so the generated
class threw MissingRequiredPropertyException when OpenSearch returned a
ShardFailure without the shard field — masking the real failure.

Per the OpenSearch API, shard is an optional integer in ShardFailure
(the primary failure reason is always present; the shard number may
be absent for certain failure types).

Remove shard from the required list in _common___ShardFailure and
update the generated ShardFailure.java to use @nullable Integer with
proper null guards in serialization, hashCode, and equals.

Fixes opensearch-project#1799

Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
@gingeekrishna
gingeekrishna force-pushed the fix/1799-shardfailure-shard-nullable branch from 2dfacc8 to a80639b Compare August 16, 2026 16:10

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please submit a change against https://github.com/opensearch-project/openSearch-api-specification, thank you

@gingeekrishna gingeekrishna Aug 17, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted the spec fix upstream: opensearch-project/opensearch-api-specification#1194

@gingeekrishna

Copy link
Copy Markdown
Author

Submitted the spec fix upstream: opensearch-project/opensearch-api-specification#1194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ShardFailure hides real failure if ApiTypeHelper assertion fails

3 participants