Skip to content

Conversation

@bolinfest
Copy link

Summary

When all of the fields of the schema for an elicitation are optional, it should be possible to hit the Submit button (sending "accept") without filling in any of the fields. Prior to this change, this would fail in the UI with:

Validation Error: data should be object

Previously, in this case, generateDefaultValue() would produce undefined as the default value, but as of this change, it produces {} instead. The undefined would fail the check here:

const ajv = new Ajv();
const validate = ajv.compile(request.request.requestedSchema);
const isValid = validate(formData);
if (!isValid) {
const errorMessage = ajv.errorsText(validate.errors);
setValidationError(errorMessage);
return;
}

Now it passes.

Note: Inspector V2 is under development to address architectural and UX improvements. See CONTRIBUTING.md for information about V2 development.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Refactoring (no functional changes)
  • Test updates
  • Build/CI improvements

Changes Made

Related Issues

Testing

  • Tested in UI mode
  • Tested in CLI mode
  • Tested with STDIO transport
  • Tested with SSE transport
  • Tested with Streamable HTTP transport
  • Added/updated automated tests
  • Manual testing performed

Test Results and/or Instructions

Screenshots are encouraged to share your testing results for this change.

Checklist

  • Code follows the style guidelines (ran npm run prettier-fix)
  • Self-review completed
  • Code is commented where necessary
  • Documentation updated (README, comments, etc.)

Breaking Changes

Additional Context

@bolinfest
Copy link
Author

I don't understand what happened: why did an action in an unrelated repo close this PR?

@olaservo olaservo self-assigned this Nov 23, 2025
expect(generateDefaultValue({ type: "object" })).toBe(undefined);
test("generates empty object for optional root object", () => {
expect(generateDefaultValue({ type: "object" })).toEqual({});
});
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to add tests for these cases as well?


  test("generates undefined for nested optional object", () => {
    // When called WITH propertyName and parentSchema, and the property is NOT required,
    // nested optional objects should return undefined
    const parentSchema = {
      type: "object" as const,
      required: ["otherField"],
      properties: {
        optionalObject: { type: "object" as const },
        otherField: { type: "string" as const },
      },
    };
    expect(
      generateDefaultValue({ type: "object" }, "optionalObject", parentSchema),
    ).toBe(undefined);
  });

  test("generates empty object for root-level object with all optional properties", () => {
    // Root-level schema with properties but no required array
    // This is the exact scenario from PR #926 - elicitation with all optional fields
    const schema: JsonSchemaType = {
      type: "object",
      properties: {
        optionalField1: { type: "string" },
        optionalField2: { type: "number" },
      },
      // No required array - all fields are optional
    };
    expect(generateDefaultValue(schema)).toEqual({});
  });

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.

2 participants