英文:
Golang OpenAPI generator wraps query parameters into an object while the Java counterpart does not
问题
所以我正在使用openAPI在Golang和Java中生成API类。各个语言的生成器解释yml文件的方式似乎不同。
这是yml文件的一部分:
parameters:
- name: collectionName
schema:
type: string
- name: filter_by
in: query
schema:
type: string
required: true
- name: batch_size
in: query
required: true
schema:
type: integer
对于Golang生成器,生成了以下结构:
type DeleteDocumentsParams struct {
FilterBy string `json:"filter_by"`
BatchSize int `json:"batch_size"`
}
而对于Java,没有创建这样的类。然而,如果我将filter_by
和batch_size
参数包装在一个对象中,像这样:
parameters:
- name: collectionName
in: path
description: The name of the collection to delete documents from
required: true
schema:
type: string
- name: deleteQueryParams
in: query
schema:
type: object
properties:
filter_by:
type: string
batch_size:
type: integer
在Java中会创建一个DeleteQueryParams类。但是在Golang中,参数会被添加到一个嵌套结构中,像这样:
type DeleteDocumentsParams struct {
DeleteQueryParams *struct {
BatchSize *int `json:"batch_size,omitempty"`
FilterBy *string `json:"filter_by,omitempty"`
} `json:"deleteQueryParams,omitempty"`
}
长话短说,Golang生成器为我指定的查询参数添加了一层包装,而Java生成器没有。在这种情况下,是否可能实现统一性?或者,是否有任何标志可以用来启用或禁用参数的对象包装?
英文:
So I'm using openAPI to generate API classes in Golang and Java. The way the generators of the respective languages interpret the yml file seems to be different.
Here is a part of the yml file:
parameters:
- name: collectionName
schema:
type: string
- name: filter_by
in: query
schema:
type: string
required: true
- name: batch_size
in: query
required: true
schema:
type: integer
And the generator for Golang generated the following structure:
type DeleteDocumentsParams struct {
FilterBy string `json:"filter_by"`
BatchSize int `json:"batch_size"`
}
while for Java, no such class was created. However if I wrap the filter_by
and batch_size
parameters within an object like this
parameters:
- name: collectionName
in: path
description: The name of the collection to delete documents from
required: true
schema:
type: string
- name: deleteQueryParams
in: query
schema:
type: object
properties:
filter_by:
type: string
batch_size:
type: integer
A DeleteQueryParams class gets created in Java. But in Golang the parameters are added to a nested structure like this
type DeleteDocumentsParams struct {
DeleteQueryParams *struct {
BatchSize *int `json:"batch_size,omitempty"`
FilterBy *string `json:"filter_by,omitempty"`
} `json:"deleteQueryParams,omitempty"`
}
Long story short, the Golang generator adds a layer of wrapping for the query parameters I specify while the Java generator does not. Is it possible to achieve an uniformity in this case. Or, is there any flags that I can use to enable or disable the object wrapping of parameters?
专注分享java语言的经验与见解,让所有开发者获益!
评论