将YAML定义转换为Python FLASK休息服务

时间:2015-08-20 11:45:55

标签: python flask yaml

有没有办法将YAML restful定义转换为Python Flask或任何其他Python restful服务代码?

示例YAML: -

basePath: /v2
paths:
  /pet/{petId}:
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet
      operationId: getPetById
      produces:
        - application/xml
        - application/json
      parameters:
        - name: petId
          in: path
          description: ID of pet to return
          required: true
          type: integer
          format: int64
      responses:
        '200':
          description: successful operation
          schema:
            db: 'pets'
        '400':
          description: Invalid ID supplied
        '404':
          description: Pet not found
      security:
        - api_key: []

这应该输出像这样的Python Flask实现

from flask import Flask
app = Flask(__name__)

@app.route("/v2/pet/")
def getpet(petId):
    return "Pet having petID"


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

0 个答案:

没有答案