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 May 2, 2024
1 parent 6a9b544 commit f3f6112
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 6 deletions.
10 changes: 10 additions & 0 deletions packages/@ama-sdk/schematics/migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"version": "10.0.0-alpha.0",
"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-v11_1": {
"version": "11.0.0-alpha.0",
"description": "Updates of @ama-sdk/schematics to v11.0.*",
"factory": "./schematics/ng-update/index#updateV11_0"
}
}
}
6 changes: 5 additions & 1 deletion packages/@ama-sdk/schematics/schematics/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { Rule, type Tree } from '@angular-devkit/schematics';
import { MigrateSchematicsSchemaOptions } from './schema';
import { getMigrationRuleRunner, type MigrationRulesMap } from '@o3r/schematics';
import { resolve } from 'node:path';
import { updateRegenScript } from '../ng-update/typescript/v11.0/update-regen-script';

const tsMigrationMap: MigrationRulesMap = {

// eslint-disable-next-line @typescript-eslint/naming-convention
'11.0.*': [
updateRegenScript
]
};

const isTypescriptSdk = (tree: Tree) => {
Expand Down
32 changes: 31 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,11 @@
/* eslint-disable camelcase */

import { Rule, Tree } from '@angular-devkit/schematics';
import { updateV10_0 as tsUpdateV10_0 } from './typescript';
import {
updateV10_0 as tsUpdateV10_0,
updateV10_1 as tsUpdateV10_1,
updateV11_0 as tsUpdateV11_0
} from './typescript';

/**
* Determine if the script is run in a Typescript SDK
Expand All @@ -24,3 +28,29 @@ 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 V11.0
*/
export function updateV11_1(): 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,6 +4,7 @@
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 { updateRegenScript } from './v11.0/update-regen-script';

/**
* update of Otter library V10.0
Expand All @@ -28,3 +29,14 @@ export function updateV10_1(): Rule {

return chain(updateRules);
}

/**
* Update of Ama-sdk library V11
*/
export function updateV11_0(): Rule {
const updateRules: Rule[] = [
updateRegenScript
];

return chain(updateRules);
}
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 '../../../typescript/core';

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);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ import { generateOperationFinderFromSingleFile } from './helpers/path-extractor'
const JAVA_OPTIONS = ['specPath', 'specConfigPath', 'globalProperty', 'outputPath'];
const OPEN_API_TOOLS_OPTIONS = ['generatorName', 'output', 'inputSpec', 'config', 'globalProperty'];

// TODO: Change to `open-api` when #1735 is done
/** 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` when #1735 is done
/** Extension of the Specification file in JSON format */
export const SPEC_JSON_EXTENSION = 'yaml';
export const SPEC_JSON_EXTENSION = 'json';

interface OpenApiToolsGenerator {
/** Location of the OpenAPI spec, as URL or file */
Expand Down

0 comments on commit f3f6112

Please sign in to comment.