我试图使用Flask RestPlus与IIS,但有问题,因为没有生成Swagger.json . 事实上,甚至无法控制Swagger UI,因为它为静态资产采用绝对基本服务器根URL .

能够至少访问URL:http://localhost/flask-demo/todo/api/v1.0/endpoint1/doc/,当我点击它时,我得到的消息为 Can't read swagger JSON from http://localhost/swagger.json

我可以看到API工作在: http://localhost/flask-demo/todo/api/v1.0/endpoint1

我还在https://github.com/noirbizarre/flask-restplus/pull/128跟随Pull Request来指定相对URL,但没有运气 .

这是代码 .

web.config

<configuration>
    <system.webServer>
        <modules>
            <remove name="WebDAVModule" />
        </modules>
        <handlers>
            <remove name="WebDAV" />
            <add name="Python FastCGI"
                        path="*"
                        verb="*"
                        modules="FastCgiModule"
                        scriptProcessor="C:\Python27\python.exe|C:\Python27\Lib\site-packages\wfastcgi.pyc"
                        resourceType="Unspecified"
                        requireAccess="Script" />
        </handlers>
    </system.webServer>
    <appSettings>
        <add key="WSGI_HANDLER" value="myapp.app" />
    </appSettings>
</configuration>

myapp.py

from flask import Flask
from endpoint1 import endpoint1

app = Flask(__name__)
app.register_blueprint(endpoint1)

if __name__ == "__main__":
    app.run()

endpoint1_backconnect.py

from flask import jsonify

'''
In memory JSON storage for REST APIs.
'''
tasks = [
    {
        'id': 1,
        'title': u'Buy groceries',
        'description': u'Milk, Cheese, Fruit', 
        'done': False
    },
    {
        'id': 2,
        'title': u'Learn Python',
        'description': u'Use material from YouTube', 
        'done': False
    }
]

def get_tasks():
    return jsonify({'tasks': tasks})

def create_task(json_object):
    task = {
        'id': tasks[-1]['id'] + 1,
        'title': json_object['title'],
        'description': json_object.get('description', ""),
        'done': False
    }
    tasks.append(task)
    return task

endpoint1.py

from flask import Blueprint, jsonify, request, abort
from flask_restplus import Api
import os
import config
import endpoint1_backconnect

CONTROLLER_PREFIX = config.API_PREFIX + os.path.splitext(os.path.basename(__file__))[0]
endpoint1 = Blueprint(os.path.splitext(os.path.basename(__file__))[0], __name__)
endpoint1_api = Api(endpoint1, doc = CONTROLLER_PREFIX + '/doc/', endpoint = CONTROLLER_PREFIX + '/doc/', specs_path = CONTROLLER_PREFIX + '/doc/swagger.json')

'''
Gets all tasks
'''
@endpoint1.route(CONTROLLER_PREFIX, methods=['GET'])
def get_tasks():
    return endpoint1_backconnect.get_tasks()

'''
Creates new task
'''
@endpoint1.route(CONTROLLER_PREFIX, methods=['POST'])
def create_task():
    if not request.json or not 'title' in request.json:
        abort(400)
    result = endpoint1_backconnect.create_task(request.json)
    return jsonify({'task': result}), 201