Search code examples
iosswiftopenapiswift-package-manageropenapi-generator

Trouble Adding OpenAPIGenerator Plugin to Run Build Tool Plug-ins in Xcode Using SPM


I'm using SPM in my project and am trying to integrate Apple/swift-openapi-generator. My project is divided into several modules, for which I'm using SPM. To manage dependencies, I have a Package.swift file.

// swift-tools-version:5.8

import Foundation
import PackageDescription

let openAPIRuntime = Target.Dependency.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime")
let openAPIURLSession = Target.Dependency.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession")
let openAPIGenerator = Target.PluginUsage.plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator")

let targets: [Target] = [
    .target(
        name: "OpenAPIClient",
        dependencies: [openAPIRuntime, openAPIURLSession],
        plugins: [openAPIGenerator]
    ),
    //...
    ]

let package = Package(
    name: "Modules",
    platforms: [.iOS("16.0"), .macOS(.v11)],
    products: targets.filter { !$0.isTest }.map { .library(name: $0.name, targets: [$0.name]) },
    dependencies: [
        .package(url: "https://github.com/apple/swift-openapi-generator", from: "0.1.0"),
        .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
        .package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
        //...
    ],
    targets: targets
)

As demonstrated, I've added openAPIRuntime and openAPIURLSession products and the openAPIGenerator plugin to this file. As a result, I'm able to successfully build the project.

Now, I want to add the openAPIGenerator plugin in MyTarget -> Build Phases -> Run Build Tool Plug-ins, but when I press the + button, I can't find openAPIGenerator.

enter image description here

How can I solve this issue?


Solution

  • You probably added a different version of the OpenApi package to your main project as you added within your Package.swift.

    As you wrote you added "0.1.0"in your Package.swift file. Make sure you add the same version in your app: Same version

    Xcode uses by default this:

    Different version