Add SwaggerSwiftIR target with Swagger 2.0 → IR converter#208
Add SwaggerSwiftIR target with Swagger 2.0 → IR converter#208MadsBogeskov wants to merge 2 commits intomainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduces a new `SwaggerSwiftIR` target containing spec-agnostic intermediate representation types that both Swagger 2.0 and future OpenAPI 3.x parsers will convert into. Adds `SwaggerToIRConverter` in `SwaggerSwiftML` to convert the existing `Swagger` struct into `IRDocument`, including full schema, parameter, request body, and response mapping. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 4 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 604be66. Configure here.
| case .pipes: return .pipeDelimited | ||
| case .multi: return .form | ||
| } | ||
| } |
There was a problem hiding this comment.
CSV maps to simple style, wrong for query parameters
High Severity
irParameterStyle maps .csv to .simple unconditionally, but per the Swagger 2.0 → OpenAPI 3.0 mapping spec, csv for query parameters converts to style: form with explode: false, not simple. The simple style is only valid for path and header parameters. Since .csv is the default collectionFormat in Swagger 2.0, this affects every array-typed query parameter without an explicit collection format — producing semantically invalid IR that will cause incorrect serialization downstream.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 604be66. Configure here.
| switch collectionFormat { | ||
| case .csv: return .simple | ||
| case .ssv: return .spaceDelimited | ||
| case .tsv: return .spaceDelimited |
There was a problem hiding this comment.
TSV incorrectly mapped to spaceDelimited style
Medium Severity
CollectionFormat.tsv (tab-separated values, delimiter \t) is mapped to IRParameterStyle.spaceDelimited (space-separated values, delimiter ). These use fundamentally different delimiter characters. OpenAPI 3.0 has no direct equivalent for TSV, so this mapping silently changes the serialization behavior from tab-separated to space-separated.
Reviewed by Cursor Bugbot for commit 604be66. Configure here.
| case .schema(let s): | ||
| additionalProperties = .schema(irSchema(from: s)) | ||
| } | ||
| return .object(IRObjectSchema(additionalProperties: additionalProperties)) |
There was a problem hiding this comment.
Dictionary schema drops named property keys during conversion
Medium Severity
The .dictionary(let valueType, _) pattern discards the keys: [KeyType] associated value, which represents named properties defined alongside additionalProperties. The resulting IRObjectSchema is created with empty properties and required, losing all named property information from dictionary-type schemas.
Reviewed by Cursor Bugbot for commit 604be66. Configure here.
| content["application/json"] = IRMediaType(schema: irSchema(from: schemaNode)) | ||
| } | ||
| return IRResponse(description: response.description, content: content) | ||
| } |
There was a problem hiding this comment.
Response MIME type hardcoded, ignores produces field
Medium Severity
irResponse always keys response content under "application/json", completely ignoring the produces field available on both Operation and Swagger. This is inconsistent with how consumes is correctly resolved for request bodies via effectiveConsumes at line 71. APIs producing XML, plain text, binary, or any other non-JSON MIME type will have their responses mislabeled as application/json in the IR.
Reviewed by Cursor Bugbot for commit 604be66. Configure here.


Summary
SwaggerSwiftIRtarget with spec-agnostic intermediate representation types (IRDocument,IROperation,IRParameter,IRRequestBody,IRResponse,IRSchema,IRServer, etc.)SwaggerToIRConverterinSwaggerSwiftMLthat converts the existingSwagger2.0 struct intoIRDocumentSwaggerSwiftCorewill eventually consume IR instead ofSwaggerdirectlyThis is the first step toward OpenAPI 3.x support. No existing code is modified — purely additive.
Key design decisions
SwaggerSwiftIRhas zero dependencies (pure Swift value types)in: bodyparameters are converted toIRRequestBodywith the correct MIME type fromconsumesin: formDataparameters are aggregated into a singleIRRequestBody(auto-detectsmultipart/form-datavsapplication/x-www-form-urlencodedbased on presence of file params)IRParameterLocationhas nobodyorformDatacases — request bodies are first-class viaIRRequestBodyIRResponseCodesupports.status(Int),.range("2XX"), and.default(OAS3-ready)CollectionFormatmaps toIRParameterStyle(e.g..csv→.simple,.multi→.form)x-nullablecustom field maps tonullable: trueonIRSchemaTest plan
SwaggerToIRConvertercovering body/formData/schema/ref conversion🤖 Generated with Claude Code
Note
Low Risk
Low risk additive change that introduces a new
SwaggerSwiftIRmodule and wiring inPackage.swift; the main risk is limited to build/package integration and correctness of the new Swagger→IR mapping.Overview
Introduces a new
SwaggerSwiftIRtarget containing spec-agnostic intermediate representation value types (IRDocument,IRSchema,IROperation, request/response/parameter/server models) intended to decouple codegen from Swagger/OpenAPI versions.Adds
SwaggerToIRConverterinSwaggerSwiftMLplus aSwagger.toIR()convenience to convert existing Swagger 2.0 parse trees into the IR, including$refresolution, request-body aggregation forin: body/in: formData, response mapping, and collectionFormat→parameter-style handling.Updates
Package.swiftto include the new target and makesSwaggerSwiftMLdepend on it; also addsCLAUDE.mdrepository guidance.Reviewed by Cursor Bugbot for commit 604be66. Bugbot is set up for automated code reviews on this repo. Configure here.