Skip to content

Commit 3d57d3d

Browse files
committed
fix(codegen): for static schema
1 parent 761d89c commit 3d57d3d

File tree

11 files changed

+67
-66
lines changed

11 files changed

+67
-66
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@smithy/core": patch
3+
"@smithy/types": patch
4+
---
5+
6+
fix ordering of static simple schema type

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
OperationSchema,
1111
ResponseMetadata,
1212
SerdeFunctions,
13+
StaticErrorSchema,
1314
} from "@smithy/types";
1415
import { getSmithyContext } from "@smithy/util-middleware";
1516

@@ -104,9 +105,9 @@ export class SmithyRpcV2CborProtocol extends RpcProtocol {
104105

105106
const registry = TypeRegistry.for(namespace);
106107

107-
let errorSchema: ErrorSchema;
108+
let errorSchema: StaticErrorSchema;
108109
try {
109-
errorSchema = registry.getSchema(errorName) as ErrorSchema;
110+
errorSchema = registry.getSchema(errorName) as StaticErrorSchema;
110111
} catch (e) {
111112
if (dataObject.Message) {
112113
dataObject.message = dataObject.Message;

packages/core/src/submodules/schema/TypeRegistry.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class TypeRegistry {
3535
*/
3636
public register(shapeId: string, schema: ISchema) {
3737
const qualifiedName = this.normalizeShapeId(shapeId);
38-
this.schemas.set(qualifiedName, schema);
38+
const registry = TypeRegistry.for(qualifiedName.split("#")[0]);
39+
registry.schemas.set(qualifiedName, schema);
3940
}
4041

4142
/**
@@ -54,15 +55,20 @@ export class TypeRegistry {
5455
* Associates an error schema with its constructor.
5556
*/
5657
public registerError(es: ErrorSchema | StaticErrorSchema, ctor: any) {
57-
this.exceptions.set(es, ctor);
58+
const $error = es as StaticErrorSchema;
59+
const registry = TypeRegistry.for($error[1]);
60+
registry.schemas.set($error[1] + "#" + $error[2], $error);
61+
registry.exceptions.set($error, ctor);
5862
}
5963

6064
/**
6165
* @param es - query.
6266
* @returns Error constructor that extends the service's base exception.
6367
*/
6468
public getErrorCtor(es: ErrorSchema | StaticErrorSchema): any {
65-
return this.exceptions.get(es);
69+
const $error = es as StaticErrorSchema;
70+
const registry = TypeRegistry.for($error[1]);
71+
return registry.exceptions.get(es);
6672
}
6773

6874
/**
@@ -78,10 +84,14 @@ export class TypeRegistry {
7884
*
7985
* @returns the synthetic base exception of the service namespace associated with this registry instance.
8086
*/
81-
public getBaseException(): ErrorSchema | undefined {
82-
for (const [id, schema] of this.schemas.entries()) {
83-
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
84-
return schema as ErrorSchema;
87+
public getBaseException(): StaticErrorSchema | undefined {
88+
for (const exceptionKey of this.exceptions.keys()) {
89+
if (Array.isArray(exceptionKey)) {
90+
const [, ns, name] = exceptionKey;
91+
const id = ns + "#" + name;
92+
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
93+
return exceptionKey;
94+
}
8595
}
8696
}
8797
return undefined;
@@ -109,8 +119,4 @@ export class TypeRegistry {
109119
}
110120
return this.namespace + "#" + shapeId;
111121
}
112-
113-
private getNamespace(shapeId: string) {
114-
return this.normalizeShapeId(shapeId).split("#")[0];
115-
}
116122
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import type { OperationSchema } from "./OperationSchema";
4343
import { op } from "./OperationSchema";
4444
import { Schema } from "./Schema";
4545
import type { SimpleSchema } from "./SimpleSchema";
46-
import { sim } from "./SimpleSchema";
46+
import { simAdapter } from "./SimpleSchema";
4747
import { struct, StructureSchema } from "./StructureSchema";
4848
import { translateTraits } from "./translateTraits";
4949

@@ -450,7 +450,7 @@ export function hydrate(
450450
const [id, ...rest] = ss;
451451
return (
452452
{
453-
[0 satisfies StaticSchemaIdSimple]: sim,
453+
[0 satisfies StaticSchemaIdSimple]: simAdapter,
454454
[1 satisfies StaticSchemaIdList]: list,
455455
[2 satisfies StaticSchemaIdMap]: map,
456456
[3 satisfies StaticSchemaIdStruct]: struct,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export abstract class Schema implements TraitsSchema {
1515

1616
public static assign<T extends Schema>(instance: T, values: Omit<T, "getName" | "symbol">): T {
1717
const schema = Object.assign(instance, values);
18-
TypeRegistry.for(schema.namespace).register(schema.name, schema);
18+
// TypeRegistry.for(schema.namespace).register(schema.name, schema);
1919
return schema;
2020
}
2121

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,15 @@ export const sim = (namespace: string, name: string, schemaRef: SchemaRef, trait
2929
traits,
3030
schemaRef,
3131
});
32+
33+
/**
34+
* @internal
35+
* @deprecated
36+
*/
37+
export const simAdapter = (namespace: string, name: string, traits: SchemaTraits, schemaRef: SchemaRef) =>
38+
Schema.assign(new SimpleSchema(), {
39+
name,
40+
namespace,
41+
traits,
42+
schemaRef,
43+
});

packages/types/src/schema/static-schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export type ShapeNamespace = string;
5959
/**
6060
* @alpha
6161
*/
62-
export type StaticSimpleSchema = [StaticSchemaIdSimple, ShapeNamespace, ShapeName, SchemaRef, SchemaTraits];
62+
export type StaticSimpleSchema = [StaticSchemaIdSimple, ShapeNamespace, ShapeName, SchemaTraits, SchemaRef];
6363

6464
/**
6565
* @alpha

private/my-local-model/src/models/models_0.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ export interface GetNumbersRequest {
4242
/**
4343
* This is deprecated documentation annotation
4444
*
45-
* @deprecated deprecated
45+
* @deprecated
4646
* @public
4747
*/
4848
fieldWithoutMessage?: string | undefined;
4949

5050
/**
5151
* This is deprecated documentation annotation
5252
*
53-
* @deprecated This field has been deprecated
53+
* @deprecated
5454
* @public
5555
*/
5656
fieldWithMessage?: string | undefined;

private/smithy-rpcv2-cbor-schema/src/schemas/schemas_0.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ import {
137137
InvalidGreeting as __InvalidGreeting,
138138
ValidationException as __ValidationException,
139139
} from "../models/index";
140-
import { TypeRegistry, error } from "@smithy/core/schema";
140+
import { TypeRegistry } from "@smithy/core/schema";
141141
import {
142142
StaticErrorSchema,
143143
StaticListSchema,
@@ -295,26 +295,15 @@ export var RpcV2CborDenseMapsInputOutput: StaticStructureSchema = [
295295
_RVCDMIO,
296296
0,
297297
[_dSM, _dNM, _dBM, _dSMe, _dSMen],
298-
[() => DenseStructMap, 128 | 1, 128 | 2, 128 | 0, [2, n1, _DSM, 0, 64 | 0, 64 | 0] as StaticMapSchema],
298+
[() => DenseStructMap, 128 | 1, 128 | 2, 128 | 0, [2, n1, _DSM, 0, 0, 64 | 0]],
299299
];
300300
export var RpcV2CborListInputOutput: StaticStructureSchema = [
301301
3,
302302
n1,
303303
_RVCLIO,
304304
0,
305305
[_sL, _sS, _iL, _bL, _tL, _eL, _iEL, _nSL, _sLt, _bLl],
306-
[
307-
64 | 0,
308-
64 | 0,
309-
64 | 1,
310-
64 | 2,
311-
64 | 4,
312-
64 | 0,
313-
64 | 1,
314-
[1, n2, _NSL, 0, 64 | 0] as StaticListSchema,
315-
() => StructureList,
316-
64 | 21,
317-
],
306+
[64 | 0, 64 | 0, 64 | 1, 64 | 2, 64 | 4, 64 | 0, 64 | 1, [1, n2, _NSL, 0, 64 | 0], () => StructureList, 64 | 21],
318307
];
319308
export var RpcV2CborSparseMapsInputOutput: StaticStructureSchema = [
320309
3,
@@ -352,7 +341,7 @@ export var SparseNullsOperationInputOutput: StaticStructureSchema = [
352341
];
353342
export var StructureListMember: StaticStructureSchema = [3, n1, _SLM, 0, [_a, _b_], [0, 0]];
354343
export var GreetingStruct: StaticStructureSchema = [3, n2, _GS, 0, [_h], [0]];
355-
export var RpcV2ProtocolServiceException = error(_sC, "RpcV2ProtocolServiceException", 0, [], [], null);
344+
export var RpcV2ProtocolServiceException: StaticErrorSchema = [-3, _sC, "RpcV2ProtocolServiceException", 0, [], []];
356345
TypeRegistry.for(_sC).registerError(RpcV2ProtocolServiceException, __RpcV2ProtocolServiceException);
357346

358347
export var ValidationExceptionFieldList: StaticListSchema = [1, n0, _VEFL, 0, () => ValidationExceptionField];

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptWriter.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ boolean writeShapeDocs(Shape shape, UnaryOperator<String> preprocessor) {
225225
if (shape.getTrait(DeprecatedTrait.class).isPresent()) {
226226
DeprecatedTrait deprecatedTrait = shape.expectTrait(DeprecatedTrait.class);
227227
String deprecationMessage = deprecatedTrait.getMessage()
228-
.orElse("deprecated");
229-
String deprecationAnnotation = "@deprecated " + deprecationMessage;
230-
docs = docs + "\n\n" + deprecationAnnotation;
228+
.map(msg -> " " + msg)
229+
.orElse("");
230+
String deprecationString = "@deprecated" + deprecationMessage;
231+
docs = docs + "\n\n" + deprecationString;
231232
}
232233
docs = preprocessor.apply(docs);
233234
docs = addReleaseTag(shape, docs);
@@ -265,13 +266,10 @@ boolean writeMemberDocs(Model model, MemberShape member) {
265266
docs = docs.replace("{", "\\{")
266267
.replace("}", "\\}");
267268
if (member.getTrait(DeprecatedTrait.class).isPresent() || isTargetDeprecated(model, member)) {
268-
DeprecatedTrait deprecatedTrait = member.getTrait(DeprecatedTrait.class)
269+
docs = docs + "\n\n@deprecated";
270+
member.getTrait(DeprecatedTrait.class)
269271
.or(() -> model.expectShape(member.getTarget()).getTrait(DeprecatedTrait.class))
270272
.orElseThrow();
271-
String deprecationMessage = deprecatedTrait.getMessage()
272-
.orElse("deprecated");
273-
String deprecationAnnotation = "@deprecated " + deprecationMessage;
274-
docs = docs + "\n\n" + deprecationAnnotation;
275273
}
276274
docs = addReleaseTag(member, docs);
277275
writeDocs(docs);

0 commit comments

Comments
 (0)