Skip to content

Commit 4e46a0f

Browse files
committed
Update Generator to support Deprecated struct
open-telemetry/semantic-conventions#2047
1 parent 1ca1074 commit 4e46a0f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Generator/Sources/FileRenderers/OTelAttributeRenderer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct OTelAttributeRenderer: FileRenderer {
5151

5252
private func renderAttribute(_ attribute: Attribute, _ namespace: Namespace, indent: Int) throws -> String {
5353
var result = renderDocs(attribute)
54-
if let deprecatedMessage = attribute.deprecated {
54+
if let deprecatedMessage = attribute.deprecated?.note?.trimmingCharacters(in: .whitespacesAndNewlines) {
5555
result.append("\n@available(*, deprecated, message: \"\(deprecatedMessage)\")")
5656
}
5757
try result.append(

Generator/Sources/FileRenderers/SpanAttributeRenderer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct SpanAttributeRenderer: FileRenderer {
110110
propertyName = nameGenerator.swiftMemberName(for: propertyName)
111111

112112
var result = renderDocs(attribute)
113-
if let deprecatedMessage = attribute.deprecated {
113+
if let deprecatedMessage = attribute.deprecated?.note?.trimmingCharacters(in: .whitespacesAndNewlines) {
114114
result.append("\n@available(*, deprecated, message: \"\(deprecatedMessage)\")")
115115
}
116116

@@ -247,7 +247,7 @@ struct SpanAttributeRenderer: FileRenderer {
247247
case .templateBoolean, .templateBooleanArray, .templateInt, .templateIntArray, .templateDouble,
248248
.templateDoubleArray, .templateString, .templateStringArray:
249249
return true
250-
case .boolean, .booleanArray, .int, .intArray, .double, .doubleArray, .string, .stringArray:
250+
case .boolean, .booleanArray, .int, .intArray, .double, .doubleArray, .string, .stringArray, .any:
251251
return false
252252
}
253253
} else {

Generator/Sources/RegistryFile.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct Attribute: Decodable {
4444
let stability: Stability
4545
let brief: String?
4646
let note: String?
47-
let deprecated: String?
47+
let deprecated: Deprecated?
4848
let examples: [String]?
4949

5050
enum RequirementLevel: String, Codable {
@@ -66,7 +66,7 @@ struct Attribute: Decodable {
6666
stability = try container.decodeIfPresent(Stability.self, forKey: .stability) ?? .experimental
6767
brief = try container.decodeIfPresent(String.self, forKey: .brief)
6868
note = try container.decodeIfPresent(String.self, forKey: .note)
69-
deprecated = try container.decodeIfPresent(String.self, forKey: .deprecated)
69+
deprecated = try container.decodeIfPresent(Deprecated.self, forKey: .deprecated)
7070
if !container.contains(.examples) {
7171
examples = nil
7272
} else if let example = try? container.decode(String.self, forKey: .examples) {
@@ -107,6 +107,7 @@ struct Attribute: Decodable {
107107
case stringArray = "string[]"
108108
case templateString = "template[string]"
109109
case templateStringArray = "template[string[]]"
110+
case any
110111
}
111112

112113
struct EnumType: AttributeType {
@@ -130,6 +131,10 @@ extension Double: AttributeExample {}
130131
extension Int: AttributeExample {}
131132
extension String: AttributeExample {}
132133

134+
struct Deprecated: Codable {
135+
let note: String?
136+
}
137+
133138
enum Stability: String, Codable {
134139
case development
135140
case experimental

0 commit comments

Comments
 (0)