2014-11-18 3 views
1

내가 개발 한 Restable API에 대한 문서를 생성하기 위해 Swagger를 발견했지만, 플라스크를 사용하지 않을 때 플래쉬를 사용하지 않고 편안하게 플라스크를 사용하려고합니다.Flask만으로 Swagger 사용하기

from sqlalchemy.orm import create_session 
from flask import Flask, request, jsonify 
from Model import * 
from flask_restful import Api 
from flask_restful_swagger import swagger 

app = Flask(__name__) 
api = swagger.docs(Api(app), apiVersion='0.1', api_spec_url="/api/spec") 
session = create_session(bind=engine) 


@app.route('/employees/', methods=['GET']) 
@swagger.operation(
    parameters=[ 
     { 
     "name": "body", 
     "description": "Get the empployees in the shop.", 
     "required": True, 
     "allowMultiple": False, 
     "dataType": NsEmployee.__name__, 
     "paramType": "body" 
     } 
    ], 

    responseMessages=[ 
     { 
      "code": 201, 
      "message": "Created. The URL of the created blueprint should be in the Location header" 
     }, 
     { 
      "code": 405, 
      "message": "Invalid input" 
     } 
]) 

def employees(): 
    if request.method == 'GET': 
    # do something...   

    return jsonify(json_results) 


if __name__ == '__main__': 
    app.run(debug=True) 

을하지만 /api/spec/를 얻을 때 나는를 찾을 수 없음 을 구하십시오 -swagger가이 같은 예를 들어 뭔가를, 작동하지 않습니다 래퍼. 내 질문은 플라스크 - 안락한 - 스 저거의 사용을 피하고 플라스크와 함께 스 내거를 통합 할 수있는 방법이 있다는 것입니다.

도움을 주시면 감사하겠습니다.

답변

-1

그것은 내가 개인적으로 자신감 API를 작성하는 즉, 플라스크와 "자신감 우선"접근 방식을 사용하고

3

모두 (플라스크 - 편안하고 사용 등) MethodView 클래스와 바닐라 플라스크 방법을 지원 https://github.com/gangverk/flask-swagger

시도 (YAML)을 사용합니다. 이 접근법은 Connexion 라이브러리에 의해 매우 잘 지원됩니다. https://pypi.python.org/pypi/connexion (필자는 저자 중 한 명임)

Connexion은 플라스크 레포츠를 사용하지 않으며 Swagger 사양에 따라 "자동"유효성 검사 및 유형 매핑을 제공합니다.

관련 문제