feat: add reusable OpenAPI diff package - #1424
Draft
andmatei wants to merge 2 commits into
Draft
Conversation
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.
Summary
Adds a reusable
tools/foas/diffpackage that exposes FOAS compatibility comparison without leaking oasdiff types.The changelog generator now consumes this package instead of owning the checker configuration and invoking oasdiff directly.
Why
Compatibility comparison was split across packages:
openapi.OasDiffproduced the raw structural diff;changelogprivately owned checker severities and deprecation settings;This made it difficult for OASIS and other Go consumers to use the same compatibility behavior as the FOAS CLI.
Public API
The returned report contains FOAS-owned types:
No oasdiff types are exposed.
Package responsibilities
diffallOfbefore comparison;changelogdiff.Compare;breakingchangesopenapi.OasDiffCompatibility
The existing
outputfilter.NewChangelogEntries(checker.Changes, ...)API remains available. Changelog uses the newNewChangelogEntriesFromDiffpath.No oasdiff dependency upgrade is included in this PR.
Adding custom rules
The custom-rule registry is intentionally internal so callers cannot redefine
the canonical FOAS ruleset at runtime.
An approved custom rule is added by:
FOAS message formatter with
newCustomRule;registeredCustomRules;RulesetVersionwhen classification changes.The registry rejects duplicate IDs, collisions with built-in oasdiff IDs,
unsupported severities, missing descriptions, nil handlers, and nil message
formatters. Multiple rule IDs may share a handler; that handler is executed
only once.
The
x-xgen-operation-id-overriderule from #1166 is not enabled by this PRbecause #1166 is explicitly a POC and its rule behavior has not been approved.
The new registry is the library-level extension point where that rule can be
added once approved.
Testing
GOWORK=off go test ./...GOWORK=off go test -race ./...go vet ./...golangci-lint v2.10.1: 0 issuesThe new diff tests cover:
Follow-up
OASIS can replace its direct oasdiff integration with
foas/diff.Compareafter this API is released.