-
Notifications
You must be signed in to change notification settings - Fork 581
fix openapi spec import for specific urls #907
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -132,15 +132,53 @@ class OpenApiImportService { | |||||||
|
|
||||||||
| /// Try to parse a JSON or YAML OpenAPI spec string. | ||||||||
| /// Returns null if parsing fails. | ||||||||
| /// | ||||||||
| /// NOTE: There's a known issue with the openapi_spec package where | ||||||||
| /// security fields containing empty arrays (e.g., "security": [[]]) | ||||||||
| /// cause parsing failures. This method includes a workaround. | ||||||||
| static OpenApi? tryParseSpec(String source) { | ||||||||
| try { | ||||||||
| // Let the library infer JSON/YAML | ||||||||
| return OpenApi.fromString(source: source, format: null); | ||||||||
| } catch (_) { | ||||||||
| } catch (e) { | ||||||||
| // Try workaround for security field parsing issues | ||||||||
| try { | ||||||||
| final processedSource = _removeProblematicSecurityField(source); | ||||||||
| if (processedSource != source) { | ||||||||
| return OpenApi.fromString(source: processedSource, format: null); | ||||||||
| } | ||||||||
| } catch (_) { | ||||||||
| // Workaround failed, fall through to return null | ||||||||
| } | ||||||||
| return null; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /// Removes problematic security fields that cause parsing issues. | ||||||||
| /// TODO: Remove this workaround once openapi_spec package fixes | ||||||||
| /// the issue with security fields containing empty arrays. | ||||||||
|
||||||||
| /// the issue with security fields containing empty arrays. | |
| /// the issue with security fields containing empty arrays. | |
| /// See: https://github.com/omidyar/openapi_spec/issues/123 (update with actual issue number) |
Copilot
AI
Oct 11, 2025
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 error message could be more specific about what preprocessing failed. Consider including details about the security field processing or JSON parsing failure to help with debugging.
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 workaround logic has a potential issue: if
_removeProblematicSecurityFieldthrows an exception, it's caught and ignored, but the method returns null instead of re-throwing the original parsing exception. This could mask the actual parsing error. Consider logging the original exception or providing more specific error handling.