All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.smithy.build.transforms.IncludeServices Maven / Gradle / Ivy

/*
 * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package software.amazon.smithy.build.transforms;

import java.util.Collections;
import java.util.Set;
import software.amazon.smithy.build.TransformContext;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.transform.ModelTransformer;

/**
 * {@code includeServices} filters out service shapes that are not
 * included in the list of shape IDs contained in the
 * {@code services} property.
 */
public final class IncludeServices extends BackwardCompatHelper {

    /**
     * {@code includeServices} configuration.
     */
    public static final class Config {
        private Set services = Collections.emptySet();

        /**
         * @return Gets the list of service shapes IDs to include.
         */
        public Set getServices() {
            return services;
        }

        /**
         * Sets the list of service shapes IDs to include.
         *
         * @param services Services to include by shape ID.
         */
        public void setServices(Set services) {
            this.services = services;
        }
    }

    @Override
    public Class getConfigType() {
        return Config.class;
    }

    @Override
    public String getName() {
        return "includeServices";
    }

    @Override
    String getBackwardCompatibleNameMapping() {
        return "services";
    }

    @Override
    protected Model transformWithConfig(TransformContext context, Config config) {
        Set services = config.getServices();
        Model model = context.getModel();
        ModelTransformer transformer = context.getTransformer();
        return transformer.filterShapes(model, shape -> !shape.isServiceShape() || services.contains(shape.getId()));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy