Repository navigation
perf(resolver): skip Schema Objects in OpenAPI 3.1 - #4332
Open
jochenberger wants to merge 1 commit into
Open
jochenberger wants to merge 1 commit into
jochenberger wants to merge 1 commit into
Conversation
normalization None of the normalization plugins handles an element type that can occur inside a Schema Object. They only act on OpenAPI, Path Item, Operation, Parameter and Header Objects. Traversing into every Schema Object is wasted work, so normalize() now uses a key map without Schema children. Refs swagger-api#3805
jochenberger
requested review from
cka121,
glowcloud and
robert-hebel-sb
as code owners
December 2, 2026 08:52
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.
Description
normalize()for OpenAPI 3.1 (ApiDOM strategy) merges five normalization plugins into a single visitor and traverses the whole document. This includes every Schema Object subtree, although none of the plugins can find anything there: they only act onOpenApi3_1Element,PathItemElement,OperationElement,ParameterElementandHeaderElement, and none of these element types can occur inside a Schema Object.This PR passes a key map to the traversal in which
SchemaElementhas no children, so schemas are no longer walked during normalization. The change is one new constant and one changed line insrc/resolver/strategies/openapi-3-1-apidom/normalize.js. It also adds a unit test that pins down the invariant (the document is still normalized, Schema Object contents are left untouched).Motivation and Context
Resolving OpenAPI 3.1 documents is much slower than resolving 3.0 ones (see #3805 and the issues linked there). Profiling
SwaggerClient.resolve()shows that on a schemas-only spec roughly one third of the time is spent innormalize. This PR removes part of that work. It does not fix #3805: 3.1 resolution stays much slower than 3.0 (about 20 ms for the same content in my measurements), which is why this refers to the issue instead of closing it.Refs #3805
Measured with
SwaggerClient.resolve()in Node on synthetic specs. Median of nine steady-state resolves (three fresh processes, runs 2 to 4):Environment: swagger-client 3.39.0,
@swagger-api/apidom-*1.16.0, Node v22.23.5, Ubuntu 24.04.5, 1 vCPU (Intel Xeon 2.30GHz).How Has This Been Tested?
test/resolver/strategies/openapi-3-1-apidom/normalize/index.js. It passes before and after the change. With a deliberately wrong key map that also skips Path Item children, 7 of the 10 tests in that file fail.http > encodeFormOrQuery > should handle custom array serialization, fails identically on the unmodified v3.39.0 tree. On currentmain(0890b13) I ran the 3.1 strategy tests only (35 tests passed) andeslinton the changed files.JSON.stringifyof the resolved spec before and after, on both specs above. The hashes are identical. The 441 kB spec makes every plugin visibly change the output (operationIds are rewritten, path-level parameters are merged into operations, parameter and header examples are copied into their schemas). Key maps that also stop atOperationElementorPathItemElementchange the hash, so the check can fail.enginessays>=22). I have not run it on Node 24.visitorOptions: { keyMap, nodeTypeGetter: getNodeType }line insrc/resolver/strategies/openapi-3-2-apidom/normalize.js.One assumption: the change relies on the five plugins never needing to look inside a Schema Object.
refractorPluginNormalizeDiscriminatorMappinginapidom-ns-openapi-3-1does work on schemas, but it is not part of this plugin list. If it is added later, the key map has to be revisited.Reproduction scripts
gen-spec.mjs:gen-rich.mjs:bench.mjs:Screenshots (if appropriate):
Types of changes
package.json)None of these fits exactly: this is a performance improvement without a behavior change (commit type
perf).Checklist:
http > encodeFormOrQuery, also fails on the unmodified tree, see above.)