简体   繁体   English

在python中使用refrence读取yaml文件

[英]Reading yaml file with refrence in python

demo.yaml演示文件

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

definitions.yaml File data definition.yaml文件数据

  name:
    type: string
    minLength: 10
    example: GANESH

I want to read yaml file with its refrence data.我想读取带有参考数据的 yaml 文件。

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

You can implement it using a custom constructor & yaml loader where you add an YAML instruction that will do the trick.您可以使用自定义构造函数和 yaml 加载程序来实现它,您可以在其中添加一条可以完成此操作的 YAML 指令。

Check https://davidchall.github.io/yaml-includes.html for example例如检查https://davidchall.github.io/yaml-includes.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM