我正在尝试通过从 Swagger 导入来创建新的 APIGateway,但出现验证错误:
导致问题的特定类是我们的 PaginationModel 类。
代码模型定义:
public class PaginationModel<T>
{
public IEnumerable<T> items { get; set; }
public int offset { get; set; }
public int totalCount { get; set; }
}
Swagger 文件部分表示特定类型的通用分页模型:
*"PaginationModel[DepartmentUIModel]":{"type":"object","properties":{"items": {"type":"array","items":{"$ref":"#/definitions/DepartmentUIModel"}},"offset": {"format":"int32","type":"integer"},"totalCount":{"format":"int32","type":"integer"}}}*
将 Swagger 文件导入 Amazon API Gateway 时出错:
无法为“PaginationModel[DepartmentUIModel]”创建模型:模型名称必须是字母数字:PaginationModel[DepartmentUIModel]
用 '<' 和 '{' 更改了 '[' 但没有解决问题。
除了为所有类型创建特定的分页模型之外,还有什么方法可以让 API Gateway 理解 Swagger 的这个特定输出?
最佳答案
fehguy 的回答对您更有帮助,但您从 API Gateway 获得的特定错误只是我们在 Swagger 规范中进行的额外验证。
Unable to create model for 'PaginationModel[DepartmentUIModel]': Model name must be alphanumeric: PaginationModel[DepartmentUIModel]
模型名称必须是字母数字,这意味着它们必须匹配正则表达式“[a-zA-Z0-9]+”
关于amazon-web-services - 从 Swagger 错误导入 Amazon API Gateway - 不采用泛型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37572531/