OpenAPISwiftCodeGenerate

1.0.3

amzn/openapi-swift-code-generate

What's New

Update SwaggerParser repository location because original is 404

2024-05-27T20:39:38Z

What's Changed

New Contributors

Full Changelog: 1.0.2...1.0.3

Build - Main Branch Swift 5.6, 5.7 and 5.8 Tested Join the Smoke Server Side community on gitter Apache 2

OpenAPISwiftCodeGenerate

OpenAPISwiftCodeGenerate is an extension of ServiceModelSwiftCodeGenerate that can be used to generate code based on OpenAPI/Swagger service models. This library can be integrated into higher level code generation applications.

Getting Started

Step 1: Add the OpenAPISwiftCodeGenerate dependency

OpenAPISwiftCodeGenerate uses the Swift Package Manager. To use the framework, add the following dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/amzn/openapi-swift-code-generate.git", .upToNextMajor(from: "0.1.0"))
]

Step 2: Use the library to generate code

OpenAPIServiceModel and SwaggerServiceModel both implement the ServiceModel protocol so they can be passed into the ServiceModelGenerate.generateFromModel function defined in ServiceModelSwiftCodeGenerate.

For example, given the following code generator:

public struct MyCodeGeneration {
    static let asyncResultType = AsyncResultType(typeName: "HTTPResult",
                                                 libraryImport: "SmokeHTTPClient")
    
    public static func generateFromModel<ModelType: ServiceModel>(
        modelFilePath: String,
        modelType: ModelType.Type,
        customizations: CodeGenerationCustomizations,
        applicationDescription: ApplicationDescription,
        modelOverride: ModelOverride?,
        ...) throws {
            func generatorFunction(codeGenerator: ServiceModelCodeGenerator,
                                   serviceModel: ModelType) throws {
                try codeGenerator.generateFromModel(serviceModel: serviceModel, ...)
            }
        
            try ServiceModelGenerate.generateFromModel(
                    modelFilePath: modelFilePath,
                    customizations: customizations,
                    applicationDescription: applicationDescription,
                    modelOverride: modelOverride,
                    generatorFunction: generatorFunction)
    }
}

OpenAPI and Swagger files can be parsed as follows:

let modelFilePath = ...
let customizations = ...
let applicationDescription = ...
let modelOverride = ...

// For OpenAPI files
try MyCodeGeneration.generateFromModel(
    modelFilePath: modelFilePath,
    modelType: OpenAPIServiceModel.Type, // Defined in OpenAPIServiceModel target
    customizations: customizations,
    applicationDescription: applicationDescription,
    modelOverride: modelOverride
)

// For Swagger files
try MyCodeGeneration.generateFromModel(
    modelFilePath: modelFilePath,
    modelType: SwaggerServiceModel.Type, // Defined in OpenAPIServiceModel target
    customizations: customizations,
    applicationDescription: applicationDescription,
    modelOverride: modelOverride
)

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Sun Oct 20 2024 10:33:47 GMT-0900 (Hawaii-Aleutian Daylight Time)