2015-01-18 3 views
1

방금 ​​완료 한 마법사 (dropwizard.io) &을 방금 완성했습니다. 이 샘플 앱에 Swagger (swagger.io)를 통합하고 싶습니다. 내가 발견Dropwizard에 통합 된 Swagger

  • github.com/federecio/dropwizard-swagger-sample-app

생성 된 JSON은 매우 유사한 것으로 보인다

  • github.com/federecio/dropwizard-swagger, 그러나 나는 각각의 작업을보기 위해 REST 리소스를 확장 할 수 없다. 제가 바와 유일한 차이점은 자신감 통합의 예 코드 공식 드롭 마법사 예 반면 SERVER하여 여기 APPLICATION

    이미지 (i.stack.imgur.com/QzhPa.png)

    를 사용했다 제 접근법에서 잘못된 점을 제게 말해 줄 수 있습니까? 대단히 감사합니다. https://github.com/geoHeil/dropwizardSwaggerIntegrationNotWorking

    편집 :

    for api - docs { 
     
        "apiVersion": "0.0", 
     
        "swaggerVersion": "1.2", 
     
        "apis": [{ 
     
        "path": "/sample" 
     
        }, { 
     
        "path": "/hello-world", 
     
        "description": "Operations about greetings" 
     
        }] 
     
    } 
     
    
     
    
     
    for sample { 
     
        "apiVersion": "0.0", 
     
        "swaggerVersion": "1.2", 
     
        "basePath": "http://geoHeil.local:8080", 
     
        "resourcePath": "/sample", 
     
        "apis": [{ 
     
        "path": "/sample", 
     
        "operations": [{ 
     
         "method": "GET", 
     
         "summary": "Sample endpoint", 
     
         "notes": "", 
     
         "type": "void", 
     
         "nickname": "get", 
     
         "authorizations": {}, 
     
         "parameters": [] 
     
        }] 
     
        }, { 
     
        "path": "/sample/hello-with-path-param/{name}", 
     
        "operations": [{ 
     
         "method": "GET", 
     
         "summary": "Sample endpoint with path param", 
     
         "notes": "", 
     
         "type": "void", 
     
         "nickname": "getWithPathParam", 
     
         "authorizations": {}, 
     
         "parameters": [{ 
     
         "name": "name", 
     
         "required": true, 
     
         "type": "string", 
     
         "paramType": "path" 
     
         }] 
     
        }] 
     
        }, { 
     
        "path": "/sample/hello-with-query-param", 
     
        "operations": [{ 
     
         "method": "GET", 
     
         "summary": "Sample endpoint with query param", 
     
         "notes": "", 
     
         "type": "void", 
     
         "nickname": "getWithQueryParam", 
     
         "authorizations": {}, 
     
         "parameters": [{ 
     
         "name": "name", 
     
         "required": false, 
     
         "type": "string", 
     
         "paramType": "query" 
     
         }] 
     
        }] 
     
        }] 
     
    } 
     
    
     
    for hello - world { 
     
        "apiVersion": "0.0", 
     
        "swaggerVersion": "1.2", 
     
        "basePath": "http://geoHeil.local:8080", 
     
        "resourcePath": "/hello-world", 
     
        "apis": [{ 
     
        "path": "/hello-world", 
     
        "operations": [{ 
     
         "method": "GET", 
     
         "summary": "Greetings endpoint", 
     
         "notes": "", 
     
         "type": "void", 
     
         "nickname": "sayHello", 
     
         "authorizations": {}, 
     
         "parameters": [{ 
     
         "name": "name", 
     
         "required": false, 
     
         "items": { 
     
          "type": "string" 
     
         }, 
     
         "paramType": "query" 
     
         }] 
     
        }] 
     
        }] 
     
    }

  • +0

    어떤 swagger-ui 버전을 사용하십니까? swagger-ui.js 파일의 맨 위를 확인할 수 있습니다. – Ron

    +0

    사용하신 사람 : io.federecio dropwizard-자신감 0.5.2 사진 내가에 버전 정보를 찾을 수 없습니다 https://www.dropbox.com/s/bsvfpvahp3ari3r/Swagger_UI.png?dl=0 찾을 수 있습니다 js 파일의 맨 위. –

    +0

    하지만 JS 콘솔에서 UncaughtType 오류 같은 일부 오류가 나타납니다 –

    답변

    1

    나는 작업을 확장하지 않는 원인이 생성 된 JSON에서 명백한 아무것도 표시되지 않습니다 여기 내 접근 코드입니다.

    그러나 dropwizard-swagger 패키지와 함께 번들로 제공되는 swagger-ui는 약간 오래된 버전입니다. swagger-ui의 최신 버전을 사용해 보겠습니다.

    번들 된 swagger-ui와 충돌하는지 확실하지 않지만 기본적으로 https://github.com/swagger-api/swagger-ui을 복제하고 정적 콘텐츠에/dist 디렉토리를 복사해야합니다.

    또 다른 옵션은 swagger-ui를 로컬로 (테스트 목적으로 만) 실행하고 /dist/index.html을 열고/api-docs 디렉토리에서 지정하는 것입니다. 그러나 제대로 작동하려면 CORS - https://github.com/swagger-api/swagger-ui#cors-support을 사용하도록 설정해야합니다.

    편집 : 나는 당신이 JSON으로 질문을 편집 통지를하지 않았고, 그것을 읽기 쉽게 만든

    . GET/hello-world 작동에 문제가 있습니다. 쿼리 매개 변수로 문자열 배열을 받아 들일 것으로 보이지만 매개 변수의 정의에 "type": "array"이 없습니다. 메서드의 선언과 주석을 보지 않고 무엇이 원인인지를 말할 수는 없지만, 여러분이보아야 할 것은 이것입니다.

    https://github.com/swagger-api/swagger-samples/tree/master/java/java-dropwizard

    이 최소한의 종속성이 최신 자신감 코어 라이브러리를 사용

    +0

    방금 ​​본 정보를 기반으로 답변을 편집했습니다. – Ron

    3

    이제 사용할 수있는 자신감 사양 2.0 예제가있다. 참고로, Jackson의 버전은 dropwizard의 2.3.2에서 swagger의 2.4.2로 업데이트해야했습니다.

    관련 문제