Swagger生成的API没有返回值

Swagger生成的API没有返回值,swagger,swagger-2.0,swagger-codegen,swagger-editor,Swagger,Swagger 2.0,Swagger Codegen,Swagger Editor,我使用的是swagger-codegen-3.0.0 如下图所示,API规范有响应200和400;但是,当生成addTeam()API时,它是使用返回类型“void”生成的 我想处理响应代码200和/或400。这是否意味着我已经在响应规范中明确定义了有效负载类型?有人能提供更多关于我的“回复”规范应该如何的细节吗 49 /team: 50 post:

我使用的是swagger-codegen-3.0.0

如下图所示,API规范有响应200和400;但是,当生成addTeam()API时,它是使用返回类型“void”生成的

我想处理响应代码200和/或400。这是否意味着我已经在响应规范中明确定义了有效负载类型?有人能提供更多关于我的“回复”规范应该如何的细节吗

 49   /team:
 50     post:                                                                                           
 51       summary: Add team                                                                           
 52       operationId: addTeam                                                                        
 53       requestBody:                                                                                  
 54         description: Team detail being added                                                      
 55         content:                                                                                    
 56           application/json:                                                                         
 57             schema:                                                                                 
 58               type: array                                                                           
 59               items:                                                                                
 60                 $ref: "#/components/schemas/addTeamPayload"                                                                           
 61       responses:                                                                                    
 62         200:                                                                                        
 63           description: Ok                                                                           
 64         400:                                                                                        
 65           description: Bad request                                                                  
 66       tags:                                                                                         
 67         - Team
java-jar swagger-codegen-cli-3.0.0.jar generate-i teamApiSpec.yaml-l java--附加属性jackson=true--工件id swagger java客户端api

此命令生成以下Java代码/API

/**
 * Add team
 * 
 * @param body Team detail being added (optional)
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body

 */
public void addTeam(List<AddTeamPayload> body) throws ApiException {
    addTeamWithHttpInfo(body);
}

/**
 * Add Team
 * 
 * @param body Team detail being added (optional)
 * @return ApiResponse&lt;Void&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body

 */
public ApiResponse<Void> addTeamWithHttpInfo(List<AddTeamPayload> body) throws ApiException {
    com.squareup.okhttp.Call call = addTeamValidateBeforeCall(body, null, null);
    return apiClient.execute(call);
}
/**
*添加团队
* 
*正在添加@param body团队详细信息(可选)
*@如果未能调用API,例如服务器错误或无法反序列化响应正文,则引发ApiException
*/
public void addTeam(列表主体)引发异常{
addTeamWithHttpInfo(正文);
}
/**
*添加团队
* 
*正在添加@param body团队详细信息(可选)
*@return-apirevoid
*@如果未能调用API,例如服务器错误或无法反序列化响应正文,则引发ApiException
*/
公共ApiResponse addTeamWithHttpInfo(列表正文)引发ApiException{
com.squareup.okhttp.Call Call=addTeamValidateBeforeCall(body,null,null);
返回apiClient.execute(调用);
}
另一个问题是,即使API规范中编程了400响应代码,当服务器返回400时,API仍会抛出异常,并且在处理过程中,返回代码的详细信息丢失。作为API的用户,我不知道返回了什么返回代码,也不知道服务器发送了什么返回响应消息


有人能对此发表评论吗?这很重要。如果我在API规范中遗漏了什么,请告诉我。

如果您的服务返回数据,您应该在响应中添加内容描述

  /team:
     post:                                                                                           
       summary: Add team                                                                           
       requestBody:                                                                                  
         description: Team detail being added                                                      
         content:                                                                                    
           application/json:                                                                         
             schema:                                                                                 
               type: array                                                                           
               items:
                 $ref: '#/components/schemas/addTeamPayLoad'
       responses:                                                                                    
         200:                                                                                        
           description: Ok
           content:
             '*/*':
              schema:
                type: object
         400:                                                                                        
           description: Bad request
           content:
             '*/*':
              schema:
                type: object
       tags:                                                                                         
         - Team

但是当我这么做的时候会发生什么呢,因为我已经尝试过了,但没有看到进步。当返回400时会发生什么?您是否为每个响应类型添加了一个内容部分?我认为问题更多地与Swagger Codegen有关,对于非2xx响应,您会得到一个包含字符串的异常,而不是与模式类型对应的对象。我已经解决了这个问题,继续前进。