feat(import): add Swagger/OpenAPI import and URL fetching support#30
feat(import): add Swagger/OpenAPI import and URL fetching support#30
Conversation
Add ability to import Swagger 2.0 and OpenAPI 3.x specs, both as file uploads and by pasting a URL to a spec endpoint (e.g. petstore.swagger.io). - New `topenapiv2` translator package supporting both JSON and YAML specs - Format detection for swagger/openapi with confidence scoring - URL fetching: when textData is a URL, fetch content before detection - Resolve textData->Data in ImportUnified so text-based imports work - Frontend: update import dialog to mention Swagger/OpenAPI support - Handle resp.Body.Close() error return for errcheck linter Tests: - Petstore Swagger 2.0 (14 operations across pet/store/user) - Stripe-like OpenAPI 3.0 (9 operations across customers/charges/refunds) - Verifies request counts, HTTP methods, path params, query params, headers, request bodies, flow structure, and body kind correctness
|
the overall architecture is clean. The translator plugs into the existing registry pattern well, the normalized internal A few things to address before merging: Bugs1. URL fetching is bypassed through
If a user pastes Fix: either call 2. No HTTP client timeout on
client: &http.Client{Timeout: 60 * time.Second},3. Non-deterministic assert status code selection
Paths and methods are already sorted for determinism — same pattern should apply here. Could sort the response codes first, or explicitly prefer Limitations to document4. No
The test fixtures work because they inline everything. This is fine for a V1, but worth adding a comment or note in the code/docs so users understand why their real spec might import with missing data. Could be a fast follow-up. 5. Swagger 2.0
Nits6. Dead code in
7.
Overall: bugs 1-3 should be fixed before merge. 4-5 are fine as documented limitations for V1. The rest are nits. |
…iteration - Remove premature TextData→Data conversion in ImportUnifiedWithTextData so resolveInputData can detect and fetch URLs - Add 60s timeout to DefaultURLFetcher HTTP client - Sort response codes and content types before iteration for deterministic output - Add TODO comments for $ref resolution and Swagger consumes field - Fix TestConstraints/TestTranslatorRegistry to include FormatOpenAPI - Add regression tests for all fixes
…d minor nits - Add SSRF protection to URL fetcher with DNS-level private IP blocking - Fix non-deterministic map iteration in mergeParameters and buildFolderStructure - Fix parseRequestBody to use first sorted content type as fallback (not last) - Cap detectOpenAPI confidence at 1.0 - Downgrade URL fetch logging from Info to Debug (URLs may contain API keys)
Summary
topenapiv2translator package supporting both JSON and YAML Swagger 2.0 / OpenAPI 3.x specsTests