Skip to content

swagger generate client command fails with invalid token reference #1898

@bigflood

Description

@bigflood

Problem statement

swagger generate client fails on a valid swagger.json.
error message is

some references could not be resolved in spec. First found: invalid token reference "v2EventMsg"

The reference is "$ref": "#/x-stream-definitions/v2EventMsg"
but, it succeeds without error if I change #/x-stream-definitions/v2EventMsg to ./example.swagger.json#/x-stream-definitions/v2EventMsg

Swagger specification

{
  "swagger": "2.0",
  "info": {
    "title": "example.proto",
    "version": "version not set"
  },
  "schemes": [
    "http",
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/example/v2/GetEvents": {
      "get": {
        "operationId": "GetEvents",
        "responses": {
          "200": {
            "description": "A successful response.(streaming responses)",
            "schema": {
              "$ref": "#/x-stream-definitions/v2EventMsg"
            }
          }
        },
        "parameters": [
          {
            "name": "afterEventID",
            "description": ".",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": [
          "Matchmaking"
        ]
      }
    }
  },
  "definitions": {
    "protobufAny": {
      "type": "object",
      "properties": {
        "type_url": {
          "type": "string"
        },
        "value": {
          "type": "string",
          "format": "byte"
        }
      }
    },
    "runtimeStreamError": {
      "type": "object",
      "properties": {
        "grpc_code": {
          "type": "integer",
          "format": "int32"
        },
        "http_code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "http_status": {
          "type": "string"
        },
        "details": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/protobufAny"
          }
        }
      }
    },
    "v2EventMsg": {
      "type": "object",
      "properties": {
        "eventID": {
          "type": "string"
        }
      }
    }
  },
  "x-stream-definitions": {
    "v2EventMsg": {
      "type": "object",
      "properties": {
        "result": {
          "$ref": "#/definitions/v2EventMsg"
        },
        "error": {
          "$ref": "#/definitions/runtimeStreamError"
        }
      },
      "title": "Stream result of v2EventMsg"
    }
  }
}

Steps to reproduce

> swagger generate client -f example.swagger.json
2019/03/06 15:13:33 validating spec example.swagger.json
The swagger spec at "example.swagger.json" is invalid against swagger specification 2.0. see errors :
- some references could not be resolved in spec. First found: invalid token reference "v2EventMsg"

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions