Skip to content

Commit 2c903eb

Browse files
author
Ignacio Bonafonte
authored
Merge pull request #277 from Sherlouk/resilient-script
Improve SemanticConvention generation template: At the moment, if you run the generate script, it will make changes to the project which will cause compiler or test failures. The three failures which this protects against: The value "int" being used as an enum value. This needs to be "Int" instead. The keyword "internal" being used as a case value. This should be wrapped with backticks like internal. The Swift telemetry language which we have chosen to add, outside of the specification. While not technically a failure, this change will also revert the documentation changes made in a previous PR which changed all the Int values to "int" incorrectly. This fixes that too.
2 parents a03ac38 + 694809e commit 2c903eb

File tree

3 files changed

+75
-257
lines changed

3 files changed

+75
-257
lines changed

Scripts/semantic-convention/templates/SemanticAttributes.swift.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
Bool
1414
{%- elif type == "number" -%}
1515
Int
16+
{%- elif type == "int" -%}
17+
Int
1618
{%- else -%}
1719
{{type}}
1820
{%- endif -%}
@@ -26,6 +28,7 @@ import Foundation
2628
public enum {{enum}}: String {
2729

2830
{%- for attribute in attributes | unique(attribute="fqn") %}
31+
{%- set class_name = attribute.fqn | to_camelcase(True) ~ "Values" %}
2932
/**
3033
{{attribute.brief | to_doc_brief}}.
3134
{%- if attribute.examples %}
@@ -50,7 +53,11 @@ public enum {{enum}}: String {
5053
- Warning: Deprecated • {{attribute.deprecated | to_doc_brief}}.
5154
{%- endif %}
5255

56+
{%- if attribute.is_enum %}
57+
- Requires: Value should be one of [`{{enum}}.{{class_name}}`](x-source-tag://otel{{class_name}}) (of type `{{to_swift_return_type(attribute.attr_type|lower)}}`)
58+
{% else %}
5359
- Requires: Value type should be `{{to_swift_return_type(attribute.attr_type|lower)}}`
60+
{% endif -%}
5461
*/
5562
{%- if attribute.deprecated %}
5663
@available(*, deprecated)
@@ -76,6 +83,7 @@ public enum {{enum}}: String {
7683
/**
7784
{{attribute.brief | to_doc_brief}}.
7885
*/
86+
/// - Tag: otel{{class_name}}
7987
{%- if attribute.attr_type.custom_values %}
8088
public struct {{class_name}}: CustomStringConvertible {
8189
{%- for member in attribute.attr_type.members %}
@@ -101,7 +109,7 @@ public enum {{enum}}: String {
101109
/**
102110
{{member.brief | to_doc_brief}}.
103111
*/
104-
case {{ member.member_id | replace(".", "_") }} = {{ print_value(type, member.value) }}
112+
case {{ member.member_id | replace(".", "_") | replace("internal", "`internal`") }} = {{ print_value(type, member.value) }}
105113
{%- endfor %}
106114
}
107115
{% endif %}

0 commit comments

Comments
 (0)