swagger-api / swagger-api/swagger-parser
[Feature]: Cache the result of deserialization when loading ref
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
Feature Description
When loading external $ref with swagger-parser, the ResolverCache stores only the read string but still deserialize the whole tree which is particuraly slow for big files.
Maybe the Resolver could also store the deserialized tree.
Use Case
We have a big project with 260+ openapi spec file.
We also have a big "dictionary" yaml file which define every field (primitive type mostly) of our application. (with currently more than 1100 fields)
So every spec file reference ($ref) to fields inside that "dictionary" (currently 3300+ ref to that file)
Everytime a ref is parsed by swagger-parser, it get the file contents (String) from the cache but still do the deserialization to JsonNode (see ResolverCache.java#L170)
Suggested Solution (optional)
A suggested solution would be to also (or only) cache the deserialized JsonNode tree.
I have cloned the repo and applied that suggestion and the result help a lot:
My application generate source with the openapi-generator-maven-plugin which use swagger-parsers-v3.
When i clean package the application without that fix, the total time (generation + other phases and plugin used for my build) is around 4m49s
With that fix, my application is now built in 58s.
I know that the time above is not focused on the swagger-parsers part alone, but it still a huge gap and benefice to enhance that cache.
I can contribute if needed with a PR.
Alternatives Considered
Additional Context
Checklist
- I have searched the existing issues to ensure this is not a duplicate.
- This feature would be useful to more than just my use case.
- I have provided enough detail for the maintainers to understand the scope of the request.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ResolverCache.java#L170 and trace how loading external $ref retrieves cached file contents and deserializes them into JsonNode. Check how the resolver handles repeated references to the same file, then ensure the deserialized tree can be reused without changing existing resolution behavior. Confirm the change improves repeated large-file reference loading, such as the dictionary-file case described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100