forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[csharp][httpclient] Introduce FileParameter as an abstraction (OpenA…
…PITools#9426) * Introduce FileParameter as an abstraction * Update Samples * Add new file to samples * Fix hardcoded package name * Fix hardcoded package name, import FileParameter in Model * Remove unneccesary warning
- Loading branch information
1 parent
1a8438b
commit 98de404
Showing
88 changed files
with
356 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...i-generator/src/main/resources/csharp-netcore/libraries/httpclient/FileParameter.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{{>partial_header}} | ||
|
||
using System.IO; | ||
|
||
namespace {{packageName}}.Client | ||
{ | ||
/// <summary> | ||
/// Represents a File passed to the API as a Parameter, allows using different backends for files | ||
/// </summary> | ||
public class FileParameter | ||
{ | ||
/// <summary> | ||
/// The filename | ||
/// </summary> | ||
public string Name { get; set; } = "no_name_provided"; | ||
|
||
/// <summary> | ||
/// The content of the file | ||
/// </summary> | ||
public Stream Content { get; set; } | ||
|
||
/// <summary> | ||
/// Construct a FileParameter just from the contents, will extract the filename from a filestream | ||
/// </summary> | ||
/// <param name="content"> The file content </param> | ||
public FileParameter(Stream content) | ||
{ | ||
if (content is FileStream fs) | ||
{ | ||
Name = fs.Name; | ||
} | ||
Content = content; | ||
} | ||
|
||
/// <summary> | ||
/// Construct a FileParameter from name and content | ||
/// </summary> | ||
/// <param name="filename">The filename</param> | ||
/// <param name="content">The file content</param> | ||
public FileParameter(string filename, Stream content) | ||
{ | ||
Name = filename; | ||
Content = content; | ||
} | ||
|
||
/// <summary> | ||
/// Implicit conversion of stream to file parameter. Useful for backwards compatibility. | ||
/// </summary> | ||
/// <param name="s">Stream to convert</param> | ||
/// <returns>FileParameter</returns> | ||
public static implicit operator FileParameter(Stream s) => new FileParameter(s); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...-generator/src/main/resources/csharp-netcore/libraries/httpclient/RequestOptions.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{{>partial_header}} | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
|
||
namespace {{packageName}}.Client | ||
{ | ||
/// <summary> | ||
/// A container for generalized request inputs. This type allows consumers to extend the request functionality | ||
/// by abstracting away from the default (built-in) request framework (e.g. RestSharp). | ||
/// </summary> | ||
public class RequestOptions | ||
{ | ||
/// <summary> | ||
/// Parameters to be bound to path parts of the Request's URL | ||
/// </summary> | ||
public Dictionary<String, String> PathParameters { get; set; } | ||
/// <summary> | ||
/// Query parameters to be applied to the request. | ||
/// Keys may have 1 or more values associated. | ||
/// </summary> | ||
public Multimap<String, String> QueryParameters { get; set; } | ||
/// <summary> | ||
/// Header parameters to be applied to to the request. | ||
/// Keys may have 1 or more values associated. | ||
/// </summary> | ||
public Multimap<String, String> HeaderParameters { get; set; } | ||
/// <summary> | ||
/// Form parameters to be sent along with the request. | ||
/// </summary> | ||
public Dictionary<String, String> FormParameters { get; set; } | ||
/// <summary> | ||
/// File parameters to be sent along with the request. | ||
/// </summary> | ||
public Dictionary<String, FileParameter> FileParameters { get; set; } | ||
/// <summary> | ||
/// Cookies to be sent along with the request. | ||
/// </summary> | ||
public List<Cookie> Cookies { get; set; } | ||
/// <summary> | ||
/// Any data associated with a request body. | ||
/// </summary> | ||
public Object Data { get; set; } | ||
/// <summary> | ||
/// Constructs a new instance of <see cref="RequestOptions"/> | ||
/// </summary> | ||
public RequestOptions() | ||
{ | ||
PathParameters = new Dictionary<string, string>(); | ||
QueryParameters = new Multimap<string, string>(); | ||
HeaderParameters = new Multimap<string, string>(); | ||
FormParameters = new Dictionary<string, string>(); | ||
FileParameters = new Dictionary<String, FileParameter>(); | ||
Cookies = new List<Cookie>(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...s/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/model.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{{>partial_header}} | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.IO; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Linq; | ||
{{#models}} | ||
{{#model}} | ||
{{#discriminator}} | ||
using JsonSubTypes; | ||
{{/discriminator}} | ||
{{/model}} | ||
{{/models}} | ||
{{#validatable}} | ||
using System.ComponentModel.DataAnnotations; | ||
{{/validatable}} | ||
using FileParameter = {{packageName}}.Client.FileParameter; | ||
using OpenAPIDateConverter = {{packageName}}.Client.OpenAPIDateConverter; | ||
{{#useCompareNetObjects}} | ||
using OpenAPIClientUtils = {{packageName}}.Client.ClientUtils; | ||
{{/useCompareNetObjects}} | ||
{{#models}} | ||
{{#model}} | ||
{{#oneOf}} | ||
{{#-first}} | ||
using System.Reflection; | ||
{{/-first}} | ||
{{/oneOf}} | ||
{{#aneOf}} | ||
{{#-first}} | ||
using System.Reflection; | ||
{{/-first}} | ||
{{/aneOf}} | ||
|
||
namespace {{packageName}}.{{modelPackage}} | ||
{ | ||
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{#anyOf}}{{#-first}}{{>modelAnyOf}}{{/-first}}{{/anyOf}}{{^oneOf}}{{^anyOf}}{{>modelGeneric}}{{/anyOf}}{{/oneOf}}{{/isEnum}} | ||
{{/model}} | ||
{{/models}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.