fix(openapi): handle circular references when writing request body schemas#409
Merged
Conversation
…hemas Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: e941b6e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
What This PR Does
The OpenAPI generator previously only guarded response-schema serialization against circular references. Request bodies that contained circular
$refs (for example self-referencingoneOf/allOfconstructs) would causeJSON.stringifyto throw, aborting the schema file write for that message. This PR reuses a single circular-safe stringifier for both request bodies and responses so recursive schemas still produce arequest-body.json/response-*.jsonwith cycles marked as"[Circular]".Changes Overview
Key Changes
stringifySchemahelper that walks the schema with aWeakSetand replaces seen objects with"[Circular]".request-body.jsonandresponse-*.jsonwrites inprocessMessagesForOpenAPISpec.circular-request-body.jsonfixture exercising deeply nestedoneOf/allOfcycles..pnpm-storeand fix trailing newline in root.gitignore.How It Works
stringifySchemais a thin wrapper aroundJSON.stringifywith a replacer that tracks visited objects in aWeakSet. When the same object reference is encountered a second time during serialization, it is emitted as the string"[Circular]"instead of recursing. The existing response-sidetry/catch+ inline replacer is removed in favor of calling this helper directly, and the request-body branch is updated to use it as well.The new test feeds an OpenAPI spec whose request body schema has a cycle via
oneOf→allOfback to an ancestor, then asserts:"[Circular]"sentinel.Breaking Changes
None. Output for non-circular schemas is byte-identical; only previously-failing circular request bodies are affected.
Additional Notes
@eventcatalog/generator-openapipatch.