GCP Cloud 端点门户未显示 swagger 中定义的 xml 定义

问题描述

在云端点门户(开发者门户)上显示 swagger 文件中定义的 xml 结构时出现问题,例如它没有显示定义的命名空间和示例,但在上传到 swagger 编辑器时可以正常工作

以下是声明的 xml 定义示例

MsgResp:
type: object
properties:
  Code:
    type: string
    example: RC_001_SUCCESS
  Message:
    type: string
    example: Message sent
xml:
  name: 'MessageResponse'
  wrapped: true
  namespace: http://MsgResponse

编辑:

Swagger 文件

# [START swagger]
swagger: '2.0'
info:
  title: <Endpoint-name>
  description: <Endpoint-name>
  version: 1.0.0
# Connects to the cloud run running the ESP Beta 2 image
host: <Endpoint-address> # CloudRun/Esp url
security: []
schemes:
  - https
paths:
  "/status":
    post:
      description: "Test API for sending  request from system 1 to IIP. "
      operationId: "status-api"
      # Defines which service it should connect to for backend processing,It can be Cloud function/ Cloud Run url
      x-google-backend:
        address: https://<Function1-address> # Backend Cloud function URL
        deadline: 3600.0
      # Defines Authentication mechanism to use,Following mentions to use API KEYS
      security:
      - api_key: []
      # MIME Types expected as request and response        
      produces:
      - "application/xml"     
      consumes:
      - "application/xml"
      parameters:
        - in: body
          name: schema
          description: Input Schema for /status
          schema:
            $ref: '#/deFinitions/InSchema'

      responses:
        200:
          description: OK
          schema:
            $ref: '#/deFinitions/MessageResponse'    
        404:
          description: Not Found
        500:
          description: Internal Service Error 
deFinitions:
  InSchema:        
    type: object
    xml:
      name: 'Identifier'
      prefix: 'msg'
      wrapped: true
      namespace: 'http://Identifier'    
    properties:
      Number:
        type: integer
      LogIdentifier:
        type: object
        properties:
          Code:
            type: integer
          Type:
            type: string            
        xml:
          name: 'LogicalIdentifier'
          wrapped: true
          namespace: http://LogicalIdentifier
          prefix: sample
    example:   # <----------
      Number: 38
      LogIdentifier:
        Code: 100
        Type: CDC
  MessageResponse:
    type: object
    properties:
      Code:
        type: string
        example: SUCCESS
      Message:
        type: string
        example: Message sent
# [START securityDef]
securityDeFinitions:
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"
# [END securityDef]

如在 swagger 编辑器上看到的那样

enter image description here

如云端点门户/应用程序门户所示

enter image description here

解决方法

根据 Cloud Run 上的 Cloud Endpoints Official Documentation,我只能看到示例中使用了 .json MimeType。

Cloud Endpoint 服务定义应基于 OpenAPI Specification v2.0,也称为 Swagger 2,它描述了后端服务的表面和任何身份验证要求。

因此在 GitHub 中检查 OpenAPI 规范 v2.0,我无法在 MimeType Section 中看到 xml 规范。但是在 Swagger Official Documentation 中,我可以看到 xml 媒体类型也受支持。

所以我想请您检查 Cloud Endpoint on Cloud Run Official Documentation 中提供的所有步骤。

在屏幕截图中,我可以看到 404 NOT_FOUND 错误,此错误在 Cloud Endpoints 的 Troubleshooting section 中提及,因此请查看。