0

我对 Flask、Connexion 和 Swagger yaml 文件有疑问。我必须将路径定义为:/price/{code1}/{code2}.

在我的 yaml 文件中,我将根路径设置为:

paths:
  /price/{code1}/{code2}:
    get:
      operationId: lib.pack.test
      parameters:
      - in: path
        name: code1
        required: true
        type: string
        description: "code 1"
      - in: path
        name: code2
        reguired: true
        type: string
        description: "code 2"

当我执行时,server.py我收到此错误:

connexion.exceptions.InvalidSpecification: {'reguired': True, 'in': 'path', 'type': 'string', 'description': 'code 2', 'name': 'code'} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['get']['properties']['parameters']['items']:
    {'oneOf': [{'$ref': '#/definitions/parameter'},
               {'$ref': '#/definitions/jsonReference'}]}

On instance['paths']['/price/{code1}/{code2}']['get']['parameters'][1]:
    {'description': 'code 2',
     'in': 'path',
     'name': 'code2',
     'reguired': True,
     'type': 'string'}

如果我删除{code2}服务器正确启动。

  • 蟒蛇 2.7
  • 烧瓶 1.0.2
  • 连接 2.2.0

这是我的代码:

服务器.py

from flask import render_template
import connexion

# Create the application instance
app = connexion.App(__name__, specification_dir="configuration/")
app.add_api('swagger.yml')
app.run(port=5000, debug=True)


# Create a URL route in our application for "/"
@app.route('/')
def home():
    """
    This function just responds to the browser ULR
    localhost:5000/

    :return:        the rendered template 'home.html'
    """
    return render_template('home.html')


# If we're running in stand alone mode, run the application
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

这就是 Yaml

swagger: "2.0"
info:
  description: This is the swagger file that goes with our server code
  version: "1.0.0"
  title: Server crawler REST
consumes:
  - "application/json"
produces:
  - "application/json"

basePath: "/api"

paths:
  /avgprice/{code1}/{code2}:
    get:
      operationId: "lib.pack.test"
      tags:
        - "Avgprice"
      summary: "Avg price"
      description: "Calculator system to define AVG price from code1/code2"
      parameters:
        - in: path
          name: code1
          required: true
          type: string
        - in: path
          name: code2
          reguired: true
          type: string
      responses:
        200:
          description: "Successful"
          schema:
            type: "array"
            items:
              properties:
                id_code1:
                  type: "integer"
                code1:
                  type: "string"
                id_code2:
                  type: "integer"
                code2:
                  type: "string"
                price:
                  type: "integer"
4

1 回答 1

0

我找到了解决方案:)

我写错了 YAML 文件

- in: path
  name: code2
  **reguired: true** <-- required: true
  type: string
  description: "code 2"
于 2019-01-22T08:56:07.137 回答