Skip to content

Commit

Permalink
feat: refactor swift enum
Browse files Browse the repository at this point in the history
  • Loading branch information
akashrpo committed Feb 3, 2025
1 parent 169505f commit fa7be85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/generators/swift/swift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type SwiftPropertyContext = {
enumName?: string;
// The formatted enum values
enumValues?: any;
// The type of the enum values
enumType?: string;
};

type SwiftTrackCallContext = {
Expand Down Expand Up @@ -206,6 +208,7 @@ function defaultPropertyContext(
hasEnum: !!hasEnum,
enumName: sanitizeEnumKey(schema.name) + '_' + getEnumPropertyTypes(schema),
enumValues: hasEnum && 'enum' in schema ? convertToEnum(schema.enum!, type) : undefined,
enumType: type === 'Any' ? 'String' : type,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/generators/swift/templates/analytics.swift.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RudderTyperAnalytics {
{{#each properties}}
{{#if hasEnum}}
{{#uniqueEnum enumName enumValues}}
public enum {{enumName}}: {{../type}} {
enum {{enumName}}: {{../enumType}} {
{{enumValues}}
}

Expand Down
8 changes: 8 additions & 0 deletions src/generators/swift/templates/class.swift.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import Foundation

class {{name}}: RudderTyperSerializable {
{{#each properties}}
{{#if hasEnum}}
{{#uniqueEnum enumName enumValues}}
enum {{enumName}}: {{../enumType}} {
{{enumValues}}
}
{{/uniqueEnum}}
{{/if}}

{{#if description}}
/// {{description}}
{{/if}}
Expand Down

0 comments on commit fa7be85

Please sign in to comment.