Skip to content

Commit 8424bd8

Browse files
Use SDK ID to generate service name if available
1 parent b5d6443 commit 8424bd8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package software.amazon.smithy.python.aws.codegen;
6+
7+
import software.amazon.smithy.aws.traits.ServiceTrait;
8+
import software.amazon.smithy.codegen.core.Symbol;
9+
import software.amazon.smithy.codegen.core.SymbolProvider;
10+
import software.amazon.smithy.model.Model;
11+
import software.amazon.smithy.model.shapes.MemberShape;
12+
import software.amazon.smithy.model.shapes.Shape;
13+
import software.amazon.smithy.python.codegen.PythonSettings;
14+
import software.amazon.smithy.python.codegen.integrations.PythonIntegration;
15+
import software.amazon.smithy.utils.StringUtils;
16+
17+
public final class AwsServiceIdIntegration implements PythonIntegration {
18+
@Override
19+
public SymbolProvider decorateSymbolProvider(Model model, PythonSettings settings, SymbolProvider symbolProvider) {
20+
return new ServiceIdSymbolProvider(symbolProvider);
21+
}
22+
23+
private static class ServiceIdSymbolProvider implements SymbolProvider {
24+
25+
private final SymbolProvider delegate;
26+
27+
ServiceIdSymbolProvider(SymbolProvider delegate) {
28+
this.delegate = delegate;
29+
}
30+
31+
@Override
32+
public Symbol toSymbol(Shape shape) {
33+
Symbol symbol = this.delegate.toSymbol(shape);
34+
if (shape.isServiceShape() && shape.hasTrait(ServiceTrait.class)) {
35+
var serviceTrait = shape.expectTrait(ServiceTrait.class);
36+
var serviceName = StringUtils.capitalize(serviceTrait.getSdkId()).replace(" ", "");
37+
symbol = symbol.toBuilder().name(serviceName).build();
38+
}
39+
return symbol;
40+
}
41+
42+
@Override
43+
public String toMemberName(MemberShape shape) {
44+
return this.delegate.toMemberName(shape);
45+
}
46+
}
47+
}

codegen/aws/core/src/main/resources/META-INF/services/software.amazon.smithy.python.codegen.integrations.PythonIntegration

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
software.amazon.smithy.python.aws.codegen.AwsAuthIntegration
77
software.amazon.smithy.python.aws.codegen.AwsProtocolsIntegration
8+
software.amazon.smithy.python.aws.codegen.AwsServiceIdIntegration
89
software.amazon.smithy.python.aws.codegen.AwsUserAgentIntegration
910
software.amazon.smithy.python.aws.codegen.AwsStandardRegionalEndpointsIntegration

0 commit comments

Comments
 (0)