Wire APIFactory and Generator to use IRDocument end-to-end#212
Wire APIFactory and Generator to use IRDocument end-to-end#212MadsBogeskov wants to merge 8 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>
- Add OpenAPI3Document and supporting model types (schema, parameter, operation, request body, response, components, server, OrRef) - Add OpenAPI3ToIRConverter converting OAS3 → IRDocument - Add SwaggerReader.readSpec() with version detection, returning APISpec (.swagger2 or .openapi3) — both convert to IRDocument via .toIR() - Add 33 tests covering parsing, IR conversion, and version detection - Add BasicOpenAPI3.yaml fixture Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace all SwaggerSwiftML-specific DataFormat/Schema references in the resolver layer with spec-agnostic IRSchema types. Introduces IRStringFormat, IRIntegerFormat, and IRNumberFormat; adds Schema.toIR() / Node<Schema>.toIR() helpers for incremental call-site migration in APIRequestFactory and RequestParameterFactory. All 41 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both factories now accept IROperation and [IRParameter] instead of SwaggerSwiftML.Operation, Parameter, Swagger, and SwaggerFile — removing the SwaggerSwiftML dependency from the factory layer entirely. Supporting changes: - Delete SwaggerSwiftCore.HTTPMethod; use SwaggerSwiftIR.HTTPMethod throughout - Delete ParameterType+ToString.swift; factories use modelTypeResolver.resolve() instead - QueryElement.ValueType.array now uses IRParameterStyle? instead of CollectionFormat? - Enumeration drops the dead collectionFormat field - APIFactory converts each ML operation to IR via Operation.toIR(globalConsumes:globalParameters:) before calling the factories - New OperationToIRConverter in SwaggerToIRConverter.swift handles standalone operation conversion - Parameter.toIRParameter() bridge extension for path-level parameter conversion All 41 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
APIFactory.generate() now accepts IRDocument instead of Swagger, removing the last direct SwaggerSwiftML dependency from the code generation engine. Generator converts Swagger → IRDocument once after parsing, then passes it to the factory. Dead extension files (Path, Operation, Parameter, Swagger, Schema, DataFormat) are deleted — their functionality is now handled by IRPathItem/IROperation or was unused. Phantom SwaggerSwiftML imports are cleaned from 8 model and parser files. Generator.swift is the only remaining file in SwaggerSwiftCore that imports SwaggerSwiftML, solely to drive the Swagger 2.0 parse → IRDocument conversion pipeline. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 3 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 7293ada. Configure here.
|
|
||
| mutating func run() async throws { | ||
| guard let token = gitHubToken ?? ProcessInfo.processInfo.environment["GITHUB_TOKEN"] else { | ||
| guard let token = githubToken ?? ProcessInfo.processInfo.environment["GITHUB_TOKEN"] else { |
There was a problem hiding this comment.
Error message references old CLI flag name
Medium Severity
The validation error message still references --git-hub-token but the CLI flag was renamed to --github-token (property githubToken generates --github-token via Swift Argument Parser). Users who see this error and follow its guidance will use a flag that doesn't exist.
Reviewed by Cursor Bugbot for commit 7293ada. Configure here.
| let modelDefinitions = try getModelDefinitions(fromSwagger: swagger) | ||
| let responseModelDefinitions = try getResponseModelDefinitions(fromSwagger: swagger) | ||
| let modelDefinitions = try getModelDefinitions(from: document) | ||
| let responseModelDefinitions = [ModelDefinition]() |
There was a problem hiding this comment.
Response model definitions always empty breaks optimization seeding
Medium Severity
responseModelDefinitions is hardcoded to an empty array, replacing the old getResponseModelDefinitions call. This means responseModelTypeNames at line 34 is always empty, and the allModelDefinitions at line 33 no longer includes global response model definitions. While inline models are captured during operation processing, the explicit seeding of response types for optimizeModelConformance is lost, potentially changing Codable conformance decisions.
Additional Locations (1)
- [
Sources/SwaggerSwiftCore/API Factory/APIFactory.swift#L32-L38](https://github.com/lunarway/SwaggerSwift/blob/7293adadd4b26f14cb9ab7de56bfe54d1078f8cc/Sources/SwaggerSwiftCore/API Factory/APIFactory.swift#L32-L38)
Reviewed by Cursor Bugbot for commit 7293ada. Configure here.
| guard let schemaNode = schemaNode, let parameter = parameter else { | ||
| guard let requestBody = requestBody, | ||
| let schema = requestBody.content["application/json"]?.schema | ||
| else { |
There was a problem hiding this comment.
Body parameter lost for non-JSON consume types
High Severity
resolveBodyParameters only checks requestBody.content["application/json"] for the body schema. If the Swagger spec declares a non-JSON consume type (e.g. application/xml, text/plain), the converter stores the schema under that MIME type key, but this lookup returns nil, silently dropping the body parameter entirely from the generated function.
Reviewed by Cursor Bugbot for commit 7293ada. Configure here.


Summary
APIFactory.generate()now acceptsIRDocumentinstead ofSwagger, removing the directSwaggerSwiftMLdependency from the code generation engineGeneratorconvertsSwagger → IRDocumentonce after parsing, then passes it to the factoryPath,Operation,Parameter,Swagger,Schema,DataFormat— their functionality is handled byIRPathItem/IROperationor was unused dead codeimport SwaggerSwiftMLremoved from 8 model and parser filesGenerator.swiftis the only remaining file inSwaggerSwiftCorethat importsSwaggerSwiftML, solely to drive the parse → IR conversionTest plan
swift test --parallel)ResponseConformanceTestsstill passes (global responses resolved via operation processing)IgnoredPathsTestsstill passes🤖 Generated with Claude Code
Note
Medium Risk
Moderate risk because it refactors core code generation to a new
SwaggerSwiftIRlayer and changes how requests/responses, parameters, and schema composition (e.g.allOf, additionalProperties) are interpreted, which can affect generated API signatures and models.Overview
Moves code generation to a spec-agnostic intermediate representation.
SwaggerSwiftCorenow generates APIs/models fromIRDocument/IROperation/IRSchemainstead ofSwaggerSwiftML.Swagger, withGeneratorconverting parsed Swagger into IR once and passing it through.Adds a new
SwaggerSwiftIRtarget and OpenAPI 3 support plumbing. This introduces IR types (document/paths/operations/params/request bodies/responses/schemas/servers) plus converters for Swagger 2 (SwaggerToIRConverter+ schema helpers) and OpenAPI 3 (OpenAPI3Documentdecoding +OpenAPI3ToIRConverter).Updates request/model generation semantics to IR. Parameter handling is reworked around
requestBody/media types, query array serialization now usesIRParameterStyle, model resolution adds handling forallOf,$refqualification rules, and dictionary-likeadditionalProperties; several Swagger-specific extensions/utilities are removed as dead/obsolete.Also renames CLI/CI flag to
--github-tokenand adds repository guidance inCLAUDE.md.Reviewed by Cursor Bugbot for commit 7293ada. Bugbot is set up for automated code reviews on this repo. Configure here.