2014-11-20 2 views
7

최근에 만든 RESTful API가 있는데 몇 달 안에 사용하는 방법을 기억하지 못합니다. 나는 Swagger를 사용하여 API를 문서화하기로 결정했지만 미쳐 가고 있습니다.Swagger UI 2.1 스텁 "리소스 목록 가져 오기"

http://editor.swagger.io/을 사용하여 YAML 파일을 만든 다음 Swagger에서 사용할 수있는 JSON 파일로 변환했습니다. Swagger UI에 파일을 넣을 때 fetching resource list: localhost/swagger.json에 붙어서 콘솔에 Uncaught TypeError: Cannot read property '$ref' of undefined이라고 표시됩니다.

enter image description here enter image description here

나는 버전 자신감 UI의 2.1.0-alpha.5을 사용하고 있습니다.

여기 내 사양 파일 : 나는 당신의 스펙을 테스트 한

 
swagger: '2.0' 
info: 
    title: TITLE 
    description: BLAH, BLAH, BLAH, ETC 
    version: "1.0b" 
host: api.example.com 
schemes: 
- http 
basePath: /v1 
produces: 
- application/json 
paths: 
    /match.json: 
    get: 
    #summary: Match Data 
     description: Used for getting data about a match 
     parameters: 
     - name: id 
      in: query 
      description: The match ID of from a game 
      required: true 
      type: integer 
      format: int32 
     - name: key 
      in: query 
      description: API key used for authentication. 
      required: true 
      type: string 
     responses: 
     200: 
      description: Returns match data 
      schema: 
      type: array 
      items: 
       $ref: '#/definitions/MatchData' 
     default: 
      description: Unexpected error 
      schema: 
      $ref: '#/definitions/Error' 

definitions: 
    MatchData: 
    properties: 
     info: 
     type: integer 
     format: int64 
     description: General information about the match 
     time: 
     type: integer 
     format: int64 
     description: Information about the start/end time 
     stats: 
     type: array 
     format: int64 
     description: Stats about the match 
    Error: 
    required: 
    - errorID 
     - message 
    properties: 
     errorID: 
     type: string 
     description: Error ID. 
     message: 
     type: string 
     description: Information about the error. 
+0

어떻게 swagger.json를 호스팅하는 당신이 자신감-UI를 실행하려면 어떻게 – Ron

+0

@webron을 작동합니다은 "swagger.json"파일이 루트에 내 htdocs 디렉토리의 "dist"디렉토리와 루트의 이름도 바뀌 었습니다. 모든 것을 호스트하기 위해 xampp을 사용하고 있습니다. – kevc45

답변

5

, 나는 당신이 같은 오류를받지 못했습니다 동안, 사양은 참으로 유효하지 않습니다.

#/definitions/MatchData/properties/stats을 보면 type: array을 정의했음을 알게 될 것이지만 배열 옆에 '항목'속성을 지정하지 않아도됩니다 (필수 항목 임). format: int64과 함께 위의 속성과 같은 type: integer을 사용하려고했을 수 있습니다.

제공하려는 의도가 확실하지 않으므로 정확한 해결책을 제공하기가 어렵지만 원하는 내용으로 의견을 추가하면보다 자세한 답변을 제공 할 수 있습니다.

몇 가지 추가 테스트를 통해 UI에 버그가 있음을 발견했습니다. 수정 한 후 사양이로드 된 후 Expand Operations 링크를 클릭하지 않으면 작업 자체가 확장되지 않습니다. 그것에 대해 issue을 열었습니다. 거기에 따라 주시기 바랍니다.

+0

전체 사양을 처음부터 다시 작성한 것입니다. 섹션을 열지 못하게하는 버그. 도움을 주셔서 감사합니다. – kevc45

0

이 문제는 실제로 Swagger 편집기에 나타나지 않은 yaml 파일의 들여 쓰기 오류로 인해 발생할 수 있습니다. 모든 정의와 Swagger 편집기에서 볼 수있는 미리보기에서 예상대로 표시되는지 확인하십시오 (특히 MatchData 확인).

또한 제공 시도 할 수 있습니다 :

responses: 
200: 
    description: Returns match data 
    schema: 
    type: array 
    items: 
     schema: 
     $ref: '#/definitions/MatchData' 
0

을 우리의 경우, 우리는 자신감-PHP를 사용하고 우리는이 : * @SWG \ 응답 ( * 응답 = 200, 는 * 설명 = "응용 프로그램의 응답을 " * @SWG \ 스키마 ( * 유형 ="배열 * @SWG을 항목 \ (REF = "#/정의/애완 동물을") "" *) *),

하지만 우리는 놓쳤다 ". ? "@SWG \ 스키마 ("제거 후에는 예를 들어

*  @SWG\Response(
*   response=200, 
*   description="app response" 
* ),