Skip to content

Commit

Permalink
feat(extractor): support o3rRequired tag on config property for the r…
Browse files Browse the repository at this point in the history
…equired field in metadata
  • Loading branch information
matthieu-crouzet committed Oct 31, 2023
1 parent 9ea8257 commit 7a7de40
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {Configuration, NestedConfiguration} from '@o3r/core';
export interface DestinationConfiguration extends NestedConfiguration {
/**
* Name of the destination's city
* @o3rRequired
*/
cityName: string;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {Configuration, NestedConfiguration} from '@o3r/core';
export interface RulesEngineDestinationConfiguration extends NestedConfiguration {
/**
* IATA code of the destination's city
* @o3rRequired
*/
cityCode: string;
/**
Expand Down
9 changes: 6 additions & 3 deletions apps/vscode-extension/src/intellisense/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ interface ConfigurationTags {
/** @see CompletionItem.documentation */
description: string;
/** @see CompletionItem.detail */
detail: string;
detail?: string;
/** @see CompletionItem.insertText */
snippet: string;
snippet?: string;
}

export const configurationCompletionTriggerChar = '@';
Expand All @@ -16,7 +16,7 @@ const getCompletionsItemsFromConfigurationTags = (configurationTags: Record<stri
return Object.entries(configurationTags).map(([label, { detail, description, snippet }]) => {
const completion = new CompletionItem({ label: `${label} `, detail }, CompletionItemKind.Keyword);
completion.documentation = description;
completion.insertText = new SnippetString(`${label} ${snippet}`);
completion.insertText = typeof snippet !== 'undefined' ? new SnippetString(`${label} ${snippet}`) : undefined;

return completion;
});
Expand Down Expand Up @@ -58,6 +58,9 @@ const getConfigurationTagsFromEslintConfig = (eslintConfig: any, comment: string
detail: 'Readable configuration name',
snippet: '${1:Name}'
},
o3rRequired: {
description: 'Tag to use to define if a value must be specify in the CMS'
},
o3rCategory: {
description: 'Tag to use CMS category for configuration property',
detail: 'categoryName',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ export class ComponentConfigExtractor {
label: configDocInfo?.label ? configDocInfo.label : name.replace(/([A-Z])/g, ' $1'),
name,
type: 'unknown',
widget: configDocInfo?.widget
widget: configDocInfo?.widget,
// Check to not add `"required": false` on all properties by default
required: configDocInfo?.required ? true : undefined
};

if (propertyNode.questionToken) {
Expand Down
2 changes: 2 additions & 0 deletions packages/@o3r/components/src/core/component.output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export interface ConfigProperty {
category?: string;
/** The CMS widget information */
widget?: ConfigPropertyWidget;
/** If true, the CMS user must specify a value for the property */
required?: boolean;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/@o3r/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@
"cpy-cli": "^4.2.0",
"eslint": "^8.42.0",
"@nx/eslint-plugin": "~16.10.0",
"jsonc-eslint-parser": "~2.3.0",
"jsonc-eslint-parser": "~2.4.0",
"eslint-import-resolver-node": "^0.3.4",
"eslint-plugin-jest": "~27.4.0",
"eslint-plugin-jest": "~27.6.0",
"eslint-plugin-jsdoc": "~46.8.0",
"eslint-plugin-prefer-arrow": "~1.2.3",
"eslint-plugin-unicorn": "^47.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/eslint-config-otter/typescript.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ module.exports = {
'jsdoc/check-tag-names': [
'warn',
{
'definedTags': ['note', 'title', 'o3rCategory', 'o3rWidget', 'o3rWidgetParam']
'definedTags': ['note', 'title', 'o3rCategory', 'o3rWidget', 'o3rWidgetParam', 'o3rRequired']
}
],
'jsdoc/check-types': 'warn',
Expand Down
24 changes: 18 additions & 6 deletions packages/@o3r/extractors/src/utils/config-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ export interface ConfigDocInformation {
/** Description */
description: string;

/** Title (taken from @title tag) */
/** Title (taken from `@title` tag) */
title?: string;

/** label (taken from @label tag) */
/** label (taken from `@label` tag) */
label?: string;

/** Tags (taken from @tags tag) */
/** Tags (taken from `@tags` tag) */
tags?: string[];

/** Category (taken from @o3rCategory tag) */
/** Category (taken from `@o3rCategory` tag) */
category?: string;

/** Category (taken from <o3rCategories> tag) */
categories?: CategoryDescription[];

/** Widget information (taken from @o3rWidget and @o3rWidgetParam tag) */
/** Widget information (taken from `@o3rWidget` and `@o3rWidgetParam` tag) */
widget?: ConfigPropertyWidget;

/** `@o3rRequired` tag presence */
required?: boolean;
}

/**
Expand Down Expand Up @@ -119,6 +122,14 @@ export function getTagsFromDocComment(docComment: DocComment): string[] | undefi
return (tags && tags.indexOf(']') > 0) && tags.split(']')[0].match(/\w+/g) || undefined;
}

/**
* Is the tag `@o3rRequired` present in `docText`
* @param docText
*/
export function isO3rRequiredTagPresent(docText: string): boolean {
return /@o3rRequired/.test(docText);
}

/**
* Get category from a given DocComment.
*
Expand Down Expand Up @@ -206,7 +217,8 @@ export class ConfigDocParser {
tags: getTagsFromDocComment(docComment),
category: getCategoryFromDocText(docText),
categories: getCategoriesFromDocText(docText),
widget: getWidgetInformationFromDocComment(docText)
widget: getWidgetInformationFromDocComment(docText),
required: isO3rRequiredTagPresent(docText)
};
}
}
Expand Down

0 comments on commit 7a7de40

Please sign in to comment.