Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ const cli = configureProject(
'wrap-ansi@^7', // Last non-ESM version
'yaml@^1',
'yargs@^15',
'jsonschema',
],
tsconfig: {
compilerOptions: {
Expand Down
26 changes: 26 additions & 0 deletions packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -22580,6 +22580,32 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


----------------

** [email protected] - https://www.npmjs.com/package/jsonschema/v/1.5.0 | MIT
jsonschema is licensed under MIT license.

Copyright (C) 2012-2015 Tom de Grunt <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


----------------

** [email protected] - https://www.npmjs.com/package/lazystream/v/1.0.1 | MIT
Expand Down
4 changes: 4 additions & 0 deletions packages/aws-cdk/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/aws-cdk/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions packages/aws-cdk/THIRD_PARTY_LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -22373,6 +22373,32 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


----------------

** [email protected] - https://www.npmjs.com/package/jsonschema/v/1.5.0 | MIT
jsonschema is licensed under MIT license.

Copyright (C) 2012-2015 Tom de Grunt <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


----------------

** [email protected] - https://www.npmjs.com/package/lazystream/v/1.0.1 | MIT
Expand Down
98 changes: 98 additions & 0 deletions packages/aws-cdk/lib/cli/user-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import * as os from 'os';
import * as fs_path from 'path';
import { ToolkitError } from '@aws-cdk/toolkit-lib';
import * as fs from 'fs-extra';
import { validate } from 'jsonschema';
import { Context, PROJECT_CONTEXT } from '../api/context';
import { Settings } from '../api/settings';
import type { Tag } from '../api/tags';
import type { IoHelper } from '../api-private';
import { cdkConfigSchema } from '../schema';

export const PROJECT_CONFIG = 'cdk.json';
export { PROJECT_CONTEXT } from '../api/context';
Expand Down Expand Up @@ -210,6 +212,9 @@ async function settingsFromFile(ioHelper: IoHelper, fileName: string): Promise<S
const expanded = expandHomeDir(fileName);
if (await fs.pathExists(expanded)) {
const data = await fs.readJson(expanded);

await validateConfigurationFile(data, fileName, ioHelper);

settings = new Settings(data);
} else {
settings = new Settings();
Expand Down Expand Up @@ -408,3 +413,96 @@ async function parseStringTagsListToObject(
}
return tags.length > 0 ? tags : undefined;
}

/**
* Find similar property names to suggest corrections for typos
*/
function getTypeCorrectionHint(expectedType: string, actualValue: any): string {
if (expectedType === 'boolean' && (actualValue === 'true' || actualValue === 'false')) {
return ` (use ${actualValue} without quotes)`;
}
if (expectedType === 'string' && typeof actualValue === 'number') {
return ` (use "${actualValue}" with quotes)`;
}
return '';
}

/**
* Validates configuration data against the CDK JSON Schema and emits warnings for issues
*
* @param data - The configuration object to validate
* @param fileName - The file name for error reporting
* @param ioHelper - IoHelper for logging warnings
*/
async function validateConfigurationFile(data: any, fileName: string, ioHelper: IoHelper): Promise<void> {
try {
const schema = cdkConfigSchema;
const result = validate(data, schema);

await handleSchemaErrors(result.errors, fileName, ioHelper);

await handleUnknownProperties(data, schema, fileName, ioHelper);
} catch (error) {
await ioHelper.defaults.debug(`Schema validation failed for ${fileName}: ${error}`);
}
}

/**
* Handles schema validation errors and emits appropriate warnings
*/
async function handleSchemaErrors(errors: any[], fileName: string, ioHelper: IoHelper): Promise<void> {
if (!errors || errors.length === 0) {
return;
}

for (const error of errors) {
const propertyPath = error.property?.replace('instance.', '') || 'root';
const propertyName = propertyPath || 'property';

if (error.name === 'type') {
const errorSchema = error.schema as any;
const expectedType = Array.isArray(errorSchema.type)
? errorSchema.type.join(' or ')
: errorSchema.type || 'unknown';
const actualType = typeof error.instance;
const hint = getTypeCorrectionHint(expectedType, error.instance);

await ioHelper.defaults.warn(
`${fileName}: '${propertyName}' should be ${expectedType}, got ${actualType}${hint}`,
);
} else if (error.name === 'enum') {
const allowedValues = (error.schema as any).enum?.join(', ') || 'unknown';
await ioHelper.defaults.warn(
`${fileName}: '${propertyName}' must be one of: ${allowedValues}`,
);
} else if (error.name !== 'additionalProperties') {
// Generic fallback for other validation errors (skip additionalProperties as we handle those separately)
await ioHelper.defaults.warn(
`${fileName}: ${error.message}`,
);
}
}
}

/**
* Handles unknown properties
*/
async function handleUnknownProperties(
data: any,
schema: any,
fileName: string,
ioHelper: IoHelper,
): Promise<void> {
if (!data || typeof data !== 'object' || Array.isArray(data)) {
return;
}

const knownProperties = Object.keys(schema.properties || {});
const unknownProperties = Object.keys(data).filter(prop => !knownProperties.includes(prop));

for (const prop of unknownProperties) {
await ioHelper.defaults.warn(
`${fileName}: Unknown property '${prop}' (not a standard CDK property)`,
);
}
}
Loading