You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "SinhSinhAn (via GitHub)" <gi...@apache.org> on 2026/04/10 07:30:39 UTC

[PR] fix(upstream): allow arbitrary key-value pairs in discovery_args [apisix-dashboard]

SinhSinhAn opened a new pull request, #3377:
URL: https://github.com/apache/apisix-dashboard/pull/3377

   ## Summary
   
   - Fix `discovery_args` Zod schema to preserve user-entered JSON properties
   
   The `UpstreamDiscovery` schema used `z.object({})` for `discovery_args`, which causes Zod to strip all unknown properties during parsing. Any user-entered JSON (e.g., `{"group_name": "my-group"}`) was silently reduced to `{}` before reaching the APISIX Admin API.
   
   Replaced with `z.record(z.string(), z.unknown())` to allow arbitrary key-value pairs, consistent with how `Plugin` is typed in `plugins.ts`.
   
   ## Test plan
   
   - [ ] Open Upstream create/edit form
   - [ ] Select a Discovery Type and enter Discovery Args JSON (e.g., `{"group_name": "my-group"}`)
   - [ ] Save the upstream
   - [ ] Verify the `discovery_args` value persists correctly on the detail page
   - [ ] Verify existing upstreams without `discovery_args` still work
   
   Fixes #3376


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(upstream): allow arbitrary key-value pairs in discovery_args [apisix-dashboard]

Posted by "SinhSinhAn (via GitHub)" <gi...@apache.org>.
SinhSinhAn commented on PR #3377:
URL: https://github.com/apache/apisix-dashboard/pull/3377#issuecomment-4273003702

   @Baoyuantop Thanks for the review! I've added unit tests for the `discovery_args` schema fix.
   
   Since the project didn't have a unit test framework, I added Vitest (which integrates seamlessly with the existing Vite setup) and created 4 test cases in `src/types/schema/apisix/upstreams.test.ts`:
   
   1. **Preserves flat key-value pairs** - verifies `group_name`, `namespace_id` survive parsing
   2. **Preserves nested values** - verifies complex objects like `{ metadata: { version: "v1" } }` are kept
   3. **Accepts empty `discovery_args`** - `{}` passes validation
   4. **Accepts missing `discovery_args`** - `undefined` is valid (optional field)
   
   All 4 tests pass. Run with: `npx vitest run src/types/schema/apisix/upstreams.test.ts`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(upstream): allow arbitrary key-value pairs in discovery_args [apisix-dashboard]

Posted by "moonming (via GitHub)" <gi...@apache.org>.
moonming merged PR #3377:
URL: https://github.com/apache/apisix-dashboard/pull/3377


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org