Skip to content

Commit

Permalink
Add PackageContainer interface (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase authored Jul 19, 2023
1 parent 96f362f commit 10ed5f2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 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.typescript.codegen;

/**
* A container for packages.
*/
public interface PackageContainer {
/**
* Gets the name of the contained package.
*
* @return Returns the name of the package.
*/
String getPackageName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* An enum of all of the built-in dependencies managed by this package.
*/
@SmithyUnstableApi
public enum TypeScriptDependency implements SymbolDependencyContainer {
public enum TypeScriptDependency implements PackageContainer, SymbolDependencyContainer {

AWS_SDK_CLIENT_DOCGEN("devDependencies", "@smithy/service-client-documentation-generator", "^1.0.1", true),
AWS_SDK_TYPES("dependencies", "@aws-sdk/types", true),
Expand Down Expand Up @@ -173,6 +173,11 @@ public List<SymbolDependency> getDependencies() {
return Collections.singletonList(dependency);
}

@Override
public String getPackageName() {
return this.packageName;
}

/**
* Creates a Symbol from the dependency of the enum, using the package
* name and version of the dependency and the provided {@code name}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public TypeScriptWriter addImport(String name, String as, String from) {
*
* @param name Type to import.
* @param as Alias to refer to the type as.
* @param from TypeScriptDependency to import the type from.
* @param from PackageContainer to import the type from.
* @return Returns the writer.
*/
public TypeScriptWriter addImport(String name, String as, TypeScriptDependency from) {
return this.addImport(name, as, from.packageName);
public TypeScriptWriter addImport(String name, String as, PackageContainer from) {
return this.addImport(name, as, from.getPackageName());
}

/**
Expand Down

0 comments on commit 10ed5f2

Please sign in to comment.