【问题标题】:Reading yaml file with refrence in python在python中参考读取yaml文件
【发布时间】:2019-12-16 04:35:51
【问题描述】:

demo.yaml

content:
        application/json:
          schema:
            title: YamlTitle
            type: object
            properties:
              name:
                "$ref": "definitions.yaml#/name"
            required:
              - data

definitions.yaml 文件数据

  name:
    type: string
    minLength: 10
    example: GANESH

我想读取 yaml 文件及其参考数据。

输出 结果 = {'content': {'application/json': {'schema': {'title': 'YamlTitle', 'type': 'object', 'properties': {'name': {'type': 'string', 'minLength': 10, 'example': 'GANESH'}}, 'required': ['name']}}}}

【问题讨论】:

  • 查看OpenAPI Python parsers。他们可能会自动解析 $refs。
  • 它没有按预期工作。
  • 你能澄清一下究竟是什么按预期工作吗?你试过什么代码,得到了什么结果?
  • 其实我想要结果,因为输出结果用 swagger API v3 显示在上面。所以在 v3 [OpenAPI Python 解析器].(stackoverflow.com/questions/57097285/…) 中不起作用。
  • 感谢 Helen prance 库工作正常。

标签: python yaml


【解决方案1】:

您可以使用自定义构造函数和 yaml 加载器来实现它,您可以在其中添加一条 YAML 指令来解决问题。

https://davidchall.github.io/yaml-includes.html 为例

【讨论】:

  • 它不起作用,它以 JSON 格式打印相同的 YAML 数据
猜你喜欢
  • 2017-08-09
  • 2017-05-19
  • 2015-12-30
  • 1970-01-01
  • 1970-01-01
  • 2022-08-02
  • 2015-09-04
  • 2019-01-09
  • 1970-01-01
相关资源
最近更新 更多