-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: SAM spec type is wrong for Serverless Function Policies (#636)
The apparent contract we didn't implement correctly was that the fields named `Inclusive*ItemTypes` need to be respected, regardless of whether the top-level type includes `List` or not. So force that behavior.
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/@aws-cdk/service-spec-importers/test/sam-spec.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { emptyDatabase } from '@aws-cdk/service-spec-types'; | ||
import { SAMSpecImporter } from '../src/importers/import-resource-spec'; | ||
|
||
/** | ||
* Tests for the CloudFormation spec of SAM | ||
*/ | ||
|
||
let db: ReturnType<typeof emptyDatabase>; | ||
beforeEach(() => { | ||
db = emptyDatabase(); | ||
}); | ||
|
||
test('respect InclusivePrimitiveItemTypes even if List is not given', () => { | ||
SAMSpecImporter.importTypes({ | ||
db, | ||
specification: { | ||
ResourceSpecificationVersion: '2016-10-31', | ||
ResourceSpecificationTransform: 'AWS::Serverless-2016-10-31', | ||
ResourceTypes: { | ||
'AWS::Some::Type': { | ||
Properties: { | ||
SomeParameter: { | ||
UpdateType: 'Mutable', | ||
PrimitiveTypes: ['String'], | ||
Types: ['Type1'], | ||
InclusivePrimitiveItemTypes: ['Integer'], | ||
InclusiveItemTypes: ['Type2'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
PropertyTypes: { | ||
'AWS::Some::Type.Type1': { | ||
Properties: { | ||
Field: { UpdateType: 'Mutable', PrimitiveType: 'String' }, | ||
}, | ||
}, | ||
'AWS::Some::Type.Type2': { | ||
Properties: { | ||
Field: { UpdateType: 'Mutable', PrimitiveType: 'String' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const resource = db.lookup('resource', 'cloudFormationType', 'equals', 'AWS::Some::Type').only(); | ||
expect(resource.properties.SomeParameter.type).toEqual({ | ||
type: 'union', | ||
types: [ | ||
{ | ||
type: 'string', | ||
}, | ||
{ | ||
reference: { | ||
$ref: '2', | ||
}, | ||
type: 'ref', | ||
}, | ||
{ | ||
element: { | ||
type: 'union', | ||
types: [ | ||
{ | ||
type: 'integer', | ||
}, | ||
{ | ||
reference: { | ||
$ref: '3', | ||
}, | ||
type: 'ref', | ||
}, | ||
], | ||
}, | ||
type: 'array', | ||
}, | ||
], | ||
}); | ||
}); |