- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 java Swagger-Codegen 类为公开固件发布服务的 Swagger Web Api 生成 c# 客户端。
public Byte[] LelFile
的属性 PackagePublishRequestInfoAndLel
需要 dto 类作为 public async Task<IHttpActionResult> PublishPackageAsync(...)
的参数 生成的客户端 DataContract 类中缺少 ApiController 方法。
我做错了什么吗?有什么特别的事情要做来处理Byte[]
特性 ?或者这是一个要在 Swagger-Codegen Github 项目中报告的问题?
注意 PackagePublishRequestInfo PackagePublishRequestInfoAndLel.PackagePublishRequestInfo
成员属性在客户端中正确公开,只有 Byte[] PackagePublishRequestInfoAndLel.LelFile
DataContract 类中缺少成员属性。
感谢您的帮助。
以下是一些代码摘录:
LelController (ApiController) 类公开了 public async Task<IHttpActionResult> PublishPackageAsync()
方法:(供引用)
/// <summary>
/// The lel ApiController handling lel file publication.
/// </summary>
[System.Web.Http.RoutePrefix("api/Lels")]
[GenerateFactory(typeof(ILelControllerFactory))]
public class LelController : ApiController,
ILelController
{
#region Fields
private readonly ILelRepository lelRepository; // Repository to access the Datasets in the RED Database
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="LelController"/> class.
/// </summary>
/// <param name="lelRepository">
/// The lel repository.
/// </param>
public LelController(ILelRepository lelRepository)
{
this.lelRepository = lelRepository;
}
#endregion
#region Public Methods and Operators
/// <summary>
/// Publishes a new firmware package.
/// </summary>
/// <param name="packagePublishRequestInfoAndLel">
/// The package publish info and the lel file content.
/// </param>
/// <returns>
/// The returned IHttpActionResult
/// </returns>
[System.Web.Http.Route("")]
[SwaggerResponse(HttpStatusCode.Created, "Package succesfully published.")]
[SwaggerResponse(HttpStatusCode.NotFound, "Unable to publish posted package data. (Detailed error message available in the response body).")]
[SwaggerResponse(HttpStatusCode.InternalServerError, "Internal server error. Package not published. An HttpException is returned with the original inner exception thrown. (Detailed error message available in the returned exception).", typeof(HttpException))]
public async Task<IHttpActionResult> PublishPackageAsync(PackagePublishRequestInfoAndLel packagePublishRequestInfoAndLel)
{
// Try to publish the package:
await this.lelRepository.PublishPackageAsync(packagePublishRequestInfoAndLel);
return this.Content(HttpStatusCode.Created, "Package successfully published.");
}
#endregion
}
PackagePublishRequestInfoAndLel
dto 类包括一个 byte[] LelFile
属性:
public class PackagePublishRequestInfoAndLel : IPackagePublishRequestInfoAndLel
{
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="PackagePublishRequestInfoAndLel"/> class.
/// </summary>
public PackagePublishRequestInfoAndLel()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="PackagePublishRequestInfoAndLel"/> class.
/// </summary>
/// <param name="packagePublishRequestInfo">
/// The package Publish Request Info.
/// </param>
/// <param name="lelFile">
/// The lel file.
/// </param>
public PackagePublishRequestInfoAndLel(PackagePublishRequestInfo packagePublishRequestInfo,
byte[] lelFile)
{
this.LelFile = lelFile;
this.PackagePublishRequestInfo = packagePublishRequestInfo;
}
#endregion
#region Public Properties
/// <summary>
/// Gets or sets the lel file
/// </summary>
[Required(AllowEmptyStrings = false, ErrorMessage = ValidationConstants.LelFileIsRequired)]
public byte[] LelFile { get; set; } // The LelFile property missing in the Swagger-Codegen generated client DataContract.
/// <summary>
/// Gets or sets the package publish request info
/// </summary>
public PackagePublishRequestInfo PackagePublishRequestInfo { get; set; }
#endregion
}
PackagePublishRequestInfoAndLel
Swagger JSon 中的定义:(正确地包括“Byte[]”类型的 LelFile 属性并格式化为“字符串”)
"PackagePublishRequestInfoAndLel": {
"required": [
"LelFile"
],
"type": "object",
"properties": {
"LelFile": {
"format": "string",
"type": "byte[]"
},
"PackagePublishRequestInfo": {
"$ref": "#/definitions/PackagePublishRequestInfo"
}
}
},
"PackagePublishRequestInfo": {
"required": [
"UserIdent"
],
"type": "object",
"properties": {
"Override": {
"type": "boolean"
},
"BootManagerVersion": {
"type": "string"
},
"BootloaderVersion": {
"type": "string"
},
"EcuIdent": {
"type": "string"
},
"HardwareVersion": {
"format": "int32",
"type": "integer"
},
"LelFileName": {
"pattern": "^[0-9]{8}_[0-9]{3}\\.lel$",
"type": "string"
},
"SoftwareVersion": {
"type": "string"
},
"SpfVersion": {
"type": "string"
},
"Status": {
"type": "string"
},
"UserIdent": {
"format": "int32",
"type": "integer"
},
"DatasetIdent": {
"type": "string"
},
"DatasetRevision": {
"format": "int32",
"type": "integer"
}
}
},
最后,不完整的 Swagger-Codegen 生成了客户端 DataContract:
namespace IO.Swagger.Model
{
[DataContract]
public class PackagePublishRequestInfoAndLel : IEquatable<PackagePublishRequestInfoAndLel>
{
[DataMember(EmitDefaultValue = false, Name = "PackagePublishRequestInfo")]
public PackagePublishRequestInfo PackagePublishRequestInfo { get; set; }
// Here, missing public Byte[] LelFile DataMember !!!
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("class PackagePublishRequestInfoAndLel {\n");
stringBuilder.Append(" PackagePublishRequestInfo: ").Append((object) this.PackagePublishRequestInfo).Append("\n");
stringBuilder.Append("}\n");
return ((object) stringBuilder).ToString();
}
public string ToJson()
{
return JsonConvert.SerializeObject((object) this, Formatting.Indented);
}
public override bool Equals(object obj)
{
return this.Equals(obj as PackagePublishRequestInfoAndLel);
}
public bool Equals(PackagePublishRequestInfoAndLel other)
{
if (other == null)
return false;
if (this.PackagePublishRequestInfo == other.PackagePublishRequestInfo)
return true;
if (this.PackagePublishRequestInfo != null)
return this.PackagePublishRequestInfo.Equals(other.PackagePublishRequestInfo);
else
return false;
}
public override int GetHashCode()
{
int num = 41;
if (this.PackagePublishRequestInfo != null)
num = num * 57 + this.PackagePublishRequestInfo.GetHashCode();
return num;
}
}
}
附录:
我猜问题可能出在 byte[] 类型的 Swashbuckle/Swagger 映射中。所以这是我的 SwaggerConfig 类代码:(byte[] 类型的映射可能是错误的...)
public class SwaggerConfig
{
#region Public Methods and Operators
/// <summary>
/// Register the configuration for Swashbuckle (Swagger .Net)
/// </summary>
/// <param name="config">
/// The global configuration
/// </param>
public static void Register(HttpConfiguration config)
{
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "RedFull.Api")
.Description(@"An API for accessing the Firmware Database services."
+ "(lel file publishing and firmware package retrieval)"
+ "<br /><br />Service events viewer is available on : <a href='/elmah.axd'>ELMAH</a> page")
.TermsOfService("Terms of service: Reserved for internal usage.")
.Contact(cc => cc
.Name("Firmware Services"
.Url("https://xxxxx.com/yyyy/Home.aspx")
.Email("xxx.yyy@gmail.com"))
.License(lc => lc
.Name("Usage License")
.Url("http://xxxxx.com/license"));
c.MapType<byte[]>(() => new Schema
{
type = "byte[]",
format = "string"
});
...
我也试过这样声明映射:
c.MapType<byte[]>(() => new Schema
{
type = "array",
format = "string",
items = new Schema()
{
type = "byte",
format = "int32"
}
});
但是这段代码在启动 swagger-codegen 生成器时导致异常:
Exception in thread "main" java.lang.RuntimeException: Could not generate model
'PackagePublishRequestInfoAndLel'
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:21
5)
at io.swagger.codegen.cmd.Generate.run(Generate.java:188)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: java.lang.NullPointerException
at io.swagger.codegen.languages.CSharpClientCodegen.getSwaggerType(CShar
pClientCodegen.java:246)
at io.swagger.codegen.DefaultCodegen.getTypeDeclaration(DefaultCodegen.j
ava:714)
at io.swagger.codegen.languages.CSharpClientCodegen.getTypeDeclaration(C
SharpClientCodegen.java:239)
at io.swagger.codegen.languages.CSharpClientCodegen.getTypeDeclaration(C
SharpClientCodegen.java:232)
at io.swagger.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:10
32)
at io.swagger.codegen.DefaultCodegen.addVars(DefaultCodegen.java:1868)
at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:845)
at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.ja
va:695)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:18
9)
... 2 more
最佳答案
binary
格式(映射到 C# API 客户端中的 byte[])在 Swagger-Codegen 的最新主控中得到支持它将包含在即将发布的稳定版本 2.1.6 中。
请暂时拉取最新的master,以获得C# API客户端对byte[]的支持。
关于c# - Swagger-codegen c# : Missing client member of type byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34852192/
我试图在我的微服务项目中生成一个单一的 swagger,在 Api 网关中将所有服务 swagger 聚合成一个单一的服务。为了实现这一点,我正在学习下一个教程 https://objectpartn
我的任务是将 Swagger 安装到 Web API 项目中。 已安装:来自 nuget 的最新版本的 Swashbuckle。 (Swashbuckle.Core.Net45 和 Swashbuck
我正在编写一个 swagger 规范,并且我有三个独立的端点。我如何在文档中将它们分开?我想明确区分示例:用户、帖子和其他。所以每个人都会有一个 CRUD 描述并显示在 swagger UI 中,它看
我试图在 Swagger 中定义一个查询参数,其中包含来自预定义项目集的逗号分隔字符串,例如 ?fruits=Apples,Oranges,Bananas但我从 swagger 编辑器收到以下错误 s
我正在使用 go-swagger 来生成 API 服务器。我注意到从 swagger.yml 生成的 json 被保存在 restapi/embedded_spec.go 中. 公开该 JSON 规范
我使用的是 springfox 版本 2.9.2 和 swagger 注释 1.5.x。 ApiModel 注释支持鉴别器、子类型和父属性,这些是使多态性工作所需的,但我没有看到生成的正确的 apid
我正在尝试使用本地 swagger.json 文件在 swagger 文档中显示。 我的 swagger.json 文件位于/home/user1/swagger-ui/dist/swagger.js
我们有一些数字字段,由于遗留原因,它们具有隐式长度限制。 给定一个长度限制为 5 的数字字段,显而易见的方法是将最大值设置为 99999,但是有没有办法在 swagger 规范中指定 1.111 可以
我们的项目为单个 API 使用多个 swagger 文件,但看起来 swagger-codegen 只接受一个。在这种情况下,我们如何使用 swagger-codegen 生成代码? 最佳答案 您可以
我正在尝试使用 https://github.com/swagger-api/swagger-codegen 生成 nodejs 客户端 sdk这是我使用的命令 swagger-codegen gen
我定义了一个以 MyObject 作为参数的路径。 MyObject 具有猫和狗的属性。这些有默认值。 在 swagger-editor 中,该示例不显示默认值,但试用确实创建了一个具有正确默认值的
我最近从 Swashbuckle 过渡到 Swagger-Net .进行更改后我遇到的一个问题是,现在我无法调用需要在 Authorization header 中发送 token 的 API。下面是
正在使用 AspNetCore 为使用 IIS 托管的 Web 应用程序设置 swagger。 .json 页面加载并且似乎可以很好地接触所有 API,但是当导航到 {localhost}/swagg
我想将任何复杂的 swagger-API-document(swagger.json) 解析为 Java 对象。 可能是列表> 有哪些可用选项? 我正在尝试使用 io.swagger.parser.S
我要将我的 API 服务器集成到 Google Cloud Endpoints。 到目前为止,Google Cloud Endpoints 支持 swagger 2.0。 但是我的依赖项/库现在是 u
我是 swagger 的新手,发现有两个用于 swagger 注释的包:io.swagger.annotations 和 com.wordnik.swagger.annotations。我想知道它们之
好的,我有许多 io.swagger.models.Swagger 对象,我已将它们合并到一个新的 super Swagger 中。现在我想要 super html。我怎样才能得到这个?请注意,为了获
我们当前的部署模式要求我手动编写 swagger json 输出,该输出将由我公司使用的基于 Swagger 的 UI 使用。我希望我正在编写的 json 能够提供“默认”值来填充所有输入字段(包括
我有以下 HTTP 触发的 Azure 函数。我已经使用此链接为我的端点设置了 Swagger here .以下 API 需要一组查询字符串参数,即 "name"、"email"、"phone",因此
我正在努力让 Swagger 正确呈现我的 ServiceStack 服务。 我希望看到一个 UserId 字符串作为表单参数,一个 PrivateCustomer 对象作为主体参数,但是尽管 Use
我是一名优秀的程序员,十分优秀!