【发布时间】:2020-07-05 13:56:24
【问题描述】:
我有例如 swagger.yaml 文件,我想从中读取一些变量。 例如那个文件:https://editor.swagger.io/
下面是文件片段。 有可能得到例如。 “参数”的值?最好将它们分配给一些变量。
paths:
/pet:
post:
tags:
- "pet"
summary: "Add a new pet to the store"
description: ""
operationId: "addPet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
responses:
405:
description: "Invalid input"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
我有那个代码:
import yaml
path_to_yaml = '../data/swagger.yaml'
with open(path_to_yaml) as f:
dataMap = yaml.safe_load(f)
print(yaml.dump(dataMap, default_flow_style=False))
【问题讨论】:
标签: python python-3.x yaml pyyaml