Skip to content

fix(resolver): reuse OpenAPI 3.1/3.2 normalization cache - #4331

Open
Finomosec wants to merge 1 commit into
swagger-api:mainfrom
Finomosec:fix/oas31-normalization-cache
Open

Finomosec wants to merge 1 commit into
swagger-api:mainfrom
Finomosec:fix/oas31-normalization-cache

Conversation

@Finomosec

Copy link
Copy Markdown

Description

pojoAdapter stores the refracted element in resolveOpenAPI3{1,2}Strategy.cache keyed by value, but then returns a second toValue(normalized) object. The resolve strategy therefore never hits that cache and refracts the whole definition again. Since #3575 the pre-normalization result is not cached per input either, so Swagger UI, which passes its memoized specJS() to resolveSubtree, refracts, normalizes and serializes the entire definition on every operation expansion.

This PR restores a per-input cache in pojoAdapter (as in #3009 / #3281, now keyed by normalize function and input) and returns the cached value object, so the strategy cache hits.

Motivation and Context

Refs swagger-api/swagger-ui#10748 (expanding operations is slow for OpenAPI 3.1, fast for 3.0.3).

With a 2.1 MB OpenAPI 3.1.0 definition (LiteLLM proxy, 1026 operations, 1062 schemas), expanding a single operation blocks the main thread for 6.6–7.4 s in swagger-ui 5.26.2. With this change it drops to 3.2–4.7 s, and to 1.7–2.3 s with swagger-ui 5.36.0 (long tasks measured in headless Chromium; the remaining time is the full-tree normalization after each resolve).

How Has This Been Tested?

  • New unit tests for both strategies (3.1 and 3.2): the same input returns the same POJO, and the returned POJO is a key in the strategy cache. They fail without the change.
  • test/resolver/strategies/openapi-3-1-apidom and openapi-3-2-apidom: 64 tests pass. Lint and commitlint pass.
  • Full unit suite: the only failures are 10 tests in test/client.js and test/oas3/client.js, which fail identically on main in my environment (Node 23).

Screenshots (if appropriate):

Types of changes

  • No code changes (changes to documentation, CI, metadata, etc)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

pojoAdapter returned a fresh toValue() result, so the strategy cache keyed
by the returned POJO never hit and every resolveSubtree call refracted and
normalized the whole definition again.
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.

1 participant