提交 0c2c8dd8 编写于 作者: C Christof Marti

Inline allOf clauses for additionalProperties: false (fixes microsoft/vscode-remote-release#2967)

上级 60c625e9
......@@ -119,6 +119,7 @@ const copyrightFilter = [
'!resources/win32/bin/code.js',
'!resources/web/code-web.js',
'!resources/completions/**',
'!extensions/configuration-editing/build/inline-allOf.ts',
'!extensions/markdown-language-features/media/highlight.css',
'!extensions/html-language-features/server/src/modes/typescript/*',
'!extensions/*/server/bin/*',
......
......@@ -5,3 +5,5 @@ out/**
extension.webpack.config.js
extension-browser.webpack.config.js
yarn.lock
build/**
schemas/*.schema.src.json
#!/usr/bin/env ts-node
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// Inlines "allOf"s to allow for "additionalProperties": false. (https://github.com/microsoft/vscode-remote-release/issues/2967)
// Run this manually after updating devContainer.schema.src.json.
import * as fs from 'fs';
function transform(schema: any) {
const definitions = Object.keys(schema.definitions)
.reduce((d, k) => {
d[`#/definitions/${k}`] = (schema.definitions as any)[k];
return d;
}, {} as any);
function copy(from: any) {
const type = Array.isArray(from) ? 'array' : typeof from;
switch (type) {
case 'object': {
const to: any = {};
for (const key in from) {
switch (key) {
case 'definitions':
break;
case 'oneOf':
const list = copy(from[key])
.reduce((a: any[], o: any) => {
if (o.oneOf) {
a.push(...o.oneOf);
} else {
a.push(o);
}
return a;
}, [] as any[]);
if (list.length === 1) {
Object.assign(to, list[0]);
} else {
to.oneOf = list;
}
break;
case 'allOf':
const all = copy(from[key]);
const leaves = all.map((one: any) => (one.oneOf ? one.oneOf : [one]));
function cross(res: any, leaves: any[][]): any[] {
if (leaves.length) {
const rest = leaves.slice(1);
return ([] as any[]).concat(...leaves[0].map(leaf => {
const intermediate = { ...res, ...leaf };
if ('properties' in res && 'properties' in leaf) {
intermediate.properties = {
...res.properties,
...leaf.properties,
};
}
return cross(intermediate, rest);
}));
}
return [res];
}
const list2 = cross({}, leaves);
if (list2.length === 1) {
Object.assign(to, list2[0]);
} else {
to.oneOf = list2;
}
break;
case '$ref':
const ref = from[key];
const definition = definitions[ref];
if (definition) {
Object.assign(to, copy(definition));
} else {
to[key] = ref;
}
break;
default:
to[key] = copy(from[key]);
break;
}
}
if (to.type === 'object' && !('additionalProperties' in to)) {
to.additionalProperties = false;
}
return to;
}
case 'array': {
return from.map(copy);
}
default:
return from;
}
}
return copy(schema);
}
const devContainer = JSON.parse(fs.readFileSync('../schemas/devContainer.schema.src.json', 'utf8'));
fs.writeFileSync('../schemas/devContainer.schema.generated.json', JSON.stringify(transform(devContainer), undefined, ' '));
{
"extends": "../../shared.tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"outDir": "./out"
}
}
......@@ -111,11 +111,11 @@
},
{
"fileMatch": "/.devcontainer/devcontainer.json",
"url": "./schemas/devContainer.schema.json"
"url": "./schemas/devContainer.schema.generated.json"
},
{
"fileMatch": "/.devcontainer.json",
"url": "./schemas/devContainer.schema.json"
"url": "./schemas/devContainer.schema.generated.json"
},
{
"fileMatch": "%APP_SETTINGS_HOME%/globalStorage/ms-vscode-remote.remote-containers/nameConfigs/*.json",
......
......@@ -3,7 +3,6 @@
"description": "Defines a dev container",
"allowComments": true,
"allowTrailingCommas": true,
"type": "object",
"definitions": {
"devContainerCommon": {
"type": "object",
......@@ -104,6 +103,7 @@
},
"codespaces": {
"type": "object",
"additionalProperties": true,
"description": "Codespaces-specific configuration."
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册