Skip to content

Commit

Permalink
allowing user to set client package (#13785)
Browse files Browse the repository at this point in the history
  • Loading branch information
devhl-labs authored Oct 21, 2022
1 parent a68c36e commit c0c31e8
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
private static FrameworkStrategy defaultFramework = FrameworkStrategy.NETSTANDARD_2_0;
protected final Map<String, String> frameworks;
protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
protected String clientPackage = "Org.OpenAPITools.Client";
protected String clientPackage = "Client";
protected String authFolder = "Auth";
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";
protected String apiDocPath = "docs" + File.separator;
protected String modelDocPath = "docs" + File.separator;

// Defines TargetFrameworkVersion in csproj files
protected String targetFramework = defaultFramework.name;
Expand Down Expand Up @@ -547,6 +547,7 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
postProcessPattern(property.pattern, property.vendorExtensions);
postProcessEmitDefaultValue(property.vendorExtensions);

// remove once https://github.com/OpenAPITools/openapi-generator/pull/13681 is merged
if (GENERICHOST.equals(getLibrary())) {
// all c# libraries should want this, but avoid breaking changes for now
// a class cannot contain a property with the same name
Expand Down Expand Up @@ -664,8 +665,6 @@ public void processOpts() {
setModelPackage("Model");
}

clientPackage = "Client";

if (GENERICHOST.equals(getLibrary())) {
setLibrary(GENERICHOST);
additionalProperties.put("useGenericHost", true);
Expand All @@ -679,7 +678,7 @@ public void processOpts() {
additionalProperties.put("useHttpClient", true);
needsUriBuilder = true;
} else {
throw new RuntimeException("Invalid HTTP library " + getLibrary() + ". Only restsharp, httpclient are supported.");
throw new RuntimeException("Invalid HTTP library " + getLibrary() + ". Only restsharp, httpclient, and generichost are supported.");
}

String inputFramework = (String) additionalProperties.getOrDefault(CodegenConstants.DOTNET_FRAMEWORK, defaultFramework.name);
Expand Down Expand Up @@ -742,7 +741,7 @@ public void processOpts() {
final AtomicReference<Boolean> excludeTests = new AtomicReference<>();
syncBooleanProperty(additionalProperties, CodegenConstants.EXCLUDE_TESTS, excludeTests::set, false);

syncStringProperty(additionalProperties, "clientPackage", (s) -> { }, clientPackage);
syncStringProperty(additionalProperties, "clientPackage", this::setClientPackage, clientPackage);

syncStringProperty(additionalProperties, CodegenConstants.API_PACKAGE, this::setApiPackage, apiPackage);
syncStringProperty(additionalProperties, CodegenConstants.MODEL_PACKAGE, this::setModelPackage, modelPackage);
Expand Down Expand Up @@ -809,6 +808,10 @@ public void processOpts() {
addTestInstructions();
}

public void setClientPackage(String clientPackage) {
this.clientPackage = clientPackage;
}

@Override
public CodegenOperation fromOperation(String path,
String httpMethod,
Expand Down

0 comments on commit c0c31e8

Please sign in to comment.