Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service-spec-importers): registry schema importers accept patches #640

Merged
merged 5 commits into from
Oct 25, 2023
Merged
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
6 changes: 3 additions & 3 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,20 @@ const awsServiceSpec = new TypeScriptWorkspace({
releasableCommits: pj.ReleasableCommits.featuresAndFixes('. ../service-spec-types ../../../sources'),
});

awsServiceSpec.tsconfigDev.addInclude('scripts');
awsServiceSpec.tsconfigDev.addInclude('build');

// Needs to be added to 'compile' task, because the integ tests will 'compile' everything (but not run the tests and linter).
awsServiceSpec.compileTask.prependSpawn(
awsServiceSpec.tasks.addTask('build:db', {
exec: `ts-node scripts/build-db.ts`,
exec: `ts-node build/build-db.ts`,
}),
);

awsServiceSpec.gitignore.addPatterns('db.json');
awsServiceSpec.gitignore.addPatterns('db.json.gz');
awsServiceSpec.gitignore.addPatterns('build-report');
awsServiceSpec.npmignore?.addPatterns('build-report');
awsServiceSpec.npmignore?.addPatterns('/scripts/');
awsServiceSpec.npmignore?.addPatterns('/build/');

// Add integration test with aws-cdk
new AwsCdkIntegrationTest(repo, {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-service-spec/.npmignore

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/aws-service-spec/.projen/tasks.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { SpecDatabase } from '@aws-cdk/service-spec-types';
import { DatabaseBuilder, DatabaseBuilderOptions, ReportAudience } from '@aws-cdk/service-spec-importers';
import { Augmentations } from './augmentations';
import { Scrutinies } from './scrutinies';
import { patchSamTemplateSpec } from './patches/sam-patches';
import { patchCloudFormationRegistry } from './patches/registry-patches';

const SOURCES = path.join(__dirname, '../../../../sources');

Expand All @@ -14,8 +16,8 @@ export class FullDatabase extends DatabaseBuilder {

this.importCloudFormationResourceSpec(path.join(SOURCES, 'CloudFormationResourceSpecification'))
.importSamResourceSpec(path.join(SOURCES, 'CloudFormationResourceSpecification/us-east-1/100_sam'))
.importCloudFormationRegistryResources(path.join(SOURCES, 'CloudFormationSchema'))
.importSamJsonSchema(path.join(SOURCES, 'SAMSpec/sam.schema.json'))
.importCloudFormationRegistryResources(path.join(SOURCES, 'CloudFormationSchema'), patchCloudFormationRegistry)
.importSamJsonSchema(path.join(SOURCES, 'SAMSpec/sam.schema.json'), patchSamTemplateSpec)
.importCloudFormationDocs(path.join(SOURCES, 'CloudFormationDocumentation/CloudFormationDocumentation.json'))
.importStatefulResources(path.join(SOURCES, 'StatefulResources/StatefulResources.json'))
.importCannedMetrics(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { EXCEPTIONS_PATCHERS } from './service-patches';
import { patching, patches } from '@aws-cdk/service-spec-importers';

/**
* Patchers that apply to the CloudFormation Registry source files
*/
export const patchCloudFormationRegistry = patching.makeCompositePatcher(
patches.patchCloudFormationRegistry,
...EXCEPTIONS_PATCHERS,
);
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { normalizeJsonSchema } from './json-schema-patches';
import { patching, patches, types } from '@aws-cdk/service-spec-importers';
import { addDefinitions, replaceDefinition, replaceDefinitionProperty } from './service-patches/core';
import { JsonObjectLens, JsonObjectPatcher, Patcher, Reason, makeCompositePatcher, onlyObjects } from '../patching';
import { jsonschema } from '../types';

const serverlessApi: Patcher<JsonObjectLens> = (lens) => {
const serverlessApi: patching.Patcher<patching.JsonObjectLens> = (lens) => {
replaceSamResourceProperty(
'AWS::Serverless::Api',
'EndpointConfiguration',
{
anyOf: [{ $ref: '#/definitions/AWS::Serverless::Api.EndpointConfiguration' }, { type: 'string' }],
},
Reason.backwardsCompat('Make the EndpointConfiguration property of AWS::Serverless::Api have a union type'),
patching.Reason.backwardsCompat(
'Make the EndpointConfiguration property of AWS::Serverless::Api have a union type',
),
)(lens);

replaceSamResourceProperty(
'AWS::Serverless::Api',
'GatewayResponses',
{ type: 'object' },
Reason.backwardsCompat('Make the GatewayResponses property of AWS::Serverless::Api accept JSON'),
patching.Reason.backwardsCompat('Make the GatewayResponses property of AWS::Serverless::Api accept JSON'),
)(lens);
replaceSamResourceProperty(
'AWS::Serverless::Api',
'Models',
{ type: 'object' },
Reason.backwardsCompat('Make the Models property of AWS::Serverless::Api accept JSON'),
patching.Reason.backwardsCompat('Make the Models property of AWS::Serverless::Api accept JSON'),
)(lens);
};

const serverlessFunction: Patcher<JsonObjectLens> = (lens) => {
const hooksReason = Reason.sourceIssue('Use of pattern properties but type is actually well-known.');
const serverlessFunction: patching.Patcher<patching.JsonObjectLens> = (lens) => {
const hooksReason = patching.Reason.sourceIssue('Use of pattern properties but type is actually well-known.');

replaceDefinitionProperty(
'AWS::Serverless::Function.DeploymentPreference',
Expand Down Expand Up @@ -59,7 +59,7 @@ const serverlessFunction: Patcher<JsonObjectLens> = (lens) => {
{
type: 'object',
},
Reason.backwardsCompat(
patching.Reason.backwardsCompat(
'This was once typed as Json, and adding types now is a breaking change. Keep them as Json forever',
),
)(lens);
Expand All @@ -74,18 +74,18 @@ const serverlessFunction: Patcher<JsonObjectLens> = (lens) => {
type: 'object',
required: ['SkillId'],
},
Reason.sourceIssue('SAM docs claim this is optional, but it is the only possible property'),
patching.Reason.sourceIssue('SAM docs claim this is optional, but it is the only possible property'),
)(lens);
};

const serverlessStateMachine: Patcher<JsonObjectLens> = (lens) => {
const serverlessStateMachine: patching.Patcher<patching.JsonObjectLens> = (lens) => {
replaceDefinitionProperty(
'AWS::Serverless::StateMachine.IAMPolicyDocument',
'Statement',
{
type: 'object',
},
Reason.backwardsCompat(
patching.Reason.backwardsCompat(
'This was once typed as Json, and adding types now is a breaking change. Keep them as Json forever',
),
)(lens);
Expand All @@ -94,9 +94,9 @@ const serverlessStateMachine: Patcher<JsonObjectLens> = (lens) => {
/**
* Patchers that apply to the SAM Template spec file
*/
export const patchSamTemplateSpec = makeCompositePatcher(
normalizeJsonSchema,
onlyObjects(makeCompositePatcher(serverlessApi, serverlessFunction, serverlessStateMachine)),
export const patchSamTemplateSpec = patching.makeCompositePatcher(
patches.normalizeJsonSchema,
patching.onlyObjects(patching.makeCompositePatcher(serverlessApi, serverlessFunction, serverlessStateMachine)),
);

/**
Expand All @@ -107,9 +107,9 @@ export const patchSamTemplateSpec = makeCompositePatcher(
function replaceSamResourceProperty(
resource: string,
propertyName: string,
newSchema: jsonschema.Schema,
reason: Reason,
): JsonObjectPatcher {
newSchema: types.jsonschema.Schema,
reason: patching.Reason,
): patching.JsonObjectPatcher {
return (lens) => {
if (lens.jsonPointer === `/definitions/${resource}/properties/Properties/properties/${propertyName}`) {
lens.replaceValue(reason.reason, newSchema);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forResource, fp, registerServicePatches, removeResourceProperty } from './core';
import { Reason } from '../../patching';
import { patching } from '@aws-cdk/service-spec-importers';

const reason = Reason.sourceIssue('Remove (presumed wrongly included) autoscaling group attribute');
const reason = patching.Reason.sourceIssue('Remove (presumed wrongly included) autoscaling group attribute');

registerServicePatches(
fp.removeFromReadOnlyProperties('AWS::AutoScaling::AutoScalingGroup', ['LaunchTemplateSpecification'], reason),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { forResource, registerServicePatches, renameDefinition } from './core';
import { Reason } from '../../patching';
import { patching } from '@aws-cdk/service-spec-importers';

registerServicePatches(
forResource('AWS::Batch::JobDefinition', (lens) => {
const reason = Reason.upstreamTypeNameChange();
const reason = patching.Reason.upstreamTypeNameChange();

renameDefinition('EksEmptyDir', 'EmptyDir', reason)(lens);
renameDefinition('EksHostPath', 'HostPath', reason)(lens);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forResource, registerServicePatches, removeResourceProperty } from './core';
import { Reason } from '../../patching';
import { patching } from '@aws-cdk/service-spec-importers';

const reason = Reason.sourceIssue('Property is only supported by the CCAPI');
const reason = patching.Reason.sourceIssue('Property is only supported by the CCAPI');

registerServicePatches(
forResource('AWS::CloudFormation::Stack', (lens) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { addDefinitions, forResource, registerServicePatches, replaceDefinition } from './core';
import { Reason } from '../../patching';
import { patching } from '@aws-cdk/service-spec-importers';

/**
* Add missing types for AWS::CodeBuild::Project
*/
registerServicePatches(
forResource('AWS::CodeBuild::Project', (lens) => {
const reason = Reason.sourceIssue(
const reason = patching.Reason.sourceIssue(
'The elements of AWS::CodeBuild::Project.Triggers.FilterGroups used to be well-typed in the Resource Specification. In the Resource Schema it is incorrectly an untyped object.',
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addDefinitions, forResource, registerServicePatches, replaceResourceProperty } from './core';
import { Reason } from '../../patching';
import { patching } from '@aws-cdk/service-spec-importers';

/**
* Make the use of the AWS::Cognito::IdentityPoolRoleAttachment.RoleMapings property safer
Expand All @@ -19,7 +19,7 @@ registerServicePatches(
type: 'object',
additionalProperties: { $ref: '#/definitions/RoleMapping' },
},
Reason.other('Make the use of RoleMappings more type safe'),
patching.Reason.other('Make the use of RoleMappings more type safe'),
)(lens);

addDefinitions(
Expand Down Expand Up @@ -67,7 +67,7 @@ registerServicePatches(
},
},

Reason.other('Make the use of RoleMappings more type safe'),
patching.Reason.other('Make the use of RoleMappings more type safe'),
)(lens);
}),
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { addDefinitions, forResource, registerServicePatches, replaceResourceProperty } from './core';
import { Reason } from '../../patching';
import { patching } from '@aws-cdk/service-spec-importers';

registerServicePatches(
forResource('AWS::Config::RemediationConfiguration', (lens) => {
const reason = Reason.sourceIssue('Unused property type in Spec, now missing in Schema');
const reason = patching.Reason.sourceIssue('Unused property type in Spec, now missing in Schema');
replaceResourceProperty(
'Parameters',
{
Expand Down
Loading
Loading