mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 11:03:53 +08:00
build: add support for x-deprecated
when generating schema
When using the CLI and a property is deprecated we emit a warning by using the `x-deprecated` field. However API consumers have no way to know that a property is deprecated at the moment. This converts `x-deprecated` to `@deprecated` comments
This commit is contained in:
parent
45b6df511f
commit
aae1afd114
@ -9,7 +9,6 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {
|
const {
|
||||||
InputData,
|
InputData,
|
||||||
JSONSchema,
|
|
||||||
JSONSchemaInput,
|
JSONSchemaInput,
|
||||||
JSONSchemaStore,
|
JSONSchemaStore,
|
||||||
TypeScriptTargetLanguage,
|
TypeScriptTargetLanguage,
|
||||||
@ -88,6 +87,8 @@ class FetchingJSONSchemaStore extends JSONSchemaStore {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content = appendDeprecatedDescription(content);
|
||||||
|
|
||||||
return parseJSON(content, "JSON Schema", address);
|
return parseJSON(content, "JSON Schema", address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,7 +117,8 @@ async function generate(inPath) {
|
|||||||
// Best description of how to use the API was found at
|
// Best description of how to use the API was found at
|
||||||
// https://blog.quicktype.io/customizing-quicktype/
|
// https://blog.quicktype.io/customizing-quicktype/
|
||||||
const inputData = new InputData();
|
const inputData = new InputData();
|
||||||
const source = { name: 'Schema', schema: fs.readFileSync(inPath, 'utf-8') };
|
const content = fs.readFileSync(inPath, 'utf-8');
|
||||||
|
const source = { name: 'Schema', schema: appendDeprecatedDescription(content) };
|
||||||
|
|
||||||
await inputData.addSource('schema', source, () => {
|
await inputData.addSource('schema', source, () => {
|
||||||
return new JSONSchemaInput(new FetchingJSONSchemaStore(inPath));
|
return new JSONSchemaInput(new FetchingJSONSchemaStore(inPath));
|
||||||
@ -137,6 +139,27 @@ async function generate(inPath) {
|
|||||||
return header + lines.join('\n') + footer;
|
return header + lines.join('\n') + footer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts `x-deprecated` to `@deprecated` comments.
|
||||||
|
* @param {string} schema
|
||||||
|
*/
|
||||||
|
function appendDeprecatedDescription(schema) {
|
||||||
|
const content = JSON.parse(schema);
|
||||||
|
const props = content.properties;
|
||||||
|
|
||||||
|
for (const key in props) {
|
||||||
|
let { description = '', 'x-deprecated': deprecated } = props[key];
|
||||||
|
if (!deprecated) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
description += '\n@deprecated' + (typeof deprecated === 'string' ? ` ${deprecated}` : '');
|
||||||
|
props[key].description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.stringify(content);
|
||||||
|
}
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
// Parse arguments and run main().
|
// Parse arguments and run main().
|
||||||
const argv = process.argv.slice(2);
|
const argv = process.argv.slice(2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user