Skip to content

Add response metadata shape to output and exception interfaces #20

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

Merged
merged 2 commits into from
Jun 22, 2017
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {Exception} from "../../../lib/Components/Type/Exception";
import {IndentedSection} from "../../../lib/Components/IndentedSection";
import {
METADATA_PROPERTY_IMPORT,
OUTPUT_METADATA_PROPERTY,
} from "../../../lib/Components/Type/constants";

describe('Exception', () => {
it('should include standard exception members if not defined', () => {
Expand All @@ -12,7 +17,9 @@ describe('Exception', () => {
});

expect(exception.toString()).toEqual(
`/**
`${METADATA_PROPERTY_IMPORT.toString()}

/**
* <p>An exceptional state</p>
*/
export interface MyException {
Expand All @@ -30,6 +37,8 @@ export interface MyException {
* <p>Human-readable description of the error.</p>
*/
message?: string;

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
});
Expand All @@ -52,7 +61,9 @@ export interface MyException {
});

expect(exception.toString()).toEqual(
`/**
`${METADATA_PROPERTY_IMPORT.toString()}

/**
* <p>An exceptional state</p>
*/
export interface MyException {
Expand All @@ -70,6 +81,8 @@ export interface MyException {
* message property doc
*/
message?: string;

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
});
Expand All @@ -92,7 +105,9 @@ export interface MyException {
});

expect(exception.toString()).toEqual(
`/**
`${METADATA_PROPERTY_IMPORT.toString()}

/**
* <p>An exceptional state</p>
*/
export interface MyException {
Expand All @@ -110,6 +125,8 @@ export interface MyException {
* name property doc
*/
name?: string;

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
});
Expand All @@ -132,7 +149,9 @@ export interface MyException {
});

expect(exception.toString()).toEqual(
`/**
`${METADATA_PROPERTY_IMPORT.toString()}

/**
* <p>An exceptional state</p>
*/
export interface MyException {
Expand All @@ -150,6 +169,8 @@ export interface MyException {
* stack property doc
*/
stack?: string;

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import {
NonStreamingBlob,
StreamingBlob,
} from "../../../__fixtures__";
import {IndentedSection} from "../../../lib/Components/IndentedSection";
import {
METADATA_PROPERTY_IMPORT,
OUTPUT_METADATA_PROPERTY,
} from "../../../lib/Components/Type/constants";

describe('Output', () => {
it(
Expand All @@ -26,11 +31,13 @@ describe('Output', () => {
});

expect(output.toString()).toEqual(
`/**
`${METADATA_PROPERTY_IMPORT.toString()}

/**
* Operation output
*/
export interface ${name} {
${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
}
Expand All @@ -53,14 +60,18 @@ export interface ${name} {
});

expect(output.toString()).toEqual(
`/**
`${METADATA_PROPERTY_IMPORT.toString()}

/**
* Operation output
*/
export interface ${name}<${GENERIC_STREAM_TYPE}> {
/**
* ${StreamingBlob.documentation}
*/
data?: ${getMemberType(StreamingBlob)};

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
}
Expand All @@ -86,14 +97,18 @@ export interface ${name}<${GENERIC_STREAM_TYPE}> {
};

expect(new Output(output).toString()).toEqual(
`/**
`${METADATA_PROPERTY_IMPORT.toString()}

/**
* ${output.documentation}
*/
export interface ${name}<${GENERIC_STREAM_TYPE}> {
/**
* ${dataMember.documentation}
*/
data?: ${getMemberType(dataMember.shape, dataMember)};

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
}
Expand Down Expand Up @@ -122,6 +137,7 @@ export interface ${name}<${GENERIC_STREAM_TYPE}> {

expect(new Output(outputShape).toString()).toEqual(
`import {${getUnmarshalledShapeName(structure.name)}} from './${structure.name}';
${METADATA_PROPERTY_IMPORT.toString()}

/**
* ${outputShape.documentation}
Expand All @@ -131,6 +147,8 @@ export interface ${name} {
* ${structure.documentation}
*/
data?: ${getMemberType(structure)};

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
});
Expand Down Expand Up @@ -166,6 +184,7 @@ export interface ${name} {

expect(new Output(inputShape).toString()).toEqual(
`import {${getUnmarshalledShapeName(structureName)}} from './${structureName}';
${METADATA_PROPERTY_IMPORT.toString()}

/**
* ${inputShape.documentation}
Expand All @@ -175,6 +194,8 @@ export interface ${name} {
* ${structureList.documentation}
*/
data?: ${getMemberType(structureList)};

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
});
Expand Down Expand Up @@ -221,6 +242,7 @@ export interface ${name} {
expect(new Output(inputShape).toString()).toEqual(
`import {${getUnmarshalledShapeName(keyStructure)}} from './${keyStructure}';
import {${getUnmarshalledShapeName(valueStructure)}} from './${valueStructure}';
${METADATA_PROPERTY_IMPORT.toString()}

/**
* ${inputShape.documentation}
Expand All @@ -230,6 +252,8 @@ export interface ${name} {
* ${structureMap.documentation}
*/
data?: ${getMemberType(structureMap)};

${new IndentedSection(OUTPUT_METADATA_PROPERTY)}
}`
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {Structure} from "./Structure";
import {SerializationType} from "@aws/types";
import {IndentedSection} from "../IndentedSection";
import {getUnmarshalledShapeName} from "./helpers";
import {Import} from "../Import";
import {
METADATA_PROPERTY_IMPORT,
OUTPUT_METADATA_PROPERTY,
} from "./constants";

interface InnateMember {
memberName: string;
Expand All @@ -15,16 +21,29 @@ export class Exception extends Structure {
.map(this.formatInnateMember, this)
.concat(
Object.keys(this.shape.members)
.map(this.getMemberDefinition, this)
.map(this.getMemberDefinition, this),
OUTPUT_METADATA_PROPERTY
);
return `
${this.imports}

${this.docBlock(this.shape.documentation)}
export interface ${this.shape.name} {
${new IndentedSection(members.join('\n\n'))}
}
`.trim();
}

private get imports(): string {
return this.foreignShapes
.map(shape => new Import(
`./${shape}`,
getUnmarshalledShapeName(shape)
))
.concat(METADATA_PROPERTY_IMPORT)
.join('\n');
}

private get innateMembers(): InnateMember[] {
const {members} = this.shape;
const innateMembers: InnateMember[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import {Structure} from "./Structure";
import {GENERIC_STREAM_TYPE} from '../../constants';
import {IndentedSection} from "../IndentedSection";
import {getUnmarshalledShapeName, hasStreamingBody} from "./helpers";
import {
METADATA_PROPERTY_IMPORT,
OUTPUT_METADATA_PROPERTY,
} from './constants';

export class Output extends Structure {

toString(): string {
return `
${this.imports}
Expand All @@ -15,6 +18,7 @@ export interface ${this.shape.name}${hasStreamingBody(this.shape) ? `<${GENERIC_
${new IndentedSection(
Object.keys(this.shape.members)
.map(this.getMemberDefinition, this)
.concat(OUTPUT_METADATA_PROPERTY)
.join('\n\n')
)}
}
Expand All @@ -27,6 +31,7 @@ ${new IndentedSection(
`./${shape}`,
getUnmarshalledShapeName(shape)
))
.concat(METADATA_PROPERTY_IMPORT)
.join('\n');
}
}
16 changes: 16 additions & 0 deletions packages/service-types-generator/lib/Components/Type/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Import} from "../Import";

const MD_PROP_ALIAS = '__ResponseMetadata__';

export const METADATA_PROPERTY_IMPORT = new Import(
'@aws/types',
`ResponseMetadata as ${MD_PROP_ALIAS}`
);

export const OUTPUT_METADATA_PROPERTY = `
/**
* Metadata about the response received, including the HTTP status code, HTTP
* headers, and any request identifiers recognized by the SDK.
*/
$metadata: ${MD_PROP_ALIAS};
`.trim();
1 change: 1 addition & 0 deletions packages/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './credentials';
export * from './protocol';
export * from './response';
11 changes: 11 additions & 0 deletions packages/types/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface ResponseHeaders {
readonly [index: string]: Array<string>;
}

export interface ResponseMetadata {
statusCode: number;
requestId?: string;
extendedRequestId?: string;
cfId?: string;
responseHeaders: ResponseHeaders;
}