diff --git a/Sources/_OpenAPIGeneratorCore/Renderer/TextBasedRenderer.swift b/Sources/_OpenAPIGeneratorCore/Renderer/TextBasedRenderer.swift index e0da301c..3fe4699e 100644 --- a/Sources/_OpenAPIGeneratorCore/Renderer/TextBasedRenderer.swift +++ b/Sources/_OpenAPIGeneratorCore/Renderer/TextBasedRenderer.swift @@ -54,12 +54,14 @@ struct TextBasedRenderer: RendererProtocol { prefix = "// MARK:" commentString = string } - return commentString.transformingLines { line in - if line.isEmpty { - return prefix + return + commentString + .transformingLines { line in + if line.isEmpty { + return prefix + } + return "\(prefix) \(line)" } - return "\(prefix) \(line)" - } } /// Renders the specified import statements. @@ -721,7 +723,7 @@ fileprivate extension String { /// Returns an array of strings, where each string represents one line /// in the current string. func asLines() -> [String] { - split(separator: "\n", omittingEmptySubsequences: false) + split(omittingEmptySubsequences: false, whereSeparator: \.isNewline) .map(String.init) } diff --git a/Tests/OpenAPIGeneratorCoreTests/Renderer/Test_TextBasedRenderer.swift b/Tests/OpenAPIGeneratorCoreTests/Renderer/Test_TextBasedRenderer.swift index f1b30e63..35cada04 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Renderer/Test_TextBasedRenderer.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Renderer/Test_TextBasedRenderer.swift @@ -67,6 +67,19 @@ final class Test_TextBasedRenderer: XCTestCase { // MARK: - Lorem ipsum """# ) + try _test( + .inline( + """ + Generated by foo\r\nAlso, bar + """ + ), + renderedBy: renderer.renderedComment, + rendersAs: + #""" + // Generated by foo + // Also, bar + """# + ) } func testImports() throws { diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml b/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml index b8dce4fe..a367d7f5 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml @@ -16,7 +16,7 @@ paths: description: "Even more information about working with pets" get: summary: List all pets - description: "You can fetch all the pets here" + description: "You can fetch\r\nall the pets here" operationId: listPets tags: - pets diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift index 0c9e2b2c..60d3b3c4 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift @@ -35,7 +35,8 @@ public struct Client: APIProtocol { private var converter: Converter { client.converter } /// List all pets /// - /// You can fetch all the pets here + /// You can fetch + /// all the pets here /// /// - Remark: HTTP `GET /pets`. /// - Remark: Generated from `#/paths//pets/get(listPets)`. diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Server.swift b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Server.swift index 628e9805..fc3dc9a7 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Server.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Server.swift @@ -60,7 +60,8 @@ extension APIProtocol { fileprivate extension UniversalServer where APIHandler: APIProtocol { /// List all pets /// - /// You can fetch all the pets here + /// You can fetch + /// all the pets here /// /// - Remark: HTTP `GET /pets`. /// - Remark: Generated from `#/paths//pets/get(listPets)`. diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift index 2db92dc5..e8cadeb1 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift @@ -9,7 +9,8 @@ import Foundation public protocol APIProtocol: Sendable { /// List all pets /// - /// You can fetch all the pets here + /// You can fetch + /// all the pets here /// /// - Remark: HTTP `GET /pets`. /// - Remark: Generated from `#/paths//pets/get(listPets)`. @@ -704,7 +705,8 @@ public enum Components { public enum Operations { /// List all pets /// - /// You can fetch all the pets here + /// You can fetch + /// all the pets here /// /// - Remark: HTTP `GET /pets`. /// - Remark: Generated from `#/paths//pets/get(listPets)`.