-
-
Notifications
You must be signed in to change notification settings - Fork 673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
openapi: fix import of big files #5299
base: main
Are you sure you want to change the base?
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
recheck |
You first need to add the agreeing comment. |
I have read the CLA Document and I hereby sign the CLA |
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Ignacio Íñigo <megalucio@users.noreply.github.com>
Signed-off-by: Ignacio Íñigo <megalucio@users.noreply.github.com>
Signed-off-by: Ignacio Íñigo <megalucio@users.noreply.github.com>
8d02429
to
6fd73e0
Compare
@@ -345,7 +345,7 @@ public OpenApiResults importOpenApiDefinitionV2( | |||
|
|||
List<String> errors = | |||
importOpenApiDefinition( | |||
Json.pretty(openApi), | |||
new String(Files.readAllBytes(file.toPath())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's this way to add support for multi file definitions, #2913, doing just this change breaks that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any good examples to test this multi file definition schema? I tried with https://github.com/Paldom/swagger-multifile-example/tree/master and in any case this does not seem to work either, getting different errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codebase has tests for that, ExtensionOpenApiTest.shouldImportMultiFileV*
.
IMO this is not the proper fix, we should change the parser limits instead. |
List<String> errors = | ||
importOpenApiDefinition( | ||
Json.pretty(openApi), | ||
!openApiString.contains("openapi:") || openApiString.contains(".yaml#") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checks will not work for JSON format (in that it will still fail to parse big files).
Agreed, however I understand the limit that is being reached here is the String's Maximum length(Integer.MAX_INT or 2147483647) as seen on the exception
Not sure how to address that. Besides the method where the exception is being thrown, Json.pretty() belongs to external library swagger-core so it does not look like we can change that. Another alternative which I was thinking was to catch for the IllegalStateException and only on that instance to get the string directly from the file, which seems a bit more proper. Thoughts? Any other ideas on how to fix it? |
It looks suspicious that's actually hitting the max of the string, what's the size of the original definition? Did you try write the expanded definition to a file to see its size (and contents for that matter)? I'm aware that's a class/method from the library, but that's "one" line of code. Agreed that looks better still I'd skip the pretty print instead of reading from the file (as that would break the multi file). |
@megalucio are you able to answer the latest questions and keep going with this? |
Overview
Fix import openapi definitions from files. It fails with big files.
Related Issues
Specify any related issues or pull requests by linking to them.
zaproxy/zaproxy#8193
Checklist
./gradlew spotlessApply
for code formattingFor more details, please refer to the developer rules and guidelines.