Skip to content

Commit

Permalink
feat(sdk): rename swagger-spec.yaml to open-api.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot committed Jul 2, 2024
1 parent 1c1a104 commit f33cdc2
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 11 deletions.
1 change: 1 addition & 0 deletions migration-guides/11.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions packages/@ama-sdk/schematics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions packages/@ama-sdk/schematics/migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
2 changes: 1 addition & 1 deletion packages/@ama-sdk/schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 2 additions & 4 deletions packages/@ama-sdk/schematics/schematics/helpers/generators.ts
Original file line number Diff line number Diff line change
@@ -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';
7 changes: 5 additions & 2 deletions packages/@ama-sdk/schematics/schematics/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/@ama-sdk/schematics/schematics/migrate/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Schematic Option */
/** Migrate Schematics Options */
export interface MigrateSchematicsSchemaOptions {
/** Starting version from which the migration scripts are executed */
from: string;
Expand Down
46 changes: 45 additions & 1 deletion packages/@ama-sdk/schematics/schematics/ng-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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`));
}
});
};
Original file line number Diff line number Diff line change
@@ -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);
});
};
2 changes: 1 addition & 1 deletion packages/@o3r/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f33cdc2

Please sign in to comment.