# Vapor testing can't find Swift OpenAPI Generator created endpoints

**URL:** <https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224>\
**Category:** Development\
**Tags:** vapor, testing, openapi\
**Created:** [July 21, 2025, 11:55am UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224 "2025-07-21T11:55:57Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 21, 2025, 11:55am UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/1 "2025-07-21T11:55:57Z")

</div>

Hi everyone,

I'm playing around with the Swift OpenAPI Generator and Vapor to see if it can be an alternative to our TypeScript based tech stack.

So far I've created a simple toy project which uses an OpenAPI spec. I can get this one running and call the endpoints as per the expected specs. ✅

Now I'm looking at testing the API. I followed the instructions on the Vapor forum: [Vapor: Advanced → Testing](https://docs.vapor.codes/advanced/testing/)

I have created the `withApp` method:

```swift
private func withApp(_ test: (Application) async throws -> ()) async throws {
    let app = try await Application.make(.testing)
    do {
        try await configure(app)
        try await test(app)
    }
    catch {
        try await app.asyncShutdown()
        throw error
    }
    try await app.asyncShutdown()
}

```

and a simple test:

```swift
        @Test("then it should return a status 200 (OK) message") func thenItShouldReturnAStatus20OKMessage() async throws {
            try await withApp { app in
                try await app.testing().test(.GET, "v1/rovers") { res async in
                    #expect(res.status == .ok)
                }
            }
        }

```

This test consistently fails with a `404 (not found)` error. Though the logs shows indeed the `/v1/rovers` endpoint is called.

However, when I run the server and call the endpoint directly using `curl http://localhost:8080/v1/rovers/` I do get the expected result back:

```swift
{
  "links" : [

  ],
  "rovers" : [
    {
      "id" : "BFE53D64-0DD9-4592-8936-BF52034D9C0F",
      "links" : [

      ],
      "pose" : {
        "heading" : "N",
        "x" : 1,
        "y" : 2
      }
    },
...

```

Am I missing something here? And/or am I supposed to test OpenAPI Generator based endpoints in a different way?

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [July 21, 2025, 1:28pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/2 "2025-07-21T13:28:15Z")

</div>

Where do you register the handlers? Is that done in your configure?

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 21, 2025, 1:29pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/3 "2025-07-21T13:29:23Z")

</div>

Hi Tim,

Yes, it's a very simple `configure` method:

```swift
// main.swift
let app = try await Vapor.Application.make()

func configure(_ app: Vapor.Application) async throws {
    let transport = VaporTransport(routesBuilder: app)
    let handler = MarsRoverAPIImplementation()
    
    try handler.registerHandlers(on: transport)
}

try await configure(app)
try await app.execute()

```

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [July 21, 2025, 5:36pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/4 "2025-07-21T17:36:27Z")

</div>

That looks like it should work fine - is there a project available to try and reproduce it?

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 22, 2025, 5:47am UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/5 "2025-07-22T05:47:49Z")

</div>

Thank you Tim,

I'll try and make a stripped out version of the project tonight.

KR Maarten

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 22, 2025, 5:52pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/6 "2025-07-22T17:52:42Z")

</div>

OK, here's a sample project (hope this way of sharing works): [iCloud Drive - Apple iCloud](https://www.icloud.com/iclouddrive/076LCGVK8dNXadqx1_upovGGA#OpenAPITest)

Also, I notice now it no longer builds the tests (regular build is fine) and shows these errors (which may or may not be related):

 ![Build errors when running tests](https://global.discourse-cdn.com/swift/original/3X/d/0/d06df47c0c5efd065a2b0ae0926ecb33e93e0093.png)

---

<div class="post-metadata">

**Author:** ![MahdiBM](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mahdibm/32/45271_2.png) [@MahdiBM](https://forums.swift.org/u/MahdiBM)\
**Post date:** [July 23, 2025, 10:15am UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/7 "2025-07-23T10:15:05Z")

</div>

I haven't checked the project but (regarding the errors in the image) off-hand I'd guess there is either a missing import or a missing dependency declaration in Package.swift. Perhaps "VaporTesting" or "Testing"?

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [July 23, 2025, 1:48pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/8 "2025-07-23T13:48:10Z")

</div>

The project builds for me, I suggest you clean the project or if that doesn't work, clear Derived Data and it should work fine

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 23, 2025, 1:57pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/9 "2025-07-23T13:57:53Z")

</div>

Did you also get the tests to pass?

I got the project to build again. Was indeed missing the `VaporTesting` dependency. But the tests still fail (unexpectedly)

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [July 23, 2025, 2:00pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/10 "2025-07-23T14:00:51Z")

</div>

Yes, though the example project you provided only has a single empty test

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 23, 2025, 2:01pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/11 "2025-07-23T14:01:20Z")

</div>

then I probably shared the wrong project. let me check.

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 23, 2025, 2:05pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/12 "2025-07-23T14:05:23Z")

</div>

@0xTim I'm so sorry to have taken up your time with the wrong project.  
This is the one that has the failing tests: [iCloud Drive - Apple iCloud](https://www.icloud.com/iclouddrive/091I5pLkVGd0TBMToIDLgQD4A#SwiftMarsRoverAPI)

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [July 23, 2025, 2:38pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/13 "2025-07-23T14:38:30Z")

</div>

Ok I can see the issue - the problem you're hitting is that the compiler is picking VaporTesting's `withApp` instead of the one you've defined so it's never registering the routes. You can fix this pretty easily by getting Vapor Testing to call the configure function. If you change your test file to

```swift
@Suite("The MarsRover API should") struct MarsRoverAPITests {
    @Suite("when the create endpoint is correctly falled") struct CreateEndPointCorrectlyCalled {
        @Test("then it should return a status 201 (Created) message") func thenItShouldReturnAStatus201CreatedMessage() async throws {
            try await withApp(configure: configure) { app in
                try await app.testing().test(.POST, "v1/rovers") { res async in
                    #expect(res.status == .created)
                }
            }
        }
    }
    
    @Suite("when the get all rovers endpoint is correctly called") struct GetAllRoversEndPointCorrectlyCalled {
        @Test("then it should return a status 200 (OK) message") func thenItShouldReturnAStatus20OKMessage() async throws {
            try await withApp(configure: configure) { app in
                try await app.testing().test(.GET, "v1/rovers") { res async in
                    #expect(res.status == .ok)
                }
            }
        }
    }
}

```

All the tests pass. (Note the `withApp(configure: configure)` call) you can remove your `withApp` implementation

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 23, 2025, 2:47pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/14 "2025-07-23T14:47:34Z")

</div>

Yes, this solved it! 🥳

Looks like the [documentation](https://docs.vapor.codes/advanced/testing/#testable-application) should be updated to reflect this change? I can create a PR if it helps.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [July 23, 2025, 2:51pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/15 "2025-07-23T14:51:36Z")

</div>

That would be great thanks!

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [July 23, 2025, 3:15pm UTC](https://forums.swift.org/t/vapor-testing-cant-find-swift-openapi-generator-created-endpoints/81224/16 "2025-07-23T15:15:40Z")

</div>

Draft PR: [Update testing documentation to include withApp(configure:) method by maartene · Pull Request #1086 · vapor/docs · GitHub](https://github.com/vapor/docs/pull/1086)
