Skip to content

fix: prefill required plugin json fields - #34

Merged
jinbagi merged 1 commit into
masterfrom
codex/plugin-required-json-template
Jul 3, 2026
Merged

fix: prefill required plugin json fields#34
jinbagi merged 1 commit into
masterfrom
codex/plugin-required-json-template

Conversation

@jinbagi

@jinbagi jinbagi commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Prefill plugin add JSON with schema required fields instead of only schema defaults
  • Choose a minimal union branch when APISIX required fields live under oneOf/anyOf, such as limit-count count/time_window
  • Avoid treating empty resolved properties as an object shape for primitive union schemas

Verification

  • corepack pnpm lint
  • corepack pnpm build
  • E2E_TARGET_URL=http://127.0.0.1:55175/ui/ playwright test e2e/tests/resource-required-templates.spec.ts --config=.tmp-playwright-chrome.config.ts --project=chrome --reporter=list --workers=1

Copilot AI review requested due to automatic review settings July 3, 2026 14:16
@jinbagi
jinbagi merged commit 41a0589 into master Jul 3, 2026
@jinbagi
jinbagi deleted the codex/plugin-required-json-template branch July 3, 2026 14:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves the “Add Plugin” JSON editor experience by generating an initial plugin config template that includes schema-required fields (not just defaults), with special handling for union schemas so the prefilled JSON is closer to a valid APISIX plugin payload.

Changes:

  • Refines schemaType inference to avoid treating empty properties as an object schema shape.
  • Reworks plugin “add” initialization to build a schema-driven template that prefills required fields (and recursively generates placeholders).
  • Adds Playwright coverage to verify required field prefilling for a representative plugin (limit-count).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/components/schema-form/schemaValidation.ts Adjusts schema type inference to reduce false “object” detection when properties is empty.
src/components/form-slice/FormItemPlugins/PluginEditorDrawer.tsx Implements required-field-aware template generation for plugin add flow (including union/placeholder logic).
e2e/tests/resource-required-templates.spec.ts Adds an e2e test asserting plugin add JSON prefills required fields from APISIX schema.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +154 to +169
const matchingVariants = [
...(resolvedSchema.oneOf ?? []),
...(resolvedSchema.anyOf ?? []),
].filter(
(variant) => validateSchemaValue(variant, value, '', rootSchema).length === 0
);
const unionVariants = [
...(resolvedSchema.oneOf ?? []),
...(resolvedSchema.anyOf ?? []),
];
if (matchingVariants.length === 0 && unionVariants[0]) {
for (const key of getActiveRequiredFields(unionVariants[0], value, rootSchema)) {
required.add(key);
}
collectTemplateRequiredFields(unionVariants[0], value, rootSchema, required);
}

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2dbb899eb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +232 to +233
if (type === 'string' && resolvedSchema.minLength && resolvedSchema.minLength > 0) {
return 'value';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor minLength when generating required strings

When an APISIX or custom plugin schema marks a string field as required with minLength greater than 5, this branch seeds it with the fixed string value. The add-mode JSON template then fails the drawer's own validateSchemaValue check and cannot be saved until the user edits a field that was supposed to be prefilled; generate a string at least minLength characters long or otherwise respect the constraint.

Useful? React with 👍 / 👎.

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