Skip to content

Commit

Permalink
feat: include parameter details in Swift docstrings (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
akashrpo authored Jan 21, 2025
1 parent 456921d commit 5fdfa31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/generators/swift/swift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Type, Schema } from '../ast.js';
import Handlebars from 'handlebars';
import { Generator, BasePropertyContext, GeneratorClient } from '../gen.js';
import lodash from 'lodash';
import { registerPartial } from '../../templates.js';

const { camelCase, upperFirst } = lodash;

Expand Down Expand Up @@ -61,6 +62,10 @@ export const swift: Generator<
allowedIdentifierChars: 'A-Za-z0-9_$',
},
setup: async () => {
await registerPartial(
'generators/swift/templates/functionDocumentation.hbs',
'functionDocumentation',
);
Handlebars.registerHelper('propertiesDictionary', generatePropertiesDictionary);
Handlebars.registerHelper('functionCall', generateFunctionCall);
Handlebars.registerHelper('functionSignature', generateFunctionSignature);
Expand Down
4 changes: 1 addition & 3 deletions src/generators/swift/templates/analytics.swift.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class RudderTyperAnalytics {
{{functionCall "RudderTyperAnalytics" functionName properties "options" "RSOption()"}}
}

{{#if functionDescription}}
/// {{functionDescription}}
{{/if}}
{{> functionDocumentation }}
static func {{functionSignature functionName properties true}} {
{{indent " " (propertiesDictionary properties)}}

Expand Down
13 changes: 13 additions & 0 deletions src/generators/swift/templates/functionDocumentation.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
{{#if functionDescription}}
{{functionDescription}}
{{else}}
Fires a '{{functionName}}' track call.
{{/if}}

- Parameters:
{{#each properties}}
- {{name}}: {{#if isRequired}}{{type}} (required){{else}}{{type}} (optional){{/if}}{{#if description}} - {{description}}{{/if}}
{{/each}}
- options: Event-level options (optional)
*/

0 comments on commit 5fdfa31

Please sign in to comment.