Repository navigation
fix(markdown): render map and scalar declarations and correct stereotypes #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,11 +117,56 @@ class MarkdownVisitor extends BaseVisitor { | |
| * @return {Object} the result of visiting or null | ||
| * @private | ||
| */ | ||
| visitClassDeclaration(classDeclaration, parameters) { | ||
| visitAssetDeclaration(classDeclaration, parameters) { | ||
| return this.visitClassDeclaration(classDeclaration, parameters, 'Asset'); | ||
| } | ||
|
|
||
| /** | ||
| * Visitor design pattern | ||
| * @param {ClassDeclaration} classDeclaration - the object being visited | ||
| * @param {Object} parameters - the parameter | ||
| * @return {Object} the result of visiting or null | ||
| * @private | ||
| */ | ||
| visitParticipantDeclaration(classDeclaration, parameters) { | ||
| return this.visitClassDeclaration(classDeclaration, parameters, 'Participant'); | ||
| } | ||
|
|
||
| /** | ||
| * Visitor design pattern | ||
| * @param {ClassDeclaration} classDeclaration - the object being visited | ||
| * @param {Object} parameters - the parameter | ||
| * @return {Object} the result of visiting or null | ||
| * @private | ||
| */ | ||
| visitTransactionDeclaration(classDeclaration, parameters) { | ||
| return this.visitClassDeclaration(classDeclaration, parameters, 'Transaction'); | ||
| } | ||
|
|
||
| /** | ||
| * Visitor design pattern | ||
| * @param {ClassDeclaration} classDeclaration - the object being visited | ||
| * @param {Object} parameters - the parameter | ||
| * @return {Object} the result of visiting or null | ||
| * @private | ||
| */ | ||
| visitEventDeclaration(classDeclaration, parameters) { | ||
| return this.visitClassDeclaration(classDeclaration, parameters, 'Event'); | ||
| } | ||
|
|
||
| /** | ||
| * Visitor design pattern | ||
| * @param {ClassDeclaration} classDeclaration - the object being visited | ||
| * @param {Object} parameters - the parameter | ||
| * @param {string} [type] - the declaration type (e.g. Concept, Asset, Participant, Transaction, Event) | ||
| * @return {Object} the result of visiting or null | ||
| * @private | ||
| */ | ||
| visitClassDeclaration(classDeclaration, parameters, type = 'Concept') { | ||
| parameters.stack.push(classDeclaration.getFullyQualifiedName()); | ||
|
|
||
| parameters.fileWriter.writeLine(0, ''); | ||
| parameters.fileWriter.writeLine(0, `### ${classDeclaration.getName()} (Concept)`); | ||
| parameters.fileWriter.writeLine(0, `### ${classDeclaration.getName()} (${type})`); | ||
| parameters.fileWriter.writeLine(0, ''); | ||
|
|
||
| const descriptionDecorator = classDeclaration.getDecorator('description'); | ||
|
|
@@ -140,7 +185,7 @@ class MarkdownVisitor extends BaseVisitor { | |
| parameters.fileWriter.writeLine(0, ''); | ||
|
|
||
| if (classDeclaration.getProperties().length > 0) { | ||
| parameters.fileWriter.writeLine(0, '| Field | Type | Required | Identifier | Reference | Inherited | Description | Contraints | '); | ||
| parameters.fileWriter.writeLine(0, '| Field | Type | Required | Identifier | Reference | Inherited | Description | Constraints | '); | ||
| parameters.fileWriter.writeLine(0, '| ------ | ------------------- | --- | --- | --- | --- |------------ | --------- |'); | ||
| classDeclaration.getProperties().forEach((property) => { | ||
| property.accept(this, parameters); | ||
|
|
@@ -203,6 +248,91 @@ class MarkdownVisitor extends BaseVisitor { | |
| parameters.fileWriter.writeLine(0, `| ${enumValueDeclaration.getName()} |${descriptionDecorator?.getArguments()[0] || ''} |`); | ||
| } | ||
|
|
||
| /** | ||
| * Visitor design pattern | ||
| * @param {MapDeclaration} mapDeclaration - the object being visited | ||
| * @param {Object} parameters - the parameter | ||
| * @return {Object} the result of visiting or null | ||
| * @private | ||
| */ | ||
| visitMapDeclaration(mapDeclaration, parameters) { | ||
| parameters.stack.push(mapDeclaration.getFullyQualifiedName()); | ||
|
|
||
| parameters.fileWriter.writeLine(0, ''); | ||
| parameters.fileWriter.writeLine(0, `### ${mapDeclaration.getName()} (Map)`); | ||
| parameters.fileWriter.writeLine(0, ''); | ||
|
|
||
| const descriptionDecorator = mapDeclaration.getDecorator('description'); | ||
| if (descriptionDecorator && descriptionDecorator.getArguments().length > 0) { | ||
| parameters.fileWriter.writeLine(0, descriptionDecorator?.getArguments()[0] || ''); | ||
| } | ||
|
|
||
| const keyType = mapDeclaration.getKey().getType(); | ||
| const valueType = mapDeclaration.getValue().getType(); | ||
|
|
||
| parameters.fileWriter.writeLine(0, '| Key Type | Value Type |'); | ||
| parameters.fileWriter.writeLine(0, '| -------- | ---------- |'); | ||
| parameters.fileWriter.writeLine(0, `| <code>${keyType}</code> | <code>${valueType}</code> |`); | ||
| parameters.fileWriter.writeLine(0, ''); | ||
|
|
||
| mapDeclaration.getDecorators().forEach(decorator => decorator.accept(this, parameters)); | ||
|
|
||
| parameters.stack.pop(); | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Visitor design pattern | ||
| * @param {ScalarDeclaration} scalarDeclaration - the object being visited | ||
| * @param {Object} parameters - the parameter | ||
| * @return {Object} the result of visiting or null | ||
| * @private | ||
| */ | ||
| visitScalarDeclaration(scalarDeclaration, parameters) { | ||
| parameters.stack.push(scalarDeclaration.getFullyQualifiedName()); | ||
|
|
||
| parameters.fileWriter.writeLine(0, ''); | ||
| parameters.fileWriter.writeLine(0, `### ${scalarDeclaration.getName()} (Scalar)`); | ||
| parameters.fileWriter.writeLine(0, ''); | ||
|
|
||
| const descriptionDecorator = scalarDeclaration.getDecorator('description'); | ||
| if (descriptionDecorator && descriptionDecorator.getArguments().length > 0) { | ||
| parameters.fileWriter.writeLine(0, descriptionDecorator?.getArguments()[0] || ''); | ||
| } | ||
|
|
||
| let constraints = []; | ||
| const validator = scalarDeclaration.getValidator?.(); | ||
| if (validator) { | ||
| if (validator.getMinLength?.() !== undefined && typeof validator.getMinLength() === 'number') { | ||
| constraints.push(`Minimum Length: ${validator.getMinLength()}`); | ||
| } | ||
| if (validator.getMaxLength?.() !== undefined && typeof validator.getMaxLength() === 'number') { | ||
| constraints.push(`Maximum Length: ${validator.getMaxLength()}`); | ||
| } | ||
| if (validator.getRegex?.()) { | ||
| constraints.push(`Matches Regular Expression: \`${validator.getRegex()}\``); | ||
| } | ||
| if (validator.getLowerBound?.() !== undefined && typeof validator.getLowerBound() === 'number') { | ||
| constraints.push(`Minimum Value: ${validator.getLowerBound()}`); | ||
| } | ||
| if (validator.getUpperBound?.() !== undefined && typeof validator.getUpperBound() === 'number') { | ||
| constraints.push(`Maximum Value: ${validator.getUpperBound()}`); | ||
| } | ||
| } | ||
|
|
||
| const defaultValue = scalarDeclaration.getDefaultValue?.() ? `<code>${scalarDeclaration.getDefaultValue()}</code>` : ''; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should-fix · correctness
|
||
|
|
||
| parameters.fileWriter.writeLine(0, '| Type | Default Value | Constraints |'); | ||
| parameters.fileWriter.writeLine(0, '| ---- | ------------- | ----------- |'); | ||
| parameters.fileWriter.writeLine(0, `| <code>${scalarDeclaration.getType()}</code> | ${defaultValue} | ${constraints.join('<br>')} |`); | ||
| parameters.fileWriter.writeLine(0, ''); | ||
|
|
||
| scalarDeclaration.getDecorators().forEach(decorator => decorator.accept(this, parameters)); | ||
|
|
||
| parameters.stack.pop(); | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Visitor design pattern | ||
| * @param {Field} field - the object being visited | ||
|
|
@@ -237,38 +367,38 @@ class MarkdownVisitor extends BaseVisitor { | |
|
|
||
| const validator = field.getValidator?.(); | ||
|
|
||
| let contraints = []; | ||
| let constraints = []; | ||
| if(validator) { | ||
| if(validator.getMinLength?.() !== undefined && typeof validator.getMinLength() === 'number') { | ||
| contraints.push(`Minimum Length: ${validator.getMinLength()}`); | ||
| constraints.push(`Minimum Length: ${validator.getMinLength()}`); | ||
| } | ||
| if(validator.getMaxLength?.() !== undefined && typeof validator.getMaxLength() === 'number') { | ||
| contraints.push(`Maximum Length: ${validator.getMaxLength()}`); | ||
| constraints.push(`Maximum Length: ${validator.getMaxLength()}`); | ||
| } | ||
| if (validator.getRegex?.()) { | ||
| contraints.push(`Matches Regular Expression: \`${validator.getRegex()}\``); | ||
| constraints.push(`Matches Regular Expression: \`${validator.getRegex()}\``); | ||
| } | ||
| if(validator.getLowerBound?.() !== undefined && typeof validator.getLowerBound() === 'number') { | ||
| contraints.push(`Minimum Value: ${validator.getLowerBound()}`); | ||
| constraints.push(`Minimum Value: ${validator.getLowerBound()}`); | ||
| } | ||
| if(validator.getUpperBound?.() !== undefined && typeof validator.getUpperBound() === 'number') { | ||
| contraints.push(`Maximum Value: ${validator.getUpperBound()}`); | ||
| constraints.push(`Maximum Value: ${validator.getUpperBound()}`); | ||
| } | ||
| } | ||
|
|
||
| const sizeValidator = field.getSizeValidator?.(); | ||
| if (sizeValidator) { | ||
| if (sizeValidator.getMinSize() !== null) { | ||
| contraints.push(`Minimum Size: ${sizeValidator.getMinSize()}`); | ||
| constraints.push(`Minimum Size: ${sizeValidator.getMinSize()}`); | ||
| } | ||
| if (sizeValidator.getMaxSize() !== null) { | ||
| contraints.push(`Maximum Size: ${sizeValidator.getMaxSize()}`); | ||
| constraints.push(`Maximum Size: ${sizeValidator.getMaxSize()}`); | ||
| } | ||
| } | ||
|
|
||
| const isInherited = field.getParent().getFullyQualifiedName() !== parameters.stack[parameters.stack.length-1]; | ||
|
|
||
| parameters.fileWriter.writeLine(0, `| ${field.getName()} | <code>${type}</code> | ${!field.isOptional() ? '✔️' : ''} | ${isIdentifier ? '✔️' : ''} | ${field.isRelationship?.() ? '✔️' : ''} | ${isInherited ? '✔️' : ''} | ${descriptionDecorator?.getArguments()[0] || ''} | ${contraints.join('<br>')} |`); | ||
| parameters.fileWriter.writeLine(0, `| ${field.getName()} | <code>${type}</code> | ${!field.isOptional() ? '✔️' : ''} | ${isIdentifier ? '✔️' : ''} | ${field.isRelationship?.() ? '✔️' : ''} | ${isInherited ? '✔️' : ''} | ${descriptionDecorator?.getArguments()[0] || ''} | ${constraints.join('<br>')} |`); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit · design
Map key and value types are rendered with
getType(), which gives the short name: the snapshot shows<code>Employee</code>and<code>SSN</code>. Field types in the same document are fully qualified (org.acme.hr@1.0.0.Employee). For a map whose key or value type is imported, readers can't tell which namespace it comes from. Consider resolving non-primitive names to their fully qualified form, for example through the model file'sgetFullyQualifiedTypeName, so maps match the class tables.