From 49b311571445c1fe03f774c02211c649f6ce629d Mon Sep 17 00:00:00 2001 From: Arthur Crocquevieille Date: Thu, 17 Aug 2023 22:03:18 +0200 Subject: [PATCH] Add test for generated server register handlers without operations --- .../ServerTranslator/ServerTranslator.swift | 2 +- .../SnippetBasedReferenceTests.swift | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift b/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift index b6289962..8438309f 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift @@ -98,7 +98,7 @@ struct ServerFileTranslator: FileTranslator { } let serverMethodDecls = serverMethodDeclPairs.map(\.functionDecl) - // To avoid an used variable warning, we add the server variable declaration + // To avoid an unused variable warning, we add the server variable declaration // and server method register calls to the body of the register handler declaration // only when there is at least one registration call. if !serverMethodDeclPairs.isEmpty { diff --git a/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift b/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift index bcc7e95a..8d13b645 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift @@ -1223,6 +1223,23 @@ final class SnippetBasedReferenceTests: XCTestCase { ) } + func testServerRegisterHandlers_noOperation() throws { + try self.assertServerRegisterHandlers( + """ + {} + """, + """ + public func registerHandlers( + on transport: any ServerTransport, + serverURL: URL = .defaultOpenAPIServerURL, + configuration: Configuration = .init(), + middlewares: [any ServerMiddleware] = [] + ) throws { + } + """ + ) + } + func testPathWithPathItemReference() throws { XCTAssertThrowsError( try self.assertPathsTranslation(