@@ -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
0 commit comments