如何解决无法从openapiapp.yaml解析Open API或Google服务配置规范
我尝试完全按照[本教程](https://cloud.google.com/community/tutorials/exposing-aspnet-webapi-using-dotnetcore-with-cloud-endpoints)进行操作,但是在尝试gcloud endpoints services deploy openapi.yaml
时出现以下错误:
错误:(gcloud.endpoints.services.deploy)无法从[SampleSolution]解析Open API或Google服务配置规范
openapi.yaml的正文:
openapi: 3.0.1
info:
title: Notes API
version: v1
host: [google cloud project ID].appspot.com
paths:
/WeatherForecast:
get:
tags:
- WeatherForecast
responses:
'200':
description: Success
content:
text/plain:
schema:
type: array
items:
$ref: '#/components/schemas/WeatherForecast'
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/WeatherForecast'
text/json:
schema:
type: array
items:
$ref: '#/components/schemas/WeatherForecast'
components:
schemas:
WeatherForecast:
type: object
properties:
date:
type: string
format: date-time
temperatureC:
type: integer
format: int32
temperatureF:
type: integer
format: int32
readOnly: true
summary:
type: string
nullable: true
additionalProperties: false
解决方法
我在那里只看到两件事:
-
openapi: 3.0.1
。这应该是Basic structure of an OpenAPI document的swagger: "2.0"
-
host: [google cloud project ID].appspot.com
。其中应包含正确的项目ID。
更新
在检查了文件和Endpoints openAPI文档的组成之后:
-
当前,Cloud Endpoints仅接受OpenAPI规范的版本2。
Swagger文档中的 -
The Components Section提到了适用于openAPI3的内容。这与第1点不兼容。
- 之后重新制作文件
Swashbuckle.AspNetCore现在支持OpenApi 3,但通过在Configure方法(启动类)中通过以下方式对其进行设置,它也与Swagger v2具有向后兼容性:
app.UseSwagger(c =>
{
c.SerializeAsV2 = true;
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。