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

software.amazon.smithy.build.model.TransformConfig Maven / Gradle / Ivy

Go to download

This module is a library used to validate Smithy models, create filtered projections of a model, and generate build artifacts.

There is a newer version: 1.54.0
Show newest version
/*
 * 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.model;

import java.util.function.Function;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.utils.SmithyBuilder;

/**
 * Transform configuration found in a projection.
 */
public final class TransformConfig {
    private final String name;
    private final ObjectNode args;

    private TransformConfig(Builder builder) {
        name = SmithyBuilder.requiredState("name", builder.name);
        args = builder.args;
    }

    public static TransformConfig fromNode(Node node) {
        TransformConfig.Builder builder = builder();
        node.expectObjectNode()
                .expectStringMember("name", builder::name)
                .getMember("args", Function.identity(), builder::args);
        return builder.build();
    }

    public static Builder builder() {
        return new Builder();
    }

    /**
     * @return The name of the projection.
     */
    public String getName() {
        return name;
    }

    /**
     * @return Gets the args.
     */
    public ObjectNode getArgs() {
        return args;
    }

    public static final class Builder implements SmithyBuilder {
        private String name;
        private ObjectNode args = Node.objectNode();

        private Builder() {}

        @Override
        public TransformConfig build() {
            return new TransformConfig(this);
        }

        /**
         * Sets the required name.
         *
         * @param name Name of the transform.
         * @return Returns the builder.
         */
        public Builder name(String name) {
            this.name = name;
            return this;
        }

        /**
         * Sets the args of the transform.
         *
         * 

If an array is provided, the array is automatically converted * to an object with a key named "__args" that contains the array. * This is a backward compatibility shim for older versions of * Smithy Builder that only accepts a list of strings for * projection transforms. * * @param args Arguments to set. * @return Returns the builder. */ public Builder args(Node args) { if (args.isArrayNode()) { this.args = Node.objectNode().withMember("__args", args); } else { this.args = args.expectObjectNode(); } return this; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy