在Swagger中使用JSON和YAML有什么实际区别? [英] What is the practical different between the usage of JSON and YAML in Swagger?

查看:309
本文介绍了在Swagger中使用JSON和YAML有什么实际区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎JSON包含路径信息和http请求动词,而YAML似乎仅定义了一个树结构.

It appears that JSON includes the path information and http request verb, whereas YAML seems to just definition a tree structure alone.

它们之间有什么区别?还是我在这里混淆了不同的概念/层次结构?新手大张旗鼓,刚刚开始学习.

What is the difference between them? Or am I mixing up different concepts/hierarchies here? newbie to swagger, just started learning.

如果YAML是JSON的超集,那么该超集具体要添加到这里-是URL路径和HTTP动词吗?添加example也是YAML添加到Swagger的JSON吗?

If YAML is a superset of JSON what specifically is the superset adding here - is it URL paths and HTTP verbs ? Is adding an example also something that YAML adds to JSON for Swagger ?

推荐答案

根据

符合OpenAPI规范的OpenAPI文档本身就是一个JSON对象,可以用JSON或YAML格式表示.

An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML format.

从功能上讲,使用JSON或YAML之间没有区别. YAML作为JSON的超集在这里添加的只是一种不同的语法.使用规范中的示例,这两个文档是相同的:

So feature-wise, there is no difference between using JSON or YAML. What YAML as a superset of JSON adds here is merely a different syntax. Using an example from the specification, these two documents are identical:

{
  "servers": [
    {
      "url": "https://development.gigantic-server.com/v1",
      "description": "Development server"
    },
    {
      "url": "https://staging.gigantic-server.com/v1",
      "description": "Staging server"
    },
    {
      "url": "https://api.gigantic-server.com/v1",
      "description": "Production server"
    }
  ]
}

servers:
- url: https://development.gigantic-server.com/v1
  description: Development server
- url: https://staging.gigantic-server.com/v1
  description: Staging server
- url: https://api.gigantic-server.com/v1
  description: Production server

第一个文档是有效的JSON和有效的YAML(因为YAML是JSON的超集).第二份文件是有效的YAML,其结构与第一份文件相同.

The first document is valid JSON and valid YAML (since YAML is a superset of JSON). The second document is valid YAML and structurally identical to the first document.

因此,要回答有关YAML超集在此处添加的问题:它添加了用于指定相同结构的不同语法.没什么.

So to answer the question about what the YAML superset adds here: It adds different syntax for specifying the same structures. Nothing more.

YAML确实包含一些无法映射到JSON的功能,但是在这里它们并不相关,因为Swagger/OpenAPI不使用它们.

这篇关于在Swagger中使用JSON和YAML有什么实际区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆