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

fix(location): dataSource property is not required #31314

Closed
wants to merge 2 commits into from
Closed
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: 4 additions & 2 deletions packages/@aws-cdk/aws-location-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ To create a place index, define a `PlaceIndex`:
```ts
new location.PlaceIndex(this, 'PlaceIndex', {
placeIndexName: 'MyPlaceIndex', // optional, defaults to a generated name
dataSource: location.DataSource.HERE, // optional, defaults to Esri
dataSource: location.DataSource.ESRI,
});
```

Expand All @@ -46,7 +46,9 @@ on the place index:
```ts
declare const role: iam.Role;

const placeIndex = new location.PlaceIndex(this, 'PlaceIndex');
const placeIndex = new location.PlaceIndex(this, 'PlaceIndex', {
dataSource: location.DataSource.ESRI,
});
placeIndex.grantSearch(role);
```

Expand Down
6 changes: 2 additions & 4 deletions packages/@aws-cdk/aws-location-alpha/lib/place-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ export interface PlaceIndexProps {

/**
* Data source for the place index
*
* @default DataSource.ESRI
*/
readonly dataSource?: DataSource;
readonly dataSource: DataSource;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A property being required on CFN does not necessarily mean we have to require it in CDK, if we can find a reasonable default for it. That's what we've done here -- we are not sending undefined into CFN and getting an error back, we are providing what we think is a sane default.

It sounds like you don't think that DataSource.ESRI is a reasonable default -- before making that change, I think that's a better discussion to have in an issue.


/**
* Intend use for the results of an operation
Expand Down Expand Up @@ -159,7 +157,7 @@ export class PlaceIndex extends PlaceIndexBase {
*/
public readonly placeIndexUpdateTime: string;

constructor(scope: Construct, id: string, props: PlaceIndexProps = {}) {
constructor(scope: Construct, id: string, props: PlaceIndexProps) {
if (props.description && !Token.isUnresolved(props.description) && props.description.length > 1000) {
throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { App, Stack } from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import { Construct } from 'constructs';
import { PlaceIndex } from '../lib';
import { DataSource, PlaceIndex } from '../lib';

class TestStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);

new PlaceIndex(this, 'PlaceIndex');
new PlaceIndex(this, 'PlaceIndex', {
dataSource: DataSource.ESRI,
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ beforeEach(() => {
});

test('create a place index', () => {
new PlaceIndex(stack, 'PlaceIndex');
new PlaceIndex(stack, 'PlaceIndex', {
dataSource: DataSource.ESRI,
});

Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', {
DataSource: 'Esri',
Expand All @@ -21,6 +23,7 @@ test('create a place index', () => {
test('create a place index with description', () => {
new PlaceIndex(stack, 'PlaceIndex', {
description: 'my-description',
dataSource: DataSource.ESRI,
});

Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', {
Expand All @@ -33,6 +36,7 @@ test('create a place index with description', () => {
test('creates a place index with empty description', () => {
new PlaceIndex(stack, 'PlaceIndex', {
description: '',
dataSource: DataSource.ESRI,
});

Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', {
Expand All @@ -43,12 +47,14 @@ test('creates a place index with empty description', () => {
test('throws with invalid description', () => {
expect(() => new PlaceIndex(stack, 'PlaceIndex', {
description: 'a'.repeat(1001),
dataSource: DataSource.ESRI,
})).toThrow('`description` must be between 0 and 1000 characters. Received: 1001 characters');
});

test('throws with invalid name', () => {
expect(() => new PlaceIndex(stack, 'PlaceIndex', {
placeIndexName: 'inv@lid',
dataSource: DataSource.ESRI,
})).toThrow(/Invalid place index name/);
});

Expand Down
Loading