Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions bin/configs/csharp-netcore-OpenAPIClient-unityWebRequest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# for .net Unity
generatorName: csharp-netcore
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
library: unityWebRequest
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
protected static final String RESTSHARP = "restsharp";
protected static final String HTTPCLIENT = "httpclient";
protected static final String GENERICHOST = "generichost";
protected static final String UNITY_WEB_REQUEST = "unityWebRequest";

// Project Variable, determined from target framework. Not intended to be user-settable.
protected static final String TARGET_FRAMEWORK_IDENTIFIER = "targetFrameworkIdentifier";
Expand Down Expand Up @@ -100,6 +101,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
protected boolean supportsRetry = Boolean.TRUE;
protected boolean supportsAsync = Boolean.TRUE;
protected boolean netStandard = Boolean.FALSE;
protected boolean supportsFileParameters = Boolean.TRUE;

protected boolean validatable = Boolean.TRUE;
protected Map<Character, String> regexModifiers;
Expand Down Expand Up @@ -325,6 +327,8 @@ public CSharpNetCoreClientCodegen() {
+ "(Experimental. Subject to breaking changes without notice.)");
supportedLibraries.put(HTTPCLIENT, "HttpClient (https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient) "
+ "(Experimental. Subject to breaking changes without notice.)");
supportedLibraries.put(UNITY_WEB_REQUEST, "UnityWebRequest (...) "
+ "(Experimental. Subject to breaking changes without notice.)");
supportedLibraries.put(RESTSHARP, "RestSharp (https://github.com/restsharp/RestSharp)");

CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "HTTP library template (sub-template) to use");
Expand Down Expand Up @@ -701,6 +705,10 @@ public void processOpts() {
setLibrary(HTTPCLIENT);
additionalProperties.put("useHttpClient", true);
needsUriBuilder = true;
} else if (UNITY_WEB_REQUEST.equals(getLibrary())) {
setLibrary(UNITY_WEB_REQUEST);
additionalProperties.put("useUnityWebRequest", true);
needsUriBuilder = true;
} else {
throw new RuntimeException("Invalid HTTP library " + getLibrary() + ". Only restsharp, httpclient, and generichost are supported.");
}
Expand Down Expand Up @@ -780,6 +788,7 @@ public void processOpts() {
syncBooleanProperty(additionalProperties, CodegenConstants.OPTIONAL_METHOD_ARGUMENT, this::setOptionalMethodArgumentFlag, optionalMethodArgumentFlag);
syncBooleanProperty(additionalProperties, CodegenConstants.NON_PUBLIC_API, this::setNonPublicApi, isNonPublicApi());
syncBooleanProperty(additionalProperties, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup, this.useOneOfDiscriminatorLookup);
syncBooleanProperty(additionalProperties, "supportsFileParameters", this::setSupportsFileParameters, this.supportsFileParameters);

final String testPackageName = testPackageName();
String packageFolder = sourceFolder + File.separator + packageName;
Expand Down Expand Up @@ -816,6 +825,20 @@ public void processOpts() {
addGenericHostSupportingFiles(clientPackageDir, packageFolder, excludeTests, testPackageFolder, testPackageName, modelPackageDir);
additionalProperties.put("apiDocPath", apiDocPath + File.separatorChar + "apis");
additionalProperties.put("modelDocPath", modelDocPath + File.separatorChar + "models");
} else if (UNITY_WEB_REQUEST.equals(getLibrary())) {
additionalProperties.put(CodegenConstants.VALIDATABLE, false);
setValidatable(false);
setSupportsRetry(false);
setSupportsAsync(true);
// Some consoles and tvOS do not support either Application.persistentDataPath or will refuse to
// compile/link if you even reference GetTempPath as well.
additionalProperties.put("supportsFileParameters", false);
Comment thread
iBicha marked this conversation as resolved.
setSupportsFileParameters(false);

addSupportingFiles(clientPackageDir, packageFolder, excludeTests, testPackageFolder, testPackageName, modelPackageDir, authPackageDir);

supportingFiles.add(new SupportingFile("ConnectionException.mustache", clientPackageDir, "ConnectionException.cs"));
supportingFiles.add(new SupportingFile("UnexpectedResponseException.mustache", clientPackageDir, "UnexpectedResponseException.cs"));
} else { //restsharp
addSupportingFiles(clientPackageDir, packageFolder, excludeTests, testPackageFolder, testPackageName, modelPackageDir, authPackageDir);
additionalProperties.put("apiDocPath", apiDocPath);
Expand Down Expand Up @@ -911,14 +934,24 @@ public void addSupportingFiles(final String clientPackageDir, final String packa
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));

supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln"));
supportingFiles.add(new SupportingFile("netcore_project.mustache", packageFolder, packageName + ".csproj"));
if (UNITY_WEB_REQUEST.equals(getLibrary())) {
supportingFiles.add(new SupportingFile("asmdef.mustache", packageFolder, packageName + ".asmdef"));
} else {
supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln"));
supportingFiles.add(new SupportingFile("netcore_project.mustache", packageFolder, packageName + ".csproj"));
}

if (Boolean.FALSE.equals(excludeTests.get())) {
supportingFiles.add(new SupportingFile("netcore_testproject.mustache", testPackageFolder, testPackageName + ".csproj"));
if (UNITY_WEB_REQUEST.equals(getLibrary())) {
supportingFiles.add(new SupportingFile("asmdef_test.mustache", testPackageFolder, testPackageName + ".asmdef"));
} else {
supportingFiles.add(new SupportingFile("netcore_testproject.mustache", testPackageFolder, testPackageName + ".csproj"));
}
}

supportingFiles.add(new SupportingFile("appveyor.mustache", "", "appveyor.yml"));
if (!UNITY_WEB_REQUEST.equals(getLibrary())) {
supportingFiles.add(new SupportingFile("appveyor.mustache", "", "appveyor.yml"));
}
supportingFiles.add(new SupportingFile("AbstractOpenAPISchema.mustache", modelPackageDir, "AbstractOpenAPISchema.cs"));
}

Expand Down Expand Up @@ -1048,6 +1081,10 @@ public void setSupportsAsync(Boolean supportsAsync) {
this.supportsAsync = supportsAsync;
}

public void setSupportsFileParameters(Boolean supportsFileParameters) {
this.supportsFileParameters = supportsFileParameters;
}

public void setSupportsRetry(Boolean supportsRetry) {
this.supportsRetry = supportsRetry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ namespace {{packageName}}.Client
/// </summary>
public Dictionary<string, string> FormParameters { get; set; }

{{#supportsFileParameters}}
/// <summary>
/// File parameters to be sent along with the request.
/// </summary>
public Multimap<string, Stream> FileParameters { get; set; }
{{/supportsFileParameters}}

/// <summary>
/// Cookies to be sent along with the request.
Expand Down Expand Up @@ -76,7 +78,9 @@ namespace {{packageName}}.Client
QueryParameters = new Multimap<string, string>();
HeaderParameters = new Multimap<string, string>();
FormParameters = new Dictionary<string, string>();
{{#supportsFileParameters}}
FileParameters = new Multimap<string, Stream>();
{{/supportsFileParameters}}
Cookies = new List<Cookie>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,17 @@ namespace {{packageName}}.{{apiPackage}}
{{#required}}
{{#isFile}}
{{#isArray}}
{{#supportsFileParameters}}
foreach (var file in {{paramName}})
{
localVarRequestOptions.FileParameters.Add("{{baseName}}", file);
}
{{/supportsFileParameters}}
{{/isArray}}
{{^isArray}}
{{#supportsFileParameters}}
localVarRequestOptions.FileParameters.Add("{{baseName}}", {{paramName}});
{{/supportsFileParameters}}
{{/isArray}}
{{/isFile}}
{{^isFile}}
Expand All @@ -379,13 +383,17 @@ namespace {{packageName}}.{{apiPackage}}
{
{{#isFile}}
{{#isArray}}
{{#supportsFileParameters}}
foreach (var file in {{paramName}})
{
localVarRequestOptions.FileParameters.Add("{{baseName}}", file);
}
{{/supportsFileParameters}}
{{/isArray}}
{{^isArray}}
{{#supportsFileParameters}}
localVarRequestOptions.FileParameters.Add("{{baseName}}", {{paramName}});
{{/supportsFileParameters}}
{{/isArray}}
{{/isFile}}
{{^isFile}}
Expand Down Expand Up @@ -602,13 +610,17 @@ namespace {{packageName}}.{{apiPackage}}
{{#required}}
{{#isFile}}
{{#isArray}}
{{#supportsFileParameters}}
foreach (var file in {{paramName}})
{
localVarRequestOptions.FileParameters.Add("{{baseName}}", file);
}
{{/supportsFileParameters}}
{{/isArray}}
{{^isArray}}
{{#supportsFileParameters}}
localVarRequestOptions.FileParameters.Add("{{baseName}}", {{paramName}});
{{/supportsFileParameters}}
{{/isArray}}
{{/isFile}}
{{^isFile}}
Expand All @@ -620,13 +632,17 @@ namespace {{packageName}}.{{apiPackage}}
{
{{#isFile}}
{{#isArray}}
{{#supportsFileParameters}}
foreach (var file in {{paramName}})
{
localVarRequestOptions.FileParameters.Add("{{baseName}}", file);
}
{{/supportsFileParameters}}
{{/isArray}}
{{^isArray}}
{{#supportsFileParameters}}
localVarRequestOptions.FileParameters.Add("{{baseName}}", {{paramName}});
{{/supportsFileParameters}}
{{/isArray}}
{{/isFile}}
{{^isFile}}
Expand Down
Loading