Skip to content

Commit

Permalink
Remove moduleVersion configuration, correct package name declaration …
Browse files Browse the repository at this point in the history
…to support vN module version paths.
  • Loading branch information
skmcgrail committed May 6, 2021
1 parent 15d97b8 commit 44b6a8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ public final class GoSettings {
private static final String SERVICE = "service";
private static final String MODULE_NAME = "module";
private static final String MODULE_DESCRIPTION = "moduleDescription";
private static final String MODULE_VERSION = "moduleVersion";

private ShapeId service;
private String moduleName;
private String moduleVersion;
private String moduleDescription = "";
private ShapeId protocol;

Expand All @@ -50,11 +48,10 @@ public final class GoSettings {
*/
public static GoSettings from(ObjectNode config) {
GoSettings settings = new GoSettings();
config.warnIfAdditionalProperties(Arrays.asList(SERVICE, MODULE_NAME, MODULE_DESCRIPTION, MODULE_VERSION));
config.warnIfAdditionalProperties(Arrays.asList(SERVICE, MODULE_NAME, MODULE_DESCRIPTION));

settings.setService(config.expectStringMember(SERVICE).expectShapeId());
settings.setModuleName(config.expectStringMember(MODULE_NAME).getValue());
settings.setModuleVersion(config.expectStringMember(MODULE_VERSION).getValue());
settings.setModuleDescription(config.getStringMemberOrDefault(
MODULE_DESCRIPTION, settings.getModuleName() + " client"));

Expand Down Expand Up @@ -115,25 +112,6 @@ public void setModuleName(String moduleName) {
this.moduleName = Objects.requireNonNull(moduleName);
}

/**
* Gets the required module version for the module that will be generated.
*
* @return The version of the module that will be generated.
* @throws NullPointerException if the module version has not been set.
*/
public String getModuleVersion() {
return Objects.requireNonNull(moduleVersion, MODULE_VERSION + " not set");
}

/**
* Sets the required module version for the module that will be generated.
*
* @param moduleVersion The version of the module that will be generated.
*/
public void setModuleVersion(String moduleVersion) {
this.moduleVersion = Objects.requireNonNull(moduleVersion);
}

/**
* Gets the optional module description for the module that will be generated.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,22 @@ public String toString() {
String[] packageParts = fullPackageName.split("/");
String header = String.format("// Code generated by smithy-go-codegen DO NOT EDIT.%n%n");

String packageName = packageParts[packageParts.length - 1];
if (packageName.startsWith("v") && packageParts.length >= 2) {
String remaining = packageName.substring(1);
try {
int value = Integer.parseInt(remaining);
packageName = packageParts[packageParts.length - 2];
if (value == 0 || value == 1) {
throw new CodegenException("module paths vN version component must only be N >= 2");
}
} catch (NumberFormatException ne) {
// Do nothing
}
}

String packageDocs = this.packageDocs.toString();
String packageStatement = String.format("package %s%n%n", packageParts[packageParts.length - 1]);
String packageStatement = String.format("package %s%n%n", packageName);

String importString = imports.toString();
String strippedContents = StringUtils.stripStart(contents, null);
Expand Down

0 comments on commit 44b6a8a

Please sign in to comment.