Skip to content

fix(openapi): validate --data JSON without a schema and harden validation - #1674

Merged
developerkunal merged 2 commits into
mainfrom
fix/data-schema-review-followups
Sep 17, 2026
Merged

developerkunal merged 2 commits into
mainfrom
fix/data-schema-review-followups

Conversation

@developerkunal

@developerkunal developerkunal commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🔧 Changes

Follow-up to the re-review of #1673. This hardens the --data schema validation path without changing how any wired command behaves today.

  • ValidateRequest now parses the JSON body before the no-schema early return, so malformed --data fails locally with a clear message even for operations that define no request schema, instead of being sent to the API as-is. Every wired --data command targets a schema-bearing operation, so this branch is reached today only by a future schemaless command.
  • Added a StatusUnknown zero value to ValidationStatus and made DataJSONHandler.ReadAndValidate return an error when it sees it, so an unset ValidationResult fails closed rather than being treated as validated.
  • The roles --data tests now inject a fixture-backed schema manager (new NewSchemaManagerFromDoc and LoadDocFromData helpers, wired through a newSchemaManager seam) so the unit suite validates offline and no longer depends on fetching the live OpenAPI document or on the remote spec keeping a particular operation schemaless.
  • Corrected the ValidateRequest doc comment to describe the actual VisitJSON behavior, and softened the schemaless test comment so it reads as a forward-looking guard.
  • Added a CHANGELOG entry for the schemaless well-formed-JSON check.

📚 References

Follow-up to #1673.

🔬 Testing

  • go build, go vet, and the openapi and cli suites pass, including under -race with repeated runs.
  • Added a unit test asserting a schemaless operation returns StatusNoSchema for well-formed JSON and StatusInvalid for malformed JSON.
  • Verified the fixture-injected roles --data tests pass with the network blocked, while a control test using the real fetcher fails, confirming the suite is now offline-safe.
  • Ran the built binary: roles create --schema, an invalid payload, and malformed JSON all behave as before for the wired commands.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

…tion

- Parse --data JSON before the no-schema early return so malformed payloads
  fail locally instead of being sent to the API as-is.
- Add a StatusUnknown zero value to ValidationStatus so an unset result fails
  closed rather than reading as valid.
- Inject a fixture-backed schema manager in the roles --data tests so the unit
  suite validates offline instead of fetching the live OpenAPI document.
- Correct the ValidateRequest doc comment and soften the schemaless test note.
@developerkunal
developerkunal requested a review from a team as a code owner September 17, 2026 11:18
ReadAndValidate now rejects StatusUnknown instead of letting an
unrecorded outcome fall through as an unvalidated send. Also note that
useFixtureSchema swaps a package-level global, so its tests must not use
t.Parallel().
@developerkunal
developerkunal enabled auto-merge (squash) September 17, 2026 14:27
@developerkunal
developerkunal merged commit db093e8 into main Sep 17, 2026
6 checks passed
@developerkunal
developerkunal deleted the fix/data-schema-review-followups branch September 17, 2026 14:36
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