|
| 1 | +/* |
| 2 | + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.smithy.aws.typescript.codegen; |
| 17 | + |
| 18 | +import java.util.Map; |
| 19 | +import software.amazon.smithy.aws.traits.ServiceTrait; |
| 20 | +import software.amazon.smithy.build.PluginContext; |
| 21 | +import software.amazon.smithy.model.Model; |
| 22 | +import software.amazon.smithy.model.shapes.ServiceShape; |
| 23 | +import software.amazon.smithy.model.shapes.ShapeId; |
| 24 | +import software.amazon.smithy.model.shapes.ShapeType; |
| 25 | +import software.amazon.smithy.model.transform.ModelTransformer; |
| 26 | +import software.amazon.smithy.typescript.codegen.TypeScriptSettings; |
| 27 | +import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; |
| 28 | +import software.amazon.smithy.utils.MapUtils; |
| 29 | +import software.amazon.smithy.utils.SmithyInternalApi; |
| 30 | + |
| 31 | +/** |
| 32 | + * Add Nimble customization. |
| 33 | + */ |
| 34 | +@SmithyInternalApi |
| 35 | +public class AddNimbleCustomizations implements TypeScriptIntegration { |
| 36 | + |
| 37 | + @Override |
| 38 | + public Model preprocessModel(PluginContext context, TypeScriptSettings settings) { |
| 39 | + Model model = context.getModel(); |
| 40 | + ServiceShape service = settings.getService(model); |
| 41 | + String serviceId = service.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse(""); |
| 42 | + if (!serviceId.equals("nimble")) { |
| 43 | + return context.getModel(); |
| 44 | + } |
| 45 | + Map<ShapeId, ShapeType> overWriteTypeMap = MapUtils.of( |
| 46 | + ShapeId.from("com.amazonaws.nimble#StudioComponentConfiguration"), ShapeType.STRUCTURE); |
| 47 | + return ModelTransformer.create().changeShapeType(model, overWriteTypeMap); |
| 48 | + } |
| 49 | +} |
0 commit comments