Skip to content

Commit 3b3ccc7

Browse files
committed
test types and other fixes
1 parent 64b312c commit 3b3ccc7

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

packages/core/src/submodules/cbor/SmithyRpcV2CborProtocol.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ describe(SmithyRpcV2CborProtocol.name, () => {
153153
const protocol = new SmithyRpcV2CborProtocol({ defaultNamespace: "" });
154154
const httpRequest = await protocol.serializeRequest(
155155
{
156+
namespace: "ns",
156157
name: "dummy",
157158
input: testCase.schema,
158159
output: "unit",
@@ -256,6 +257,7 @@ describe(SmithyRpcV2CborProtocol.name, () => {
256257
});
257258
const output = await protocol.deserializeResponse(
258259
{
260+
namespace: "ns",
259261
name: "dummy",
260262
input: "unit",
261263
output: testCase.schema,

packages/core/src/submodules/cbor/SmithyRpcV2CborProtocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { RpcProtocol } from "@smithy/core/protocols";
2-
import type { ErrorSchema, OperationSchema } from "@smithy/core/schema";
2+
import type { ErrorSchema } from "@smithy/core/schema";
33
import { deref, NormalizedSchema, TypeRegistry } from "@smithy/core/schema";
44
import type {
55
EndpointBearer,
66
HandlerExecutionContext,
77
HttpRequest as IHttpRequest,
88
HttpResponse as IHttpResponse,
99
MetadataBearer,
10+
OperationSchema,
1011
ResponseMetadata,
1112
SerdeFunctions,
1213
} from "@smithy/types";

packages/core/src/submodules/schema/schemas/NormalizedSchema.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ export class NormalizedSchema implements INormalizedSchema {
3737
* @param ref - a polymorphic SchemaRef to be dereferenced/normalized.
3838
* @param memberName - optional memberName if this NormalizedSchema should be considered a member schema.
3939
*/
40-
private constructor(
41-
readonly ref: SchemaRef,
42-
private memberName?: string
43-
) {
40+
private constructor(readonly ref: SchemaRef, private memberName?: string) {
4441
const traitStack = [] as SchemaTraits[];
4542
let _ref = ref;
4643
let schema = ref;
@@ -95,13 +92,18 @@ export class NormalizedSchema implements INormalizedSchema {
9592
* Static constructor that attempts to avoid wrapping a NormalizedSchema within another.
9693
*/
9794
public static of(ref: SchemaRef): NormalizedSchema {
95+
if (ref instanceof NormalizedSchema) {
96+
return ref;
97+
}
9898
if (Array.isArray(ref)) {
99+
const [ns, traits] = ref;
100+
if (ns instanceof NormalizedSchema) {
101+
Object.assign(ns.getMergedTraits(), NormalizedSchema.translateTraits(traits));
102+
return ns;
103+
}
99104
// An aggregate schema must be initialized with members and the member retrieved through the aggregate
100105
// container.
101-
throw new Error("@smithy/core/schema - may not init member schema.");
102-
}
103-
if (ref instanceof NormalizedSchema) {
104-
return ref;
106+
throw new Error(`@smithy/core/schema - may not init unwrapped member schema=${JSON.stringify(ref, null, 2)}.`);
105107
}
106108
return new NormalizedSchema(ref);
107109
}
@@ -386,15 +388,17 @@ export class NormalizedSchema implements INormalizedSchema {
386388
*
387389
* This does NOT return list and map members, it is only for structures.
388390
*
389-
* @deprecated use structIterator instead.
391+
* @deprecated use (checked) structIterator instead.
390392
*
391393
* @returns a map of member names to member schemas (normalized).
392394
*/
393395
public getMemberSchemas(): Record<string, NormalizedSchema> {
394396
const buffer = {} as any;
395-
for (const [k, v] of this.structIterator()) {
396-
buffer[k] = v;
397-
}
397+
try {
398+
for (const [k, v] of this.structIterator()) {
399+
buffer[k] = v;
400+
}
401+
} catch (ignored) {}
398402
return buffer;
399403
}
400404

packages/types/src/schema/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export type SchemaTraits = TraitBitVector | SchemaTraitsObject;
5050
* @public
5151
*/
5252
export interface TraitsSchema {
53+
namespace: string;
5354
name: string;
5455
traits: SchemaTraits;
5556
}

0 commit comments

Comments
 (0)