failure to import swagger 1.2 json

Hi community

I am trying to import this (http://pastebin.com/raw.php?i=CdhNBy9K) to devportal smartdocs.

{
  "swaggerVersion": "1.2",
  "basePath": "http://localhost:8000/greetings",
  "apis": [
    {
      "path": "/hello/{subject}",
      "operations": [
        {
          "method": "GET",
          "summary": "Greet our subject with hello!",
          "type": "string",
          "nickname": "helloSubject",
          "parameters": [
            {
              "name": "subject",
              "description": "The subject to be greeted.",
              "required": true,
              "type": "string",
              "paramType": "path"
            }
          ]
        }
      ]
    }
  ],
  "models": {}
}

I stole it from hello-world sample: https://github.com/swagger-api/swagger-spec/wiki/Hello-World-Sample

It is failing with

There was an error importing your data. Please consult the logs.

Here is the response from management API:

>>>>>>>>
POST /v1/o/.../apimodels/omodel/revisions?action=import&format=swagger HTTP/1.1
Host: api.enterprise.apigee.com
accept: application/json; charset=utf-8
Content-Type: text/plain; charset=utf-8
User-Agent: DevPortal/15.01.08.00 Guzzle/3.9.2 curl/7.32.0 PHP/5.3.29
Referer: http://....devportal.apigee.com/admin/smartdocs/models/omodel/import
Authorization: Basic [**masked**]
Content-Length: 42

URL=http://pastebin.com/raw.php?i=CdhNBy9K
<<<<<<<<
HTTP/1.1 500 Server Error
Content-Type: application/json
Date: Fri, 17 Apr 2015 16:18:37 GMT
Content-Length: 71
Connection: keep-alive

{
  "message" : "io/swagger/parser/SwaggerParser",
  "contexts" : [ ]
}

What am I doing wrong?

Solved Solved
1 15 2,143
1 ACCEPTED SOLUTION

If you're using an org in the cloud, you should be able to import 2.0

View solution in original post

15 REPLIES 15

Hi Ozan, the swagger parser will navigate thro your swagger resource listing as well as individual apis.. so technically you cant give your pastebin url.

Raw swagger json is being served from pastebin URL. You can directly paste that url in browser to see.

I also have an Apigee proxy in front of pastebin raw to change the content type to json. 🙂

Ozan, your specification is invalid. Try Swagger's online validator badge project:

http://online.swagger.io/validator/?url=http%3A%2F%2Fpastebin.com%2Fraw.php%3Fi%3DCdhNBy9K

and debug version: http://online.swagger.io/validator/debug?url=http%3A%2F%2Fpastebin.com%2Fraw.php%3Fi%3DCdhNBy9K

Swagger-tools also offers great validation features as well, arguably more robust than the above.

Isn't this validating against swagger 2.0 - which is not supported anyway?

@Marsh Gardiner - is there an example URL that you can paste here?

You may be right about the online validator being 2.0 only. Need check.

Swagger tools is able to validate 1.2 and 2.0.

Modeling services do have 2.0 import support in beta now, so you could try that.

Do I need to do something to enable swagger 2.0 for my org/portal?

Because I am getting the same error in a valid swagger 2.0 (http://pastebin.com/raw.php?i=9wCSLkAW)

Here is the validation badge: http://online.swagger.io/validator/?url=http://pastebin.com/raw.php?i=9wCSLkAW

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Simple API"
    },
    "host": "httpbin.org",
    "basePath": "/",
    "produces": [
        "application/json"
    ],
    "paths": {
        "/get": {
            "get": {
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    }
}
There was an error importing your data. Please consult the logs.
HTTP/1.1 500 Server Error
Content-Type: application/json
Date: Fri, 17 Apr 2015 18:39:21 GMT
Content-Length: 71
Connection: keep-alive

{
  "message" : "io/swagger/parser/SwaggerParser",
  "contexts" : [ ]
}

http://online.swagger.io/validator/?url=https://mobily.fwd.wf/mobily_release/v2/api-docs?group=Mobil...

i checked my json here its valid but even i am getting the same error ''Error using OpenAPI: Unable to identify the Swagger version or the Swagger version is unsupported''

@amit patel the link you provided showed an "ERROR" image when I visited it: ERROR badge

Usually that validator is correct, so you might want to check that the spec doesn't have an error in there somewhere.

@Marsh Gardiner yes because I stop the server that's by now it is showing error but my yml/json file is valid I checked here its showing valid with green color , but still same error

If you're using an org in the cloud, you should be able to import 2.0

I must be doing something wrong then because this fails in an org in cloud:

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Simple API"
    },
    "host": "httpbin.org",
    "basePath": "/",
    "produces": [
        "application/json"
    ],
    "paths": {
        "/get": {
            "get": {
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    }
}

Just to close this off - swagger 2 is supported (in beta) as @Marsh Gardiner mentioned.

The problem with the above swagger json was that operationId property was missing - it is not a mandatory property in swagger but smartdocs seems to depend on it (for the moment).

Here is a simple swagger 2.0 that works with smartdocs (note the operationId property):

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Simple API"
    },
    "host": "httpbin.org",
    "basePath": "",
    "produces": [
        "application/json"
    ],
        "schemes": ["http"],
    "paths": {
        "/get": {
            "get": {
                "description": "Some description here",
                "operationId": "operationX",
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    }
}

BTW - pastebin is a very good solution for smartdocs requiring a URL for swagger json - for those that don't have a place to host their swagger files.

Just create an account and create a new paste. Right click "Raw" link, copy the url and paste it in devportal swagger URL field.

E.g. the swagger json file above is http://pastebin.com/raw.php?i=9wCSLkAW