forked from apple/swift-openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderedSwiftRepresentation.swift
70 lines (60 loc) · 2.44 KB
/
RenderedSwiftRepresentation.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
//
// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#if os(Linux)
@preconcurrency import struct Foundation.URL
#else
import struct Foundation.URL
#endif
import struct Foundation.Data
/// An in-memory file that contains the generated Swift code.
typealias RenderedSwiftRepresentation = InMemoryOutputFile
/// An in-memory input file that contains the raw data of an OpenAPI document.
///
/// Contents are formatted as either YAML or JSON.
public struct InMemoryInputFile: Sendable {
/// The absolute path to the file.
public var absolutePath: URL
/// The YAML or JSON file contents encoded as UTF-8 data.
public var contents: Data
/// Creates a file with the specified path and contents.
/// - Parameters:
/// - absolutePath: An absolute path to the file.
/// - contents: Data contents of the file, encoded as UTF-8.
public init(absolutePath: URL, contents: Data) {
self.absolutePath = absolutePath
self.contents = contents
}
}
/// An in-memory output file that contains the generated Swift source code.
public struct InMemoryOutputFile: Sendable {
/// The base name of the file.
public var baseName: String
/// The Swift file contents encoded as UTF-8 data.
public var contents: Data
/// Creates a file with the specified name and contents.
/// - Parameters:
/// - baseName: A base name representing the desired name.
/// - contents: Data contents of the file, encoded as UTF-8.
public init(baseName: String, contents: Data) {
self.baseName = baseName
self.contents = contents
}
}
extension InMemoryOutputFile: Comparable {
/// Compares two `InMemoryOutputFile` instances based on `baseName` and contents for ordering.
public static func < (lhs: InMemoryOutputFile, rhs: InMemoryOutputFile) -> Bool {
guard lhs.baseName == rhs.baseName else { return lhs.baseName < rhs.baseName }
return lhs.contents.base64EncodedString() < rhs.contents.base64EncodedString()
}
}