[英]Generic object names not being serialized when using openapi generator for a java client
我生成了一個 java 客戶端使用 openapi 生成版本 5.0.0 使用除 model 包等以外的所有默認值。
我讓它在像這樣的 swagger 編輯器中正確渲染。
此組件的特定 yaml 如下所示。
components:
schemas:
WorkItem:
properties:
workitems:
type: array
items:
properties:
json:
type: object
additionalProperties:
type: string
使用客戶端的示例代碼如下所示。
ApiKeyAuth ApiKeyAuth = (ApiKeyAuth) defaultClient.getAuthentication("ApiKeyAuth");
ApiKeyAuth.setApiKey(result.getToken());
WorkItem workItem = new WorkItem();
Map map = new HashMap();
map.put("test1", "test1");
map.put("test2", "test2");
map.put("test3", "test3");
workItem.addWorkitemsItem(map);
apiInstance.addWorkItem("3", "9", workItem);
然而,當我記錄信息時,它顯示請求正文中的有效負載看起來像這樣。
{"workitems":[{"test2":"test2","test3":"test3","test1":"test1"}]}
而不是上面 swagger 顯示的內容。 我期待它渲染出對象名稱。 在這種情況下,它是通用 map 而不是名為 object 的“json”。 在構建openapi的方式上我做錯了什么嗎?
如果我嘗試在不使用附加屬性的情況下使其更具體,在這種情況下,客戶端仍然會求助於使用通用 object。
解決方案是使用 singleton map 而不是常規的 map。
workItem.addWorkitemsItem(Collections.singletonMap("json", map));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.