Detect struct fields removed from the spec but left in models.rs (#237)#240
Open
sdairs wants to merge 2 commits into
Open
Detect struct fields removed from the spec but left in models.rs (#237)#240sdairs wants to merge 2 commits into
sdairs wants to merge 2 commits into
Conversation
OpenAPI drift detection was one-directional for fields: it caught spec properties missing from models.rs and optionality flips, but not the reverse — a field removed from the live spec yet still present as a struct field. A model that is a superset of the spec passed every field check (this is how the stale `storageSize` fields in #235/#236 slipped through). Add the code→spec mirror of the existing missing-field check, matching the missing/extra split already used for client methods: - spec_coverage_test.rs: `assert_no_extra_struct_fields` + `struct_fields_have_no_extras_vs_{spec,live_spec}` tests, plus an `EXTRA_FIELD_EXEMPTIONS` allowlist (analogous to OPTIONALITY_EXEMPTIONS / NON_OPENAPI_CLIENT_METHODS) with stale-entry detection. Schemas with no/empty `properties` are skipped so composition/marker schemas don't flag every field. - check-openapi-drift.py: `check_extra_fields` reverse pass + `parse_extra_field_exemptions` (reads the same constant), surfaced as a new "Extra Struct Fields" report section and summary row. - AGENTS.md: document the now-bidirectional field coverage and the EXTRA_FIELD_EXEMPTIONS allowlist. Detection only — nothing is remediated and the allowlist is empty, so the real findings it surfaces are reported rather than hidden. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bring models.rs in line with the vendored OpenAPI snapshot, clearing the 5 findings surfaced by the new struct_fields_have_no_extras_vs_spec detector (#237). EXTRA_FIELD_EXEMPTIONS stays empty — these are fixed, not exempted. - PostgresServicePatchRequest: drop name/provider/region/postgresVersion; the live spec only allows size/haType/tags. The `postgres update` CLI surface loses the matching --name/--region/--provider/--pg-version flags (same class of stale field as the storageSize cleanup in #235/#236). - ScimEnterpriseManager: drop the code-only $ref attribute absent from the ClickHouse spec. Updates the affected library and CLI tests plus the README update example. struct_fields_have_no_extras_vs_spec now passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #237.
Problem
OpenAPI drift detection was one-directional for fields (spec → code). It caught fields added to the spec that are missing from
models.rsand optionality flips, but not the reverse: a field removed from the live spec yet still present as a struct field. A model that is a superset of the spec passed every field check — exactly how the stalestorageSizefields in #235/#236 slipped through.Change
Adds the code→spec mirror of the existing missing-field check, matching the missing/extra split already used for client methods (
assert_client_operation_coverage), and remediates the findings it surfaces so the model matches the vendored snapshot.Detector
spec_coverage_test.rs:assert_no_extra_struct_fields+struct_fields_have_no_extras_vs_spec(snapshot) andstruct_fields_have_no_extras_vs_live_spec(live,#[ignore]). Adds anEXTRA_FIELD_EXEMPTIONSallowlist — analogous toOPTIONALITY_EXEMPTIONS/NON_OPENAPI_CLIENT_METHODS— with stale-entry detection. Schemas with no/emptypropertiesare skipped so composition/marker schemas don't flag every field.check-openapi-drift.py:check_extra_fieldsreverse pass +parse_extra_field_exemptions(reads the same Rust constant), surfaced as a new "Extra Struct Fields" report section and summary row.AGENTS.md: documents the now-bidirectional field coverage and theEXTRA_FIELD_EXEMPTIONSallowlist.Remediation
The detector surfaced 5 stale fields against the snapshot; all are fixed, not exempted, so
EXTRA_FIELD_EXEMPTIONSstays empty.PostgresServicePatchRequestname,provider,region,postgresVersionsize,haType,tagsScimEnterpriseManager$refdisplayName,valuePostgresServicePatchRequestis live CLI surface — same class of stale field as thestorageSizecleanup in Remove storageSize from Postgres create/update requests #235/Remove storageSize from Postgres create/update requests #236. Thepostgres updatecommand loses the matching--name/--region/--provider/--pg-versionflags (keeps--size/--ha-type/--add-tag/--remove-tag);PostgresUpdateOptions, thepostgres_updatehandler, themain.rsmatch arm, the parse/write-command tests, and the README update example are updated accordingly.ScimEnterpriseManager.$refwas a code-only SCIM attribute absent from the ClickHouse spec, with no usages.update_postgres_servicemock test rewritten to patchsizeinstead ofname.The live-spec-only findings (
seekSnapshoton the two PubSub sources) are out of scope — they aren't in the vendored snapshot this PR aligns to; they'll be picked up by the live drift run / snapshot refresh.Verification
struct_fields_have_no_extras_vs_specnow passes — all 9 snapshot spec-coverage tests green; the 8 live-spec tests stay#[ignore].NOTE: … exempted), a bogus entry fails as stale.cargo build,cargo clippy --all-targets, and the fullclickhousectl+clickhouse-cloud-apitest suites pass; all integration targets compile.🤖 Generated with Claude Code
Note
Medium Risk
Removes
postgres updateflags and patch request fields users may still rely on; changes are spec-aligned but are a breaking CLI/API-model surface for Postgres metadata updates.Overview
Adds bidirectional OpenAPI field coverage so drift detection catches Rust struct fields that no longer exist in the spec, not only missing spec properties.
spec_coverage_test.rsgainsassert_no_extra_struct_fieldswith snapshot and live-spec tests plus an emptyEXTRA_FIELD_EXEMPTIONSallowlist (stale-entry checks).check-openapi-drift.pymirrors this withcheck_extra_fields, exemption parsing, and an Extra Struct Fields report section.Remediation removes five stale fields surfaced by the new check:
PostgresServicePatchRequestdropsname,provider,region, andpostgresVersion;ScimEnterpriseManagerdrops$ref. Thecloud postgres updateCLI is narrowed to match the patch schema—--name,--region,--provider, and--pg-versionare removed; updates use--size,--ha-type, and tag flags. README, library mock tests, and CLI parse/write tests follow the same shape.AGENTS.mddocuments bidirectional field coverage and extra-field exemptions.Reviewed by Cursor Bugbot for commit 676d5b9. Bugbot is set up for automated code reviews on this repo. Configure here.