无法从Openapiapp.yaml中解析Open API或Google服务配置规范

人气:1,314 发布:2022-10-16 标签: google-app-engine asp.net-web-api openapi google-cloud-endpoints

问题描述

我尝试严格遵循[本教程](https://cloud.google.com/community/tutorials/exposing-aspnet-webapi-using-dotnetcore-with-cloud-endpoints),但在尝试gcloud endpoints services deploy openapi.yaml时遇到以下错误:

错误:(gcloud.endpoint ts.services.ploy)无法从[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

推荐答案

Swashuckle.AspNetCore现在支持OpenApi 3,但它也具有与Swagger v2的向后兼容性,方法是在Configure方法(Startup类)中使用:

app.UseSwagger(c =>
                {
                    c.SerializeAsV2 = true;
                });

451