nswag
软件的总体思路令人惊奇。
这些家伙完全毁了它。
我现在真的在考虑删除它,原因如下:
过于复杂
有问题
记录极差的
不受欢迎
关于我的版本-"nswag@11.17.19"
。
我的服务应该传递一个复合结构(例如嵌套数组)-但在最新版本中,它会通过URL传递所有内容,这就是我的意思:
此外,它的最新版本不会生成输入类-例如我的API控制器有动作ImportEntries(ImportEntriesInput input)
nswag
不再生成输入类(我的意思是ImportEntriesInput
)-而是仅列出其所有成员:
例如比较
importEntries(input: ImportEntriesInput | null | undefined): Observable<VocabularyDto> {
使用
importEntries(entries: CrawlerEntryDto[] | null | undefined, vocabularyId: number | undefined, newVocabulary: boolean | undefined, typeId: number | undefined, name: string | null | undefined, notes: string | null | undefined): Observable<VocabularyDto | null> {
也许开发它的人觉得还可以,但是我会说这完全使整个方法过于复杂,并且太糟糕了。
我真的找不到涵盖此部分的文档。
有人知道如何解决这个问题吗?
此外,以下是它创建要通过URL传递的内容的地方:
importEntries(entries: CrawlerEntryDto[] | null | undefined, vocabularyId: number | undefined, newVocabulary: boolean | undefined, typeId: number | undefined, name: string | null | undefined, notes: string | null | undefined): Observable<VocabularyDto | null> {
let url_ = this.baseUrl + "/api/Import/ImportEntries?";
if (entries !== undefined)
entries && entries.forEach((item, index) => {
for (let attr in item)
url_ += "entries[" + index + "]." + attr + "=" + encodeURIComponent("" + item[attr]) + "&";
});
if (vocabularyId === null)
throw new Error("The parameter 'vocabularyId' cannot be null.");
else if (vocabularyId !== undefined)
url_ += "vocabularyId=" + encodeURIComponent("" + vocabularyId) + "&";
if (newVocabulary === null)
throw new Error("The parameter 'newVocabulary' cannot be null.");
else if (newVocabulary !== undefined)
url_ += "newVocabulary=" + encodeURIComponent("" + newVocabulary) + "&";
if (typeId === null)
throw new Error("The parameter 'typeId' cannot be null.");
else if (typeId !== undefined)
url_ += "typeId=" + encodeURIComponent("" + typeId) + "&";
if (name !== undefined)
url_ += "name=" + encodeURIComponent("" + name) + "&";
if (notes !== undefined)
url_ += "notes=" + encodeURIComponent("" + notes) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_ : any = {
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
"Content-Type": "application/json",
"Accept": "application/json",
'Authorization': 'Bearer ' + localStorage.getItem('token')
})
};
return this.http.request("post", url_, options_).flatMap((response_ : any) => {
return this.processImportEntries(response_);
}).catch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processImportEntries(<any>response_);
} catch (e) {
return <Observable<VocabularyDto | null>><any>Observable.throw(e);
}
} else
return <Observable<VocabularyDto | null>><any>Observable.throw(response_);
});
}
挺令人震惊的吗?
swaggerToTypeScriptClient
位来自配置:
"codeGenerators": {
"swaggerToTypeScriptClient": {
"className": "{controller}ServiceProxy",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 2.0,
"template": "Angular",
"promiseType": "Promise",
"httpClass": "HttpClient",
"dateTimeType": "MomentJS",
"nullValue": "Undefined",
"generateClientClasses": true,
"generateClientInterfaces": false,
"generateOptionalParameters": false,
"wrapDtoExceptions": false,
"wrapResponses": false,
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"useTransformOptionsMethod": false,
"useTransformResultMethod": false,
"generateDtoTypes": true,
"operationGenerationMode": "MultipleClientsFromPathSegments"
"markOptionalProperties": false,
"generateCloneMethod": true,
"typeStyle": "Class",
"extensionCode": "service.extensions.ts",
"generateDefaultValues": true,
"excludedTypeNames": [],
"handleReferences": false,
"generateConstructorInterface": true,
"importRequiredTypes": true,
"useGetBaseUrlMethod": false,
"baseUrlTokenName": "API_BASE_URL",
"injectionTokenType": "InjectionToken",
"output": "../src/shared/service-proxies/service-proxies.ts"
},
答案 0 :(得分:0)
这解决了我上面的帖子中提到的URL问题。
没有记录,但是为了使nswag
与ASP.NET Core一起正常工作,您应该将[FromBody]
属性应用于接受数据的每个操作
例如
public async Task<VocabularyDto> ImportEntries([FromBody] ImportEntriesInput input)