Skip to content

Commit 37847db

Browse files
committed
add missed fullname replacement and deprecate smithy namespace mapping
1 parent 5aed2b4 commit 37847db

11 files changed

Lines changed: 50 additions & 217 deletions

File tree

‎.changelog/bugfix-fix-legacy-id-table.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"type": "bugfix",
33
"category": "tools",
44
"contributor": "",
5-
"description": "Derive generated service client namespaces from the service ID (codegen ID) in both the C2J and Smithy code generators. Generated client output is unchanged."
5+
"description": "Derive generated service client namespaces from the service ID in both the C2J and Smithy code generators. Generated client output is unchanged."
66
}

‎tools/code-generation/generator/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<resource>
2222
<directory>src/main/resources</directory>
2323
</resource>
24-
<!-- Shared Service ID SEP identifier table, single source of truth shared with the
25-
Smithy generator. Bundled onto the classpath so ServiceNamespaceTable can load it. -->
24+
<!-- Shared service-id -> namespace identifier table, single source of truth shared with
25+
the Smithy generator. Bundled onto the classpath so ServiceNamespaceTable can load it. -->
2626
<resource>
2727
<directory>../shared</directory>
2828
<includes>

‎tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/domainmodels/codegeneration/Metadata.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ public String findFirstSupportedProtocol() {
7272
return protocol;
7373
}
7474

75-
//We're releasing CBOR so current services (only arc-region-switch) need to opt into the new protocol priority
76-
if (serviceFullName != null && serviceFullName.equalsIgnoreCase("ARC - Region switch")){
75+
//We're releasing CBOR so current services (only arc-region-switch) need to opt into the new protocol priority.
76+
//Match on the service id (serviceId), NOT the display name (serviceFullName), so a
77+
//display-name change can never silently flip the wire protocol (JSON <-> CBOR).
78+
if (serviceId != null && serviceId.equalsIgnoreCase("ARC Region switch")){
7779
return "json";
7880
}
7981

8082
return protocols.stream().filter(supportedProtocols::contains)
8183
.min(Comparator.comparingInt(protocolName -> supportedProtocols.indexOf(protocolName)))
82-
.orElseThrow(() -> new RuntimeException(String.format("No supported protocol found for %s", serviceFullName)));
84+
.orElseThrow(() -> new RuntimeException(String.format("No supported protocol found for %s", serviceId)));
8385
}
8486
}

‎tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/transform/C2jModelToGeneratorModelTransformer.java‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public class C2jModelToGeneratorModelTransformer {
5252
UNSUPPORTEDHTMLTAGS.add("</important>");
5353
}
5454

55-
// SEP exception: a few ancient models carry no "serviceId" at all, so their namespace cannot
56-
// be keyed by one (the Service ID SEP forbids keying on a docgen id, endpoint prefix, or model
57-
// file name). Their already-released namespaces are therefore preserved by model (service)
58-
// name. Every other preserved namespace lives in the shared, serviceId-keyed identifier table
55+
// A few ancient models carry no "serviceId" at all, so their namespace cannot be keyed by one
56+
// (identifiers must not be keyed on a display name, endpoint prefix, or model file name). Their
57+
// already-released namespaces are therefore preserved by model (service) name. Every other
58+
// preserved namespace lives in the shared, serviceId-keyed identifier table
5959
// (service-namespace-table.json via ServiceNamespaceTable).
6060
private static final Map<String, String> SERVICE_ID_LESS_NAMESPACES = new HashMap<>();
6161
static {
@@ -268,10 +268,10 @@ Metadata convertMetadata() {
268268
metadata.setGlobalEndpoint(c2jMetadata.getGlobalEndpoint());
269269
metadata.setTimestampFormat(c2jMetadata.getTimestampFormat());
270270

271-
// Service namespace is derived from the codegen id ("serviceId") ONLY, per Revision 2 of
272-
// the Service ID SEP. Docgen ids (serviceAbbreviation / serviceFullName) MUST NOT be read
273-
// to derive it. Names released before that revision that diverge from the serviceId-derived
274-
// name are preserved via the static, serviceId-keyed identifier table (ServiceNamespaceTable).
271+
// Service namespace is derived from the service id ("serviceId") ONLY. The display-name
272+
// fields (serviceAbbreviation / serviceFullName) MUST NOT be read to derive it. Names that
273+
// diverge from the serviceId-derived name are preserved via the static, serviceId-keyed
274+
// identifier table (ServiceNamespaceTable).
275275
metadata.setNamespace(deriveNamespace(c2jMetadata, this.c2jServiceModel.getServiceName()));
276276

277277
metadata.setServiceId(c2jMetadata.getServiceId() != null ? c2jMetadata.getServiceId() : c2jMetadata.getEndpointPrefix());
@@ -978,20 +978,20 @@ Error convertError(C2jError c2jError, String operationName) {
978978
}
979979

980980
/**
981-
* Derive the service namespace from the codegen id ("serviceId") only, consulting the frozen,
981+
* Derive the service namespace from the service id ("serviceId") only, consulting the frozen,
982982
* serviceId-keyed identifier table (ServiceNamespaceTable) for already-released names that
983-
* diverge from it. See the Service ID SEP (seps/accepted/shared/service-id.md).
983+
* diverge from it.
984984
*
985985
* @param c2jMetadata the raw C2J metadata for the service
986986
* @param serviceModelName the model (service) name, used only for S3-CRT and for the two
987-
* serviceId-less SEP exceptions; never used to derive a tabled value
987+
* serviceId-less exceptions; never used to derive a tabled value
988988
*/
989989
String deriveNamespace(C2jMetadata c2jMetadata, String serviceModelName) {
990990
// S3-CRT is a projection of s3 with no model of its own.
991991
if ("S3-CRT".equalsIgnoreCase(serviceModelName)) {
992992
return "S3Crt";
993993
}
994-
// SEP exception: pre-serviceId models (see SERVICE_ID_LESS_NAMESPACES).
994+
// Exception: pre-serviceId models (see SERVICE_ID_LESS_NAMESPACES).
995995
String serviceIdLess = SERVICE_ID_LESS_NAMESPACES.get(serviceModelName);
996996
if (serviceIdLess != null) {
997997
return serviceIdLess;
@@ -1007,7 +1007,7 @@ String deriveNamespace(C2jMetadata c2jMetadata, String serviceModelName) {
10071007
return preserved;
10081008
}
10091009
String derived = sanitizeServiceAbbreviation(serviceId);
1010-
// SEP uniqueness guard: a serviceId-derived name must never collide with a preserved one.
1010+
// Uniqueness guard: a serviceId-derived name must never collide with a preserved one.
10111011
if (ServiceNamespaceTable.isReservedNamespace(derived)) {
10121012
throw new SourceGenerationFailedException(String.format(
10131013
"Derived namespace '%s' for serviceId '%s' collides with a reserved namespace "

‎tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/transform/ServiceNamespaceTable.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
import java.util.Map;
1717

1818
/**
19-
* Static, checked-in table that preserves the C++ SDK service namespaces released before
20-
* Revision 2 of the Service ID SEP (seps/accepted/shared/service-id.md) that diverge from the
21-
* namespace derived from the service's codegen id ("serviceId").
19+
* Static, checked-in table that preserves the C++ SDK service namespaces that diverge from the
20+
* namespace derived from the service's {@code "serviceId"} (so previously released names stay
21+
* stable).
2222
*
23-
* <p>The table is keyed by the exact, untransformed "serviceId" and is loaded from the shared
24-
* data file {@code service-namespace-table.json}, which is the single source of truth shared
25-
* with the Smithy generator. The SEP forbids keying on a docgen id, an endpoint prefix, or a
26-
* model file name, and forbids deriving the preserved value from any of those; the values here
27-
* are frozen literals, not computed from model metadata at generation time.
23+
* <p>The table is keyed by the exact, untransformed {@code "serviceId"} and is loaded from the
24+
* shared data file {@code service-namespace-table.json}, which is the single source of truth
25+
* shared with the Smithy generator. Identifiers are derived from {@code "serviceId"} only, never
26+
* from the display-name fields ({@code serviceAbbreviation}/{@code serviceFullName}), the endpoint
27+
* prefix, or the model file name; the values here are frozen literals, not computed from model
28+
* metadata at generation time.
2829
*/
2930
public final class ServiceNamespaceTable {
3031

‎tools/code-generation/smithy/cpp-codegen/smithy-cpp-codegen/build.gradle.kts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ tasks.test {
3232
useJUnitPlatform()
3333
}
3434

35-
// Bundle the shared Service ID SEP identifier table (single source of truth, also consumed by the
36-
// C2J generator) onto the classpath so ServiceNamespaceTable can load it as a resource.
35+
// Bundle the shared service-id -> namespace identifier table (single source of truth, also consumed
36+
// by the C2J generator) onto the classpath so ServiceNamespaceTable can load it as a resource.
3737
tasks.named<ProcessResources>("processResources") {
3838
from("$projectDir/../../../shared") {
3939
include("service-namespace-table.json")

‎tools/code-generation/smithy/cpp-codegen/smithy-cpp-codegen/src/main/java/com/amazonaws/util/awsclientsmithygenerator/generators/ServiceNameUtil.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public final class ServiceNameUtil {
1616
private static final String S3_CRT_PROJECTION_PREFIX = "s3-crt";
1717
private static final String S3_CRT_NAMESPACE = "S3Crt";
1818

19-
// SEP exception: legacy services with NO serviceId in their C2J model (generated as Smithy
20-
// "mock" projections). They cannot be keyed by serviceId, so their already-released namespaces
21-
// are preserved here, keyed by the normalized (sanitized, lower-cased) sdkId. Every other
22-
// preserved namespace lives in the shared, serviceId-keyed table (ServiceNamespaceTable).
19+
// Legacy services with NO serviceId in their C2J model (generated as Smithy "mock" projections).
20+
// They cannot be keyed by serviceId, so their already-released namespaces are preserved here,
21+
// keyed by the normalized (sanitized, lower-cased) sdkId. Every other preserved namespace lives
22+
// in the shared, serviceId-keyed table (ServiceNamespaceTable).
2323
private static final Map<String, String> SERVICE_ID_LESS_NAMESPACES = Map.ofEntries(
2424
Map.entry("importexport", "ImportExport"),
2525
Map.entry("simpledb", "SimpleDB")
@@ -31,29 +31,29 @@ public static String getServiceName(ServiceShape service) {
3131
return S3_CRT_NAMESPACE;
3232
}
3333

34-
// Namespace is derived from the codegen id (sdkId == C2J serviceId) ONLY, per Revision 2 of
35-
// the Service ID SEP. Docgen ids (smithy.api#title) MUST NOT be read. Pre-rev2 names that
36-
// diverge from the sdkId-derived name are preserved via the shared identifier table.
34+
// Namespace is derived from the service id (sdkId == C2J serviceId) ONLY. The display name
35+
// (smithy.api#title) MUST NOT be read. Names that diverge from the sdkId-derived name are
36+
// preserved via the shared identifier table.
3737
String serviceId = service.getTrait(ServiceTrait.class)
3838
.map(ServiceTrait::getSdkId)
3939
.orElse(service.getId().getName());
4040

4141
String sanitized = sanitizeServiceAbbreviation(serviceId);
4242
String key = sanitized.toLowerCase();
4343

44-
// SEP exception: serviceId-less legacy (mock) services.
44+
// Exception: serviceId-less legacy (mock) services.
4545
String exception = SERVICE_ID_LESS_NAMESPACES.get(key);
4646
if (exception != null) {
4747
return exception;
4848
}
4949

50-
// Preserved divergent name from the shared Service ID SEP table (keyed by serviceId).
50+
// Preserved divergent name from the shared, serviceId-keyed table.
5151
String preserved = ServiceNamespaceTable.getByNormalizedKey(key);
5252
if (preserved != null) {
5353
return preserved;
5454
}
5555

56-
// SEP uniqueness guard: a sdkId-derived name must never collide with a preserved one.
56+
// Uniqueness guard: a sdkId-derived name must never collide with a preserved one.
5757
if (ServiceNamespaceTable.isReservedNamespace(sanitized)) {
5858
throw new IllegalStateException(String.format(
5959
"Derived namespace '%s' for serviceId '%s' collides with a reserved namespace in %s",

‎tools/code-generation/smithy/cpp-codegen/smithy-cpp-codegen/src/main/java/com/amazonaws/util/awsclientsmithygenerator/generators/ServiceNamespaceTable.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
import java.util.Map;
1717

1818
/**
19-
* Static, checked-in table preserving the C++ SDK service namespaces released before Revision 2
20-
* of the Service ID SEP (seps/accepted/shared/service-id.md) that diverge from the namespace
21-
* derived from the service's codegen id ("serviceId" == Smithy sdkId).
19+
* Static, checked-in table preserving the C++ SDK service namespaces that diverge from the
20+
* namespace derived from the service's {@code "serviceId"} (== Smithy sdkId), so previously
21+
* released names stay stable.
2222
*
2323
* <p>This loads the SAME shared data file as the C2J generator
2424
* ({@code tools/code-generation/shared/service-namespace-table.json}), the single source of truth.
25-
* The file is keyed by the exact, untransformed serviceId per the SEP. Because the Smithy
26-
* generator queries with a sanitized, lower-cased serviceId, this class builds a lookup index
27-
* keyed by {@code sanitizeServiceAbbreviation(serviceId).toLowerCase()} (the same normalization
25+
* The file is keyed by the exact, untransformed serviceId. Because the Smithy generator queries
26+
* with a sanitized, lower-cased serviceId, this class builds a lookup index keyed by
27+
* {@code sanitizeServiceAbbreviation(serviceId).toLowerCase()} (the same normalization
2828
* {@link ServiceNameUtil#getServiceName} applies). The stored values are frozen literals, never
29-
* derived from a docgen id, endpoint prefix, or model file name.
29+
* derived from the display-name fields, endpoint prefix, or model file name.
3030
*/
3131
public final class ServiceNamespaceTable {
3232

‎tools/code-generation/smithy/mapping/smithy-namespace-mapping.json‎

Lines changed: 0 additions & 147 deletions
This file was deleted.

‎tools/scripts/codegen/legacy_c2j_cpp_gen.py‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ def generate(self, executor: ProcessPoolExecutor, max_workers: int, args: dict)
153153
if len(failures):
154154
return -1
155155

156-
self._create_smithy_namespace_mapping(self.c2j_models)
157-
158156
print(f"Code generation done, (re)generated {len(done)} packages.") # Including defaults and partitions
159157

160158
return 0
@@ -376,20 +374,3 @@ def _generate_core_component(self,
376374
output_zip_file = self.run_generator_once(f"core/{component_name}", run_command, output_filename)
377375

378376
return self.extract_zip(output_zip_file, f"core/{component_name}", output_dir, None)
379-
380-
def _create_smithy_namespace_mapping(self, c2j_models: dict):
381-
mapping = {}
382-
for service, model_files in c2j_models.items():
383-
full_model_file_path = f"{self.path_to_api_definitions}/{model_files.c2j_model}"
384-
with open(full_model_file_path, 'r') as f:
385-
model = json.load(f)
386-
abbreviation = model.get("metadata", {}).get("serviceAbbreviation")
387-
if abbreviation:
388-
mapping[service] = abbreviation
389-
# add customization for s3-crt
390-
mapping["s3-crt"] = "S3Crt"
391-
output_path = f"{self.path_to_api_definitions}/../smithy/mapping/smithy-namespace-mapping.json"
392-
tmp_path = output_path + ".tmp"
393-
with open(tmp_path, 'w') as f:
394-
json.dump(mapping, f, indent=2)
395-
os.replace(tmp_path, output_path)

0 commit comments

Comments
 (0)