我正在開發一個提供交易列表的 API。我正在用 Java/Kotlin Spring 編寫它,但更喜歡將 golang 用于 CLI,因此我正在為其生成一個 golang 客戶端。該 API 在 Swagger UI 中運行良好。科特林 API:@GetMappingfun listTransactions() : ResponseEntity<List<Transaction>> { val transactions = ArrayList<Transaction>() transactionRepository.findAll().mapTo(transactions) { fromEntity(it) } return ResponseEntity.ok(transactions)}科特林對象:data class Transaction( val id: Long, val transactionDate: Date, // Java SQL date val postedDate: Date?, // Java SQL date val amount: BigDecimal, val category: Category, val merchant: Merchant, val merchantDescription: String?)Golang 客戶端對象:type Transaction struct { Id *int64 `json:"id,omitempty"` TransactionDate *time.Time `json:"transactionDate,omitempty"` PostedDate *time.Time `json:"postedDate,omitempty"` Amount *float32 `json:"amount,omitempty"` Category *Category `json:"category,omitempty"` Merchant *Merchant `json:"merchant,omitempty"` MerchantDescription *string `json:"merchantDescription,omitempty"`}所有這一切似乎都是正確的。但是,當我使用 OpenAPI 客戶端時,反序列化似乎無法正常工作:Error when calling `TransactionRouterApi.ListTransactions``: parsing time "\"2022-10-28\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse "\"" as "T"Response from `TransactionRouterApi.ListTransactions`: [{0x140000aa218 0001-01-01 00:00:00 +0000 UTC <nil> <nil> <nil> <nil> <nil>}]我是否做錯了什么導致反序列化失???或者這是一個客戶端錯誤(似乎值得懷疑,但誰知道呢)。我查看了我使用的生成參數和端點上可用的模式,它們看起來都是正確的。執行的腳本:openapi-generator-cli generate -g go -i http://localhost:8080/v3/api-docs
- 1 回答
- 0 關注
- 114 瀏覽
添加回答
舉報
0/150
提交
取消