google-app-engine - 无法解析 Open API 或来自 openapiapp.yaml 的 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] 解析开放 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
解决方案
Swashbuckle.AspNetCore 现在支持 OpenApi 3,但它也向后兼容 Swagger v2,通过在 Configure 方法(Startup 类)中设置它:
app.UseSwagger(c =>
{
c.SerializeAsV2 = true;
});