2016-10-25 12 views
0

私は以下のSpring Webサービスを持っています。 JSON for swaggerSpring Rest Webサービスの返却415

{ 
"swagger": "2.0", 
"info": { 
    "version": "1.0.0", 
    "title": "Extended User Management API", 
    "description": "This is communicate with an extended user management webservice to test the swagger API for learning" 
}, 
"schemes": [ 
    "http" 
], 
"basePath": "/UserManagement/rest/UserService", 
"host": "127.0.0.1:8089", 
"produces": [ 
    "application/json" 
], 
"consumes": [ 
    "application/json" 
], 
"paths": { 
    "/users": { 
     "get": { 
      "responses": { 
       "200": { 
        "description": "An array of users", 
        "schema": { 
         "type": "array", 
         "items": { 
          "$ref": "#/definitions/User" 
         } 
        } 
       }, 
       "default": { 
        "description": "Unexpected error", 
        "schema": { 
         "$ref": "#/definitions/Error" 
        } 
       } 
      } 
     } 
    }, 
    "/addUser": { 
     "post": { 
      "summary": "Add an additional user", 
      "description": "This service is used to add and additional user to the list of users.", 
      "parameters": [ 
       { 
        "name": "user_id", 
        "in": "query", 
        "description": "Unique id of the user to be added.", 
        "required": true, 
        "type": "integer", 
        "format": "int32" 
       }, 
       { 
        "name": "name", 
        "in": "query", 
        "description": "Name of the user to be added.", 
        "required": true, 
        "type": "string" 
       }, 
       { 
        "name": "profession", 
        "in": "query", 
        "description": "Profession of the user to be added.", 
        "required": true, 
        "type": "string" 
       } 
      ], 
      "responses": { 
       "200": { 
        "description": "OK" 
       }, 
       "default": { 
        "description": "Unexpected error", 
        "schema": { 
         "$ref": "#/definitions/Error" 
        } 
       } 
      } 
     } 
    } 
}, 
"definitions": { 
    "User": { 
     "type": "object", 
     "properties": { 
      "user_id": { 
       "type": "integer", 
       "format": "int32", 
       "description": "This is unique id that is assigned to each user." 
      }, 
      "name": { 
       "type": "string", 
       "description": "This is the name of the user" 
      }, 
      "profession": { 
       "type": "string", 
       "description": "This is the profession that the user holds" 
      } 
     } 
    }, 
    "Error": { 
     "type": "object", 
     "properties": { 
      "code": { 
       "type": "integer", 
       "format": "int32" 
      }, 
      "message": { 
       "type": "string" 
      }, 
      "fields": { 
       "type": "string" 
      } 
     } 
    } 
} 
} 

私はコードを生成し、プロジェクトのすべてのエラーを解決しました。私は、Spring boot mainで実行するアプリケーションを問題なく出しました。私が今直面している問題は、Webサービス "/ users"を入手する際に、サービスからエラーが出ることです。 Error produced

私はスプリングアプリケーションをデバッグしようとしましたが、意図したサービスがヒットしていないことがわかりました。サービスのコードを以下に示します。 javax.annotation.Generated @(値= "クラスio.swagger.codegen.languages.SpringCodegen" は、日付= "2016-10-24T09:36:32.738Z")は、このインタフェースの

@Api(value = "users", description = "the users API") 
public interface UsersApi { 

@ApiOperation(value = "", notes = "", response = User.class, responseContainer = "List", tags={ }) 
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "An array of users", response = User.class), 
    @ApiResponse(code = 200, message = "Unexpected error", response = User.class) }) 
@RequestMapping(value = "/users", 
    produces = { "application/json" }, 
    consumes = { "application/json" }, 
    method = RequestMethod.GET) 
ResponseEntity<List<User>> usersGet(); 

} 

実装であります以下の通りです

@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringCodegen", date = "2016-10-24T09:36:32.738Z") 
@Controller 
public class UsersApiController implements UsersApi { 

UserDao udao = new UserDao(); 

public ResponseEntity<List<User>> usersGet() { 
    return new ResponseEntity<List<User>>(udao.getAllUsers(), HttpStatus.OK); 
} 
} 

私がこれを解決できるように私が作った間違いを教えてください。

答えて

1

例外として、サポートされていないメディアタイプを使用しています。 はあなたの@RequestMapping注釈を見てください:

@RequestMapping(value = "/users", 
produces = { "application/json" }, 
consumes = { "application/json" }, 
method = RequestMethod.GET) 
ResponseEntity<List<User>> usersGet(); 

キー消費を削除するか、あなたのGETリクエストでのContent-Typeをサポートするのどちらか。

編集:おそらく、消費キーを削除する方が良い方法でしょう。私は、GETリクエストでjsonを消費するのは良い考えではないと思います。

関連する問題