Skip to content

Commit

Permalink
generate JSDoc style comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gabormagyar committed Feb 25, 2022
1 parent 10aca3b commit e3a8748
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/generators/typescript/TypeScriptRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,24 @@ ${renderedLines}

renderProperty(propertyName: string, property: CommonModel, type: PropertyType = PropertyType.property): string {
const formattedPropertyName = this.nameProperty(propertyName, property);

const desc = property.getFromOriginalInput('description')?.trim();
const examples = property.getFromOriginalInput('examples');
const formattedExamples = `@example ${examples?.join ? examples.join(', ') : examples}`
const doc = this.renderComments(`${desc || ''}\n${examples ? formattedExamples : ''}`.trim());
const formattedDoc = desc || examples ? `${doc}\n` : '';

let signature: string;
switch (type) {
case PropertyType.property:
signature = this.renderTypeSignature(property, { isRequired: this.model.isRequired(propertyName) });
return `${formattedPropertyName}${signature};`;
case PropertyType.additionalProperty:
case PropertyType.patternProperties:
signature = this.renderType(property);
return `${formattedPropertyName}?: Map<String, ${signature}>;`;
default:
return '';
case PropertyType.property:
signature = this.renderTypeSignature(property, { isRequired: this.model.isRequired(propertyName) });
return `${formattedDoc}${formattedPropertyName}${signature};`;
case PropertyType.additionalProperty:
case PropertyType.patternProperties:
signature = this.renderType(property);
return `${formattedPropertyName}?: Map<String, ${signature}>;`;
default:
return '';
}
}

Expand Down

0 comments on commit e3a8748

Please sign in to comment.