Swagger POST 生成的参数体覆盖
Swagger POST generated parameter body override
我有一个示例对象,它被 swagger 引用以在我的文档中创建一个 POST 端点。
然后我使用文档生成客户端进行测试。但是,API 的工作方式与直接呈现对象的方式略有不同。我想将文档中创建的模型的 POST 主体参数类型从服务类型覆盖为字符串(服务的引用字符串)。我在下面包含了引用的对象。
@Entity
public class ServiceType {
private String id;
private Service service;
private String type;
public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
正文生成为:
{
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"service": {
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"name": "string",
"routingKey": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
},
"type": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
}
但我希望它采用以下格式:
{
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"service": "string",
"type": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
}
不确定这是否可行。感谢您的帮助。
您可以使用 @ApiModel
and @ApiModelProperty
annotations to override the default data type for a field. Note that the data type must be a fully-qualified type name (such as java.lang.String
). For more information, see Overriding Property Datatypes.
@Entity
@ApiModel
public class ServiceType {
private String id;
@ApiModelProperty(dataType = "java.lang.String")
private Service service;
private String type;
public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
我有一个示例对象,它被 swagger 引用以在我的文档中创建一个 POST 端点。
然后我使用文档生成客户端进行测试。但是,API 的工作方式与直接呈现对象的方式略有不同。我想将文档中创建的模型的 POST 主体参数类型从服务类型覆盖为字符串(服务的引用字符串)。我在下面包含了引用的对象。
@Entity
public class ServiceType {
private String id;
private Service service;
private String type;
public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
正文生成为:
{
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"service": {
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"name": "string",
"routingKey": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
},
"type": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
}
但我希望它采用以下格式:
{
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"service": "string",
"type": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
}
不确定这是否可行。感谢您的帮助。
您可以使用 @ApiModel
and @ApiModelProperty
annotations to override the default data type for a field. Note that the data type must be a fully-qualified type name (such as java.lang.String
). For more information, see Overriding Property Datatypes.
@Entity
@ApiModel
public class ServiceType {
private String id;
@ApiModelProperty(dataType = "java.lang.String")
private Service service;
private String type;
public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}