Skip to content

Commit 976cff1

Browse files
authored
Merge pull request #75 from cesarParra/2.14_rc
2.14 rc
2 parents c64e1b5 + 597f2c7 commit 976cff1

File tree

11 files changed

+73
-50
lines changed

11 files changed

+73
-50
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ The CLI supports the following parameters:
129129
| --defaultGroupName | N/A | Defines the `@group` name to be used when a file does not specify it. | `Miscellaneous` | No |
130130
| --sanitizeHtml | N/A | When on, any special character within your ApexDocs is converted into its HTML code representation. This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" because otherwise the content within < and > would be treated as HTML tags and not shown in the output. Content in @example blocks are never sanitized. | `Apex REST Api` | No |
131131
| --openApiTitle | N/A | If using "openapi" as the target generator, this allows you to specify the OpenApi title value. | true | No |
132+
| --title | N/A | Allows you to specify the home page main title. If using "openapi" this acts as an alias to the openApiTitle parameter | `Classes` | No |
132133
| --namespace | N/A | The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. If generating an OpenApi definition, it will be added to the file's Server Url. | N/A | No |
133134
| --openApiFileName | N/A | If using "openapi" as the target generator, this allows you to specify the name of the output file. | `openapi` | No |
135+
| --includeMetadata | N/A | Whether to include the file's meta.xml information: Whether it is active and and the API version | false | No |
134136

135137
### Importing to your project
136138

docs/Main/nspc.SampleClass.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
`NAMESPACEACCESSIBLE`
44

5-
`APIVERSION: 54`
6-
7-
`STATUS: ACTIVE`
8-
95
This is a class description. This class relates to [nspc.SampleInterface](/Sample-Interfaces/nspc.SampleInterface.md)
106
But this [ClassThatDoesNotExist](ClassThatDoesNotExist) does not exist.
117
You can also link using this syntax [nspc.SampleInterface](/Sample-Interfaces/nspc.SampleInterface.md)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"postversion": "git push && git push --tags",
2525
"docs:init": "docsify init docs",
2626
"docs:serve": "docsify serve docs",
27-
"execute:example": "node lib/cli/generate.js -s examples/force-app -t docs --scope global public private protected -g docsify --defaultGroupName \"Misc Group\" --namespace nspc",
27+
"execute:example": "node lib/cli/generate.js -s examples/force-app -t docs --scope global public private protected -g docsify --defaultGroupName \"Misc Group\" --namespace nspc --title \"Sample Documentation\"",
2828
"execute:example:index:only": "node lib/cli/generate.js -s examples/force-app -t docs --scope global public private -g docsify --indexOnly",
2929
"execute:example:openapi": "node lib/cli/generate.js -s examples/force-app -t docs -g openapi --openApiTitle \"Sample REST Api\" --namespace nspc --openApiFileName restapi"
3030
},

src/cli/generate.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const argv = yargs.options({
6666
default: 'Apex REST Api',
6767
describe: 'If using "openapi" as the target generator, this allows you to specify the OpenApi title value.',
6868
},
69+
title: {
70+
type: 'string',
71+
describe: "If this allows you to specify the title of the generated documentation's home file.",
72+
default: 'Classes',
73+
},
6974
namespace: {
7075
type: 'string',
7176
describe:
@@ -77,6 +82,11 @@ const argv = yargs.options({
7782
describe: 'If using "openapi" as the target generator, this allows you to specify the name of the output file.',
7883
default: 'openapi',
7984
},
85+
includeMetadata: {
86+
type: 'boolean',
87+
describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
88+
default: false,
89+
},
8090
}).argv;
8191

8292
Settings.build({
@@ -89,8 +99,10 @@ Settings.build({
8999
defaultGroupName: argv.defaultGroupName,
90100
sanitizeHtml: argv.sanitizeHtml,
91101
openApiTitle: argv.openApiTitle,
102+
title: argv.title,
92103
namespace: argv.namespace,
93104
openApiFileName: argv.openApiFileName,
105+
includeMetadata: argv.includeMetadata,
94106
});
95107

96108
try {

src/model/markdown-home-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class MarkdownHomeFile extends MarkdownFile {
1010
if (headerContent) {
1111
this.addText(headerContent);
1212
}
13-
this.addTitle('Classes');
13+
this.addTitle(Settings.getInstance().getTitle());
1414
this.addTypeEntries(types);
1515
}
1616

src/service/__tests__/apex-file-reader.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ describe('File Reader', () => {
1313
defaultGroupName: 'Misc',
1414
sanitizeHtml: true,
1515
openApiFileName: 'openapi',
16+
title: 'Classes',
17+
includeMetadata: false,
1618
} as SettingsConfig);
1719
});
1820

src/service/apex-file-reader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export class ApexFileReader {
2727

2828
const rawApexFile = fileSystem.readFile(currentPath);
2929
const metadataPath = fileSystem.joinPath(rootPath, `${currentFilePath}-meta.xml`);
30-
const rawMetadataFile = fileSystem.exists(metadataPath) ? fileSystem.readFile(metadataPath) : null;
30+
let rawMetadataFile = null;
31+
if (Settings.getInstance().includeMetadata()) {
32+
rawMetadataFile = fileSystem.exists(metadataPath) ? fileSystem.readFile(metadataPath) : null;
33+
}
34+
3135
bundles.push(new ApexBundle(currentFilePath, rawApexFile, rawMetadataFile));
3236
});
3337
return bundles;

src/service/parser.ts

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
Type,
3-
ReflectionResult,
4-
ClassMirror,
5-
FieldMirror,
6-
PropertyMirror,
7-
MethodMirror,
8-
InterfaceMirror,
9-
} from '@cparra/apex-reflection';
1+
import { ClassMirror, InterfaceMirror, ReflectionResult, Type } from '@cparra/apex-reflection';
102
import ApexBundle from '../model/apex-bundle';
113
import MetadataProcessor from './metadata-processor';
124
import { Logger } from '../util/logger';
@@ -30,7 +22,7 @@ export class RawBodyParser implements TypeParser {
3022
const metadataParams = MetadataProcessor.process(currentBundle.rawMetadataContent);
3123
metadataParams.forEach((value, key) => {
3224
const declaration = `${key}: ${value}`;
33-
result.typeMirror!.annotations.push({
25+
result.typeMirror?.annotations.push({
3426
rawDeclaration: declaration,
3527
name: declaration,
3628
type: declaration,
@@ -42,6 +34,7 @@ export class RawBodyParser implements TypeParser {
4234
.filter((reflectionResult) => {
4335
return reflectionResult.typeMirror;
4436
})
37+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4538
.map((reflectionResult) => reflectionResult.typeMirror!);
4639

4740
return this.addFieldsFromParent(types);
@@ -76,7 +69,6 @@ export class RawBodyParser implements TypeParser {
7669

7770
typeAsInterface = this.addMethodsFromParent(typeAsInterface, types);
7871
typesWithFields.push(typeAsInterface);
79-
continue;
8072
}
8173

8274
return typesWithFields;
@@ -131,45 +123,48 @@ export class RawBodyParser implements TypeParser {
131123
}
132124

133125
private getInheritedFields(parentAsClass: ClassMirror, currentClass: ClassMirror) {
134-
const parentFields = parentAsClass.fields
135-
// Filter out private fields
136-
.filter((currentField) => currentField.access_modifier.toLowerCase() !== 'private')
137-
// Filter out fields that also exist on the child
138-
.filter((currentField) => !this.memberExists(currentClass.fields, currentField.name))
139-
.map((currentField) => ({
140-
...currentField,
141-
inherited: true,
142-
}));
143-
return parentFields;
126+
return (
127+
parentAsClass.fields
128+
// Filter out private fields
129+
.filter((currentField) => currentField.access_modifier.toLowerCase() !== 'private')
130+
// Filter out fields that also exist on the child
131+
.filter((currentField) => !this.memberExists(currentClass.fields, currentField.name))
132+
.map((currentField) => ({
133+
...currentField,
134+
inherited: true,
135+
}))
136+
);
144137
}
145138

146139
private getInheritedProperties(parentAsClass: ClassMirror, currentClass: ClassMirror) {
147-
const parentProperties = parentAsClass.properties
148-
// Filter out private properties
149-
.filter((currentProperty) => currentProperty.access_modifier.toLowerCase() !== 'private')
150-
// Filter out properties that also exist on the child
151-
.filter((currentProperty) => !this.memberExists(currentClass.properties, currentProperty.name))
152-
.map((currentProperty) => ({
153-
...currentProperty,
154-
inherited: true,
155-
}));
156-
return parentProperties;
140+
return (
141+
parentAsClass.properties
142+
// Filter out private properties
143+
.filter((currentProperty) => currentProperty.access_modifier.toLowerCase() !== 'private')
144+
// Filter out properties that also exist on the child
145+
.filter((currentProperty) => !this.memberExists(currentClass.properties, currentProperty.name))
146+
.map((currentProperty) => ({
147+
...currentProperty,
148+
inherited: true,
149+
}))
150+
);
157151
}
158152

159153
private getInheritedMethods(
160154
parentAsClass: ClassMirror | InterfaceMirror,
161155
currentClass: ClassMirror | InterfaceMirror,
162156
) {
163-
const parentMethods = parentAsClass.methods
164-
// Filter out private methods
165-
.filter((currentMethod) => currentMethod.access_modifier.toLowerCase() !== 'private')
166-
// Filter out methods that also exist on the child
167-
.filter((currentMethod) => !this.memberExists(currentClass.methods, currentMethod.name))
168-
.map((currentMethod) => ({
169-
...currentMethod,
170-
inherited: true,
171-
}));
172-
return parentMethods;
157+
return (
158+
parentAsClass.methods
159+
// Filter out private methods
160+
.filter((currentMethod) => currentMethod.access_modifier.toLowerCase() !== 'private')
161+
// Filter out methods that also exist on the child
162+
.filter((currentMethod) => !this.memberExists(currentClass.methods, currentMethod.name))
163+
.map((currentMethod) => ({
164+
...currentMethod,
165+
inherited: true,
166+
}))
167+
);
173168
}
174169

175170
memberExists(members: NameAware[], fieldName: string): boolean {

src/settings.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ export interface SettingsConfig {
1010
defaultGroupName: string;
1111
sanitizeHtml: boolean;
1212
openApiTitle?: string;
13+
title: string;
1314
namespace?: string;
1415
openApiFileName: string;
16+
includeMetadata: boolean;
1517
}
1618

1719
export class Settings {
@@ -63,7 +65,11 @@ export class Settings {
6365
}
6466

6567
public getOpenApiTitle(): string | undefined {
66-
return this.config.openApiTitle;
68+
return this.config.openApiTitle ?? this.config.title;
69+
}
70+
71+
public getTitle(): string {
72+
return this.config.title;
6773
}
6874

6975
public getNamespace(): string | undefined {
@@ -80,4 +86,8 @@ export class Settings {
8086
public openApiFileName(): string {
8187
return this.config.openApiFileName;
8288
}
89+
90+
public includeMetadata(): boolean {
91+
return this.config.includeMetadata;
92+
}
8393
}

src/test-helpers/SettingsBuilder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class SettingsBuilder {
1717
sanitizeHtml: true,
1818
openApiTitle: 'Apex API',
1919
openApiFileName: 'openapi',
20+
title: 'Classes',
21+
includeMetadata: false,
2022
};
2123
}
2224
}

0 commit comments

Comments
 (0)