【发布时间】:2021-11-30 07:52:38
【问题描述】:
我正在尝试为网关 API 设置一个 yaml 文件以发布到云功能,但我不知道该怎么做,我在互联网上搜索并找到了一些示例,但是当我创建网关时使用我的 YAML 文件的设置出现以下错误:
我知道错误的原因可能是 YAML 文件缩进错误,但我无法解决它。
我的 YAML 文件配置如下:
swagger: '2.0'
info:
title: gateway-homologation gateway for homologation of the project cycle
description: "Send a deal object for the data to be treated"
version: "1.0.0"
schemes:
- https
produces:
- application/json
paths:
/dispatcher:
post:
x-google-backend:
address: https://url
description: "Jailson esteve aqui =)"
operationId: "dispatcher"
parameters:
type: object
properties:
request_type:
type: string
deal:
name:
type: string
responses:
200:
description: "#OK"
schema:
type: string
400:
description: "#OPS"
另一个问题是如何配置网关将发送到我的云功能的内容?
【问题讨论】:
-
错误消息很清楚,在
/paths/~1dispatcher/post/parameters,需要一个数组,但给出了一个对象。这不是 YAML 错误,而是架构错误——您必须给出架构定义的结构。将parameters的值设为数组将克服该错误,但我对 Swagger 的了解不够,无法确信这是您代码中的唯一错误。 -
@flyx,我明白你所说的,但我无法做到这一点。在实践中如何将对象变成数组?
-
the docs 有一些例子;
-开始一个序列项;序列项组成一个 YAML 序列,在 JavaScript 上下文中将作为数组加载。 -
@flyx ,您的 cmets 非常有帮助。为了社区的利益,您能否将它们发布为答案而不是评论?
-
@NestorDanielOrtegaPerez 我只发布 cmets,因为答案应该显示如何使给定数据有效,而我的 cmets 没有。我发布的链接指出参数没有
properties,因此在此修复后输入仍然无效,我不知道该怎么办。
标签: google-cloud-platform yaml api-gateway