Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Handle the '\r\n' newline correctly #169

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Sources/_OpenAPIGeneratorCore/Renderer/TextBasedRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ struct TextBasedRenderer: RendererProtocol {
prefix = "// MARK:"
commentString = string
}
return commentString.transformingLines { line in
if line.isEmpty {
return prefix
return
commentString
.replacingOccurrences(of: "\r", with: "\n")
czechboy0 marked this conversation as resolved.
Show resolved Hide resolved
.transformingLines { line in
if line.isEmpty {
return prefix
}
return "\(prefix) \(line)"
}
return "\(prefix) \(line)"
}
}

/// Renders the specified import statements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ 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)`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ 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)`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ 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)`.
Expand Down Expand Up @@ -704,7 +706,9 @@ 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)`.
Expand Down