首页 > 解决方案 > Swagger 文档位置不存在

问题描述

我一直在尝试部署我的谷歌云端点,但是我收到错误“位置不存在”?我似乎无法弄清楚我的 yaml 文件有什么问题,我一直在构建文档示例

我似乎没有从谷歌云控制台收到特定的错误消息,我的 yaml 文件看起来还好吗?抱歉,如果这看起来很模糊,这对我来说很新

打开-api-appengine.yaml

# [START swagger]
swagger: "2.0"
info:
  description: "" API Endpoint"
  title: "API Endpoint"
  version: "1.0.0"
host: "EXAMPLE"
# [END swagger]
consumes:
- "application/json"
produces:
- "application/json"
schemes:
- "https"
paths:
#/getallyield path
  "/getallyield":
    get:
      description: "return all arrays under yield"
      operationId: "allyield"
      produces:
      - "application/json"
      responses:
        200:
          description: "return all arrays under yield"
          schema:
            $ref: "#/definitions/allyield"
      security:
      - api_key: []
#/getyield{id} path
  "/gettotalyield/{date}":
    get:
      description: "Returns the requests' authentication information."
      operationId: "auth_info_google_jwt"
      parameters:
        - name: date
          in: path
          description: "date of total yield"
          required: true
          schema:
            type: string
            format: date
      produces:
      - "application/json"
      responses:
        200:
          description: "Authentication info."
          schema:
            $ref: "#/definitions/authInfoResponse"
      security:
      - api_key: []
  "/getyield/{id}":
    get:
      description: "Returns the requests' authentication information."
      operationId: "authInfoGoogleIdToken"
      parameters:
        - name: id
          in: path
          description: "id of requested document"
          required: true
          schema:
            type: integer
            format: int64
      produces:
      - "application/json"
      responses:
        200:
          description: "Authentication info."
          schema:
            $ref: "#/definitions/authInfoResponse"
      security:
      - api_key: []
  "/login":
    get:
      description: "Returns the requests' authentication information."
      operationId: "authInfoFirebase"
      produces:
      - "application/json"
      responses:
        200:
          description: "Authentication info."
          schema:
            $ref: "#/definitions/authInfoResponse"
      security:
      - api_key: []
########################################################################################################################################################################
definitions:
  echoMessage:
    type: "object"
    properties:
      message:
        type: "string"
  authInfoResponse:
    properties:
      id:
        type: "string"
      email:
        type: "string"
# [START securityDef]
securityDefinitions:
  # This section configures basic authentication with an API key.
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"
# [END securityDef]
  # This section configures authentication using Google API Service Accounts
  # to sign a json web token. This is mostly used for server-to-server
  # communication.
  google_jwt:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    # This must match the 'iss' field in the JWT.
    x-google-issuer: "jwt-client.endpoints.sample.google.com"
    # Update this with your service account's email address.
    x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL"
    # This must match the "aud" field in the JWT. You can add multiple audiences to accept JWTs from multiple clients.
    x-google-audiences: "echo.endpoints.sample.google.com"
  # This section configures authentication using Google App Engine default
  # service account to sign a json web token. This is mostly used for
  # server-to-server communication.
  gae_default_service_account:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    # Replace YOUR-CLIENT-PROJECT-ID with your client project ID.
    x-google-issuer: "YOUR-CLIENT-PROJECT-ID@appspot.gserviceaccount.com"
    # Replace YOUR-CLIENT-PROJECT-ID with your client project ID.
    x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/YOUR-CLIENT-PROJECT-ID@appspot.gserviceaccount.com"
    # This must match the "aud" field in the JWT. You can add multiple audiences to accept JWTs from multiple clients.
    x-google-audiences: "echo.endpoints.sample.google.com"
  # This section configures authentication using a service account
  # to sign a json web token. This is mostly used for server-to-server
  # communication.
  google_service_account:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    # Replace YOUR-SERVICE-ACCOUNT-EMAIL with your service account email.
    x-google-issuer: "YOUR-SERVICE-ACCOUNT-EMAIL"
    # Replace YOUR-SERVICE-ACCOUNT-EMAIL with your service account email.
    x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/YOUR-SERVICE-ACCOUNT-EMAIL"
    # This must match the "aud" field in the JWT. You can add multiple audiences to accept JWTs from multiple clients.
    x-google-audiences: "echo.endpoints.sample.google.com"
  # This section configures authentication using Google OAuth2 ID Tokens.
  # ID Tokens can be obtained using OAuth2 clients, and can be used to access
  # your API on behalf of a particular user.
  google_id_token:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    x-google-issuer: "https://accounts.google.com"
    x-google-jwks_uri: "https://www.googleapis.com/oauth2/v3/certs"
    # Your OAuth2 client's Client ID must be added here. You can add multiple client IDs to accept tokens form multiple clients.
    x-google-audiences: "YOUR-CLIENT-ID"
  # This section configures authentication using Firebase Auth.
  # [START firebaseAuth]
  firebase:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    x-google-issuer: "https://securetoken.google.com/YOUR-PROJECT-ID"
    x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
    x-google-audiences: "YOUR-PROJECT-ID"
  # [END firebaseAuth]

这是我从 GCP 控制台返回的错误

ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Cannot convert to service config.
'location: "unknown location"
kind: ERROR
message: "Invalid OpenAPI file. Please fix the schema errors:\nerror: instance failed to match exactly one schema (matched 0 out of 2)\n    level: \"error\"\n    schema: {\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/parametersList/items\"}\n    instance: {\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"}\n    domain: \"validation\"\n    keyword: \"oneOf\"\n    matched: 0\n    nrSchemas: 2\n    reports: {\"/definitions/parametersList/items/oneOf/0\":[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/parameter\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"oneOf\",\"message\":\"instance failed to match exactly one schema (matched 0 out of 2)\",\"matched\":0,\"nrSchemas\":2,\"reports\":{\"/definitions/parameter/oneOf/0\":[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/bodyParameter/properties/in\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0/in\"},\"domain\":\"validation\",\"keyword\":\"enum\",\"message\":\"instance value (\\\"path\\\") not found in enum (possible values: [\\\"body\\\"])\",\"value\":\"path\",\"enum\":[\"body\"]}],\"/definitions/parameter/oneOf/1\":[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/nonBodyParameter\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"oneOf\",\"message\":\"instance failed to match exactly one schema (matched 0 out of 4)\",\"matched\":0,\"nrSchemas\":4,\"reports\":{\"/definitions/nonBodyParameter/oneOf/0\":[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/headerParameterSubSchema\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"additionalProperties\",\"message\":\"object instance has properties which are not allowed by the schema: [\\\"schema\\\"]\",\"unwanted\":[\"schema\"]}],\"/definitions/nonBodyParameter/oneOf/1\":[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/formDataParameterSubSchema\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"additionalProperties\",\"message\":\"object instance has properties which are not allowed by the schema: [\\\"schema\\\"]\",\"unwanted\":[\"schema\"]}],\"/definitions/nonBodyParameter/oneOf/2\":[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/queryParameterSubSchema\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"additionalProperties\",\"message\":\"object instance has properties which are not allowed by the schema: [\\\"schema\\\"]\",\"unwanted\":[\"schema\"]}],\"/definitions/nonBodyParameter/oneOf/3\":[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/pathParameterSubSchema\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"additionalProperties\",\"message\":\"object instance has properties which are not allowed by the schema: [\\\"schema\\\"]\",\"unwanted\":[\"schema\"]}]}},{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/nonBodyParameter\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"required\",\"message\":\"object has missing required properties ([\\\"type\\\"])\",\"required\":[\"in\",\"name\",\"type\"],\"missing\":[\"type\"]}]}}],\"/definitions/parametersList/items/oneOf/1\":[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/jsonReference\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"additionalProperties\",\"message\":\"object instance has properties which are not allowed by the schema: [\\\"description\\\",\\\"in\\\",\\\"name\\\",\\\"required\\\",\\\"schema\\\"]\",\"unwanted\":[\"description\",\"in\",\"name\",\"required\",\"schema\"]},{\"level\":\"error\",\"schema\":{\"loadingURI\":\"http://swagger.io/v2/schema.json#\",\"pointer\":\"/definitions/jsonReference\"},\"instance\":{\"pointer\":\"/paths/~1gettotalyield~1{date}/get/parameters/0\"},\"domain\":\"validation\",\"keyword\":\"required\",\"message\":\"object has missing required properties ([\\\"$ref\\\"])\",\"required\":[\"$ref\"],\"missing\":[\"$ref\"]}]}"

我在 swagger editor.io 上运行了我的 yaml,似乎没有格式错误,我无法弄清楚我做错了什么?还为代码格式化程序如何处理错误消息表示歉意

标签: google-cloud-platformswaggergoogle-cloud-endpoints

解决方案


推荐阅读