From 1c68d8475103c29ca33884b99a274ce4818ee8e2 Mon Sep 17 00:00:00 2001 From: Stefana Dranca Date: Mon, 27 Nov 2023 17:21:58 +0200 Subject: [PATCH 1/4] Created the SorceFile struct that represents the file to be created by the code generator. Motivation: The CodeRenderer needs to create objects of some type representing the files containing the generated code. This type is SourceFile. Modifications: Implemented the SourceFile struct, containing a name as a String and the generated code as Data. Result: The Code Renderer can now be brought from the OpenAPI generator, as it will have an output type. The code generator will use objects of this type to create the files containing the generated Swift code. --- Sources/GRPCCodeGen/SourceFile.swift | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Sources/GRPCCodeGen/SourceFile.swift diff --git a/Sources/GRPCCodeGen/SourceFile.swift b/Sources/GRPCCodeGen/SourceFile.swift new file mode 100644 index 000000000..3351c42aa --- /dev/null +++ b/Sources/GRPCCodeGen/SourceFile.swift @@ -0,0 +1,8 @@ +// +// File.swift +// +// +// Created by Stefana Dranca on 27/11/2023. +// + +import Foundation From 0a6693f70e5a4d85549b2d4093adab690b48cc3d Mon Sep 17 00:00:00 2001 From: Stefana Dranca Date: Mon, 27 Nov 2023 17:56:50 +0200 Subject: [PATCH 2/4] added Sendable conformance --- Sources/GRPCCodeGen/SourceFile.swift | 38 +++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Sources/GRPCCodeGen/SourceFile.swift b/Sources/GRPCCodeGen/SourceFile.swift index 3351c42aa..bce08f321 100644 --- a/Sources/GRPCCodeGen/SourceFile.swift +++ b/Sources/GRPCCodeGen/SourceFile.swift @@ -1,8 +1,32 @@ -// -// File.swift -// -// -// Created by Stefana Dranca on 27/11/2023. -// +/* + * Copyright 2023, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import Foundation +/// Representation of the file to be created by the code generator, that contains the +/// generated Swift source code. +public struct SourceFile: Sendable { + /// The base name of the file. + public var name: String + + /// The generated code encoded as UTF-8 data. + public var sourceCode: Data + + /// Creates a representation of a file containing Swift code with the specified name + /// and contents. + public init(name: String, sourceCode: Data) { + self.name = name + self.sourceCode = sourceCode + } +} From 5d0f4f83f92ceff53fc3c22dad21923373bc0f3a Mon Sep 17 00:00:00 2001 From: Stefana Dranca Date: Mon, 27 Nov 2023 18:08:28 +0200 Subject: [PATCH 3/4] switched the type of the sourceCode from Data to String --- Sources/GRPCCodeGen/SourceFile.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/GRPCCodeGen/SourceFile.swift b/Sources/GRPCCodeGen/SourceFile.swift index bce08f321..aef640815 100644 --- a/Sources/GRPCCodeGen/SourceFile.swift +++ b/Sources/GRPCCodeGen/SourceFile.swift @@ -20,12 +20,12 @@ public struct SourceFile: Sendable { /// The base name of the file. public var name: String - /// The generated code encoded as UTF-8 data. - public var sourceCode: Data + /// The generated code as a String. + public var sourceCode: String /// Creates a representation of a file containing Swift code with the specified name - /// and contents. - public init(name: String, sourceCode: Data) { + /// and contents. + public init(name: String, sourceCode: String) { self.name = name self.sourceCode = sourceCode } From ef16d63c7e1e740f02403a6d048d4c3ed662a257 Mon Sep 17 00:00:00 2001 From: Stefana Dranca Date: Mon, 27 Nov 2023 18:20:54 +0200 Subject: [PATCH 4/4] implemented feedback --- Sources/GRPCCodeGen/SourceFile.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/GRPCCodeGen/SourceFile.swift b/Sources/GRPCCodeGen/SourceFile.swift index aef640815..c435fb100 100644 --- a/Sources/GRPCCodeGen/SourceFile.swift +++ b/Sources/GRPCCodeGen/SourceFile.swift @@ -16,17 +16,17 @@ /// Representation of the file to be created by the code generator, that contains the /// generated Swift source code. -public struct SourceFile: Sendable { +public struct SourceFile: Sendable, Hashable { /// The base name of the file. public var name: String /// The generated code as a String. - public var sourceCode: String + public var contents: String /// Creates a representation of a file containing Swift code with the specified name /// and contents. - public init(name: String, sourceCode: String) { + public init(name: String, contents: String) { self.name = name - self.sourceCode = sourceCode + self.contents = contents } }