diff --git a/migration-guides/11.0.md b/migration-guides/11.0.md index f7f5827817..1c876b08a8 100644 --- a/migration-guides/11.0.md +++ b/migration-guides/11.0.md @@ -6,6 +6,7 @@ ## @ama-sdk/core - `prepareOptions` method has been removed from `ApiClient`. `getRequestOptions` should be used instead. +- To support `JSON` specification format and to remove the reference to the outdated `Swagger` format name, the file containing the current specification used to generate the SDK will be stored in a file `open-api.yaml` or `open-api.json` instead of `swagger-api.yaml`. ## @o3r/schematics diff --git a/packages/@ama-sdk/schematics/README.md b/packages/@ama-sdk/schematics/README.md index 10f828a340..4e3e5985e2 100644 --- a/packages/@ama-sdk/schematics/README.md +++ b/packages/@ama-sdk/schematics/README.md @@ -252,6 +252,7 @@ yarn schematics @ama-sdk/schematics:migrate --from 10.0.0 [--to 11.0.0] ``` > [!NOTE] +> > - The `--from` parameter is mandatory to provide the version of the original `@ama-sdk/schematics` package from which the rules should be run. > - The *optional* `--to` parameter allows to indicate a version until which the rules should be run. The current installed version will be used if not provided. diff --git a/packages/@ama-sdk/schematics/migration.json b/packages/@ama-sdk/schematics/migration.json index 5634a64a2e..77dcb97c6b 100644 --- a/packages/@ama-sdk/schematics/migration.json +++ b/packages/@ama-sdk/schematics/migration.json @@ -6,10 +6,20 @@ "description": "Updates of @ama-sdk/schematics to v10.0.*", "factory": "./schematics/ng-update/index#updateV10_0" }, + "migration-v10_1": { + "version": "10.1.0-alpha.0", + "description": "Updates of @ama-sdk/schematics to v10.1.*", + "factory": "./schematics/ng-update/index#updateV10_1" + }, "migration-v10_3": { "version": "10.3.0-alpha.0", "description": "Updates of @ama-sdk/schematics to v10.3.*", "factory": "./schematics/ng-update/index#updateV10_3" + }, + "migration-v11_0": { + "version": "11.0.0-alpha.0", + "description": "Updates of @ama-sdk/schematics to v11.0.*", + "factory": "./schematics/ng-update/index#updateV11_0" } } } diff --git a/packages/@ama-sdk/schematics/package.json b/packages/@ama-sdk/schematics/package.json index 2beb532000..83c7679d0a 100644 --- a/packages/@ama-sdk/schematics/package.json +++ b/packages/@ama-sdk/schematics/package.json @@ -136,7 +136,7 @@ "lint-staged": "^15.0.0", "minimist": "^1.2.6", "rimraf": "^5.0.1", - "typedoc": "~0.25.0", + "typedoc": "~0.26.0", "tsc-watch": "^6.0.4", "yaml-eslint-parser": "^1.2.2" }, diff --git a/packages/@ama-sdk/schematics/schematics/helpers/generators.ts b/packages/@ama-sdk/schematics/schematics/helpers/generators.ts index 5eaa3fe110..4ed08d0c67 100644 --- a/packages/@ama-sdk/schematics/schematics/helpers/generators.ts +++ b/packages/@ama-sdk/schematics/schematics/helpers/generators.ts @@ -1,10 +1,8 @@ -// TODO: Change to `openapi` in v11 (ref: #1745) /** Name of the specification file copied locally (without extension) */ -export const LOCAL_SPEC_FILENAME = 'swagger-spec'; +export const LOCAL_SPEC_FILENAME = 'open-api'; /** Extension of the Specification file in YAML format */ export const SPEC_YAML_EXTENSION = 'yaml'; -// TODO: Change to `json` in v11 (ref: #1745) /** Extension of the Specification file in JSON format */ -export const SPEC_JSON_EXTENSION = 'yaml'; +export const SPEC_JSON_EXTENSION = 'json'; diff --git a/packages/@ama-sdk/schematics/schematics/migrate/index.ts b/packages/@ama-sdk/schematics/schematics/migrate/index.ts index 8c5fb8c5b5..5bfb3331f2 100644 --- a/packages/@ama-sdk/schematics/schematics/migrate/index.ts +++ b/packages/@ama-sdk/schematics/schematics/migrate/index.ts @@ -2,16 +2,19 @@ import type { Rule } from '@angular-devkit/schematics'; import { MigrateSchematicsSchemaOptions } from './schema'; import { getMigrationRuleRunner, getWorkspaceConfig, type MigrationRulesMap } from '@o3r/schematics'; import { resolve } from 'node:path'; +import { updateRegenScript } from '../ng-update/typescript/v11.0/update-regen-script'; import { gt, minVersion } from 'semver'; import { isTypescriptSdk } from '../helpers/is-typescript-project'; import {updateOpenApiVersionInProject} from '../ng-update/typescript/v10.3/update-openapiversion'; /* eslint-disable @typescript-eslint/naming-convention */ const tsMigrationMap: MigrationRulesMap = { - '~10.3.2': updateOpenApiVersionInProject() + '~10.3.2': updateOpenApiVersionInProject(), + '11.0.*': [ + updateRegenScript + ] }; /* eslint-enable @typescript-eslint/naming-convention */ - /** * Facilitate the migration of a version to another by the run of migration rules * @param options diff --git a/packages/@ama-sdk/schematics/schematics/migrate/schema.ts b/packages/@ama-sdk/schematics/schematics/migrate/schema.ts index a2ca0c5a64..ead4827383 100644 --- a/packages/@ama-sdk/schematics/schematics/migrate/schema.ts +++ b/packages/@ama-sdk/schematics/schematics/migrate/schema.ts @@ -1,4 +1,4 @@ -/** Schematic Option */ +/** Migrate Schematics Options */ export interface MigrateSchematicsSchemaOptions { /** Starting version from which the migration scripts are executed */ from: string; diff --git a/packages/@ama-sdk/schematics/schematics/ng-update/index.ts b/packages/@ama-sdk/schematics/schematics/ng-update/index.ts index 634db42e0a..345a70c20d 100644 --- a/packages/@ama-sdk/schematics/schematics/ng-update/index.ts +++ b/packages/@ama-sdk/schematics/schematics/ng-update/index.ts @@ -2,7 +2,12 @@ /* eslint-disable camelcase */ import type { Rule } from '@angular-devkit/schematics'; -import { updateV10_0 as tsUpdateV10_0 } from './typescript'; +import { + updateV10_0 as tsUpdateV10_0, + updateV10_1 as tsUpdateV10_1, + updateV10_3 as tsUpdateV10_3, + updateV11_0 as tsUpdateV11_0 +} from './typescript'; import { isTypescriptSdk } from '../helpers/is-typescript-project'; /** @@ -17,3 +22,42 @@ export function updateV10_0(): Rule { return tree; }; } + +/** + * update of Otter library V10.1 + */ +export function updateV10_1(): Rule { + return (tree, context) => { + if (isTypescriptSdk(tree)) { + return tsUpdateV10_1()(tree, context); + } + + return tree; + }; +} + +/** + * update of Otter library V10.3 + */ +export function updateV10_3(): Rule { + return (tree, context) => { + if (isTypescriptSdk(tree)) { + return tsUpdateV10_3()(tree, context); + } + + return tree; + }; +} + +/** + * update of Otter library V11.0 + */ +export function updateV11_0(): Rule { + return (tree, context) => { + if (isTypescriptSdk(tree)) { + return tsUpdateV11_0()(tree, context); + } + + return tree; + }; +} diff --git a/packages/@ama-sdk/schematics/schematics/ng-update/typescript/index.ts b/packages/@ama-sdk/schematics/schematics/ng-update/typescript/index.ts index 1e92a8b74b..f6dd1a7d30 100644 --- a/packages/@ama-sdk/schematics/schematics/ng-update/typescript/index.ts +++ b/packages/@ama-sdk/schematics/schematics/ng-update/typescript/index.ts @@ -4,7 +4,9 @@ import { chain, Rule } from '@angular-devkit/schematics'; import { addCpyDependencies, deprecateScriptsFolder, updateScriptPackageJson } from './v10.0/script-removal'; import { addPresetsRenovate } from './v10.1/add-presets-renovate'; -import {updateOpenApiVersionInProject} from './v10.3/update-openapiversion'; +import { updateOpenApiVersionInProject } from './v10.3/update-openapiversion'; +import { updateRegenScript } from './v11.0/update-regen-script'; +import { updateOpenapitoolsFile } from './v11.0/update-openapitools'; /** * update of Otter library V10.0 @@ -40,3 +42,15 @@ export function updateV10_3(): Rule { return chain(updateRules); } + +/** + * Update of Ama-sdk library V11 + */ +export function updateV11_0(): Rule { + const updateRules: Rule[] = [ + updateRegenScript, + updateOpenapitoolsFile + ]; + + return chain(updateRules); +} diff --git a/packages/@ama-sdk/schematics/schematics/ng-update/typescript/v11.0/update-openapitools.ts b/packages/@ama-sdk/schematics/schematics/ng-update/typescript/v11.0/update-openapitools.ts new file mode 100644 index 0000000000..86ed8dd96b --- /dev/null +++ b/packages/@ama-sdk/schematics/schematics/ng-update/typescript/v11.0/update-openapitools.ts @@ -0,0 +1,19 @@ +import type { Rule } from '@angular-devkit/schematics'; +import { findFilesInTree } from '@o3r/schematics'; +import { LOCAL_SPEC_FILENAME } from '../../../helpers/generators'; + +/** + * Update Regen Script to base remove 'swagger' keyword + * @param tree + */ +export const updateOpenapitoolsFile: Rule = (tree) => { + const files = findFilesInTree(tree.root, (p) => p.endsWith('openapitools.json')); + + files.forEach((file) => { + const configFileContent = tree.readText(file.path); + + if (configFileContent.includes('swagger-spec.yaml')) { + tree.overwrite(file.path, configFileContent.replace(/swagger-spec\.yaml/g, `${LOCAL_SPEC_FILENAME}.yaml`)); + } + }); +}; diff --git a/packages/@ama-sdk/schematics/schematics/ng-update/typescript/v11.0/update-regen-script.ts b/packages/@ama-sdk/schematics/schematics/ng-update/typescript/v11.0/update-regen-script.ts new file mode 100644 index 0000000000..af2fa86def --- /dev/null +++ b/packages/@ama-sdk/schematics/schematics/ng-update/typescript/v11.0/update-regen-script.ts @@ -0,0 +1,32 @@ +import type { Rule } from '@angular-devkit/schematics'; +import { findFilesInTree } from '@o3r/schematics'; +import type { PackageJson } from 'type-fest'; +import { LOCAL_SPEC_FILENAME } from '../../../helpers/generators'; + +const SCRIPT_REGEN_LABEL = 'spec:regen'; + +/** + * Update Regen Script to base remove 'swagger' keyword + * @param tree + */ +export const updateRegenScript: Rule = (tree) => { + const files = findFilesInTree(tree.root, (p) => p.endsWith('package.json')); + + files.forEach((file) => { + const packageJson = tree.readJson(file.path) as PackageJson; + if (!packageJson.scripts || !Object.keys(packageJson.scripts).includes(SCRIPT_REGEN_LABEL)) { + return; + } + + const swaggerFilePath = file.path.replace(/package\.json$/, 'swagger-spec.yaml'); + if (!tree.exists(swaggerFilePath)) { + return; + } + + packageJson.scripts[SCRIPT_REGEN_LABEL] = packageJson.scripts[SCRIPT_REGEN_LABEL]!.replace(/swagger-spec\.yaml/g, `${LOCAL_SPEC_FILENAME}.yaml`); + tree.overwrite(file.path, JSON.stringify(packageJson, null, 2)); + + const openApiFilePath = file.path.replace(/package\.json$/, `${LOCAL_SPEC_FILENAME}.yaml`); + tree.rename(swaggerFilePath, openApiFilePath); + }); +}; diff --git a/packages/@o3r/core/package.json b/packages/@o3r/core/package.json index 21098a6355..838bccd506 100644 --- a/packages/@o3r/core/package.json +++ b/packages/@o3r/core/package.json @@ -155,7 +155,7 @@ "jsonc-eslint-parser": "~2.4.0", "eslint-import-resolver-node": "^0.3.9", "eslint-plugin-jest": "~28.6.0", - "eslint-plugin-jsdoc": "~48.2.1", + "eslint-plugin-jsdoc": "~48.4.0", "eslint-plugin-prefer-arrow": "~1.2.3", "eslint-plugin-unicorn": "^54.0.0", "jest": "~29.7.0",