swagger2postman icon indicating copy to clipboard operation
swagger2postman copied to clipboard

java.lang.ClassNotFoundException when I call Swagger2PostmanApp.scala from console.

Open dakiryanov opened this issue 8 years ago • 12 comments

I have downloaded the sources from your repository and unzipped it. If I try to call a Swagger2PostmanApp.scala from console, it throws an exception. Could you please help me to solve the problem?

dakiryanov avatar Feb 20 '17 14:02 dakiryanov

Can you post the command you ran? I just ran the following command from latest master and it worked:

sbt "runMain com.josephpconley.swagger2postman.app.v2.Swagger2PostmanApp v2petstore-swagger.json petstore"

josephpconley avatar Feb 21 '17 15:02 josephpconley

Hi Joseph! I run a command in that way: Screenshot

c:\converter>sbt "runMain converter.src.main.scala.com.josephpconley.swagger2postman.app.v2.Swagger2PostmanApp swagger.json postman.json"

It throws error: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0 [info] Set current project to converter (in build file:/C:/converter/) [info] Running converter.src.main.scala.com.josephpconley.swagger2postman.app.v2.Swagger2PostmanApp swagger.json postman.json [error] (run-main-0) java.lang.ClassNotFoundException: converter.src.main.scala.com.josephpconley.swagger2postman.app.v2.Swagger2PostmanApp java.lang.ClassNotFoundException: converter.src.main.scala.com.josephpconley.swagger2postman.app.v2.Swagger2PostmanApp at java.lang.ClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) [trace] Stack trace suppressed: run last compile:runMain for the full output. java.lang.RuntimeException: Nonzero exit code: 1 at scala.sys.package$.error(package.scala:27) [trace] Stack trace suppressed: run last compile:runMain for the full output. [error] (compile:runMain) Nonzero exit code: 1

dakiryanov avatar Feb 21 '17 15:02 dakiryanov

Looks like you need to cd into the swagger2postman directory, then run from there.

josephpconley avatar Feb 21 '17 16:02 josephpconley

Now it throws another errors

C:\converter\converter\src\main\scala\com\josephpconley\swagger2postman>sbt "runMain app.v2.Swagger2PostmanApp swagger.json postman.json" Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0 [info] Set current project to swagger2postman (in build file:/C:/converter/converter/src/main/scala/com/josephpconley/swagger2postman/) [info] Updating {file:/C:/converter/converter/src/main/scala/com/josephpconley/swagger2postman/}swagger2postman... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] Compiling 1 Scala source to C:\converter\converter\src\main\scala\com\josephpconley\swagger2postman\target\scala-2.10\classes... [info] 'compiler-interface' not yet compiled for Scala 2.10.6. Compiling... [info] Compilation completed in 8.173 s [error] C:\converter\converter\src\main\scala\com\josephpconley\swagger2postman\CollectionArgs.scala:3: object utils is not a member of package com.josephpconley.swagger2postman [error] import com.josephpconley.swagger2postman.utils.ConversionUtils [error] ^ [error] C:\converter\converter\src\main\scala\com\josephpconley\swagger2postman\CollectionArgs.scala:4: not found: object play [error] import play.api.libs.json.Json [error] ^ [error] C:\converter\converter\src\main\scala\com\josephpconley\swagger2postman\CollectionArgs.scala:6: not found: object ConversionUtils [error] import ConversionUtils._ [error] ^ [error] C:\converter\converter\src\main\scala\com\josephpconley\swagger2postman\CollectionArgs.scala:11: not found: value genUUID [error] val collectionId = genUUID [error] ^ [error] C:\converter\converter\src\main\scala\com\josephpconley\swagger2postman\CollectionArgs.scala:15: not found: value Json [error] implicit val collectionFmt = Json.format[CollectionArgs] [error] ^ [error] 5 errors found [error] (compile:compileIncremental) Compilation failed [error] Total time: 21 s, completed Feb 21, 2017 7:24:27 PM

dakiryanov avatar Feb 21 '17 16:02 dakiryanov

Try running from C:\converter\converter\.

josephpconley avatar Feb 21 '17 16:02 josephpconley

I'd also add that if you just want to do a quick Swagger -> Postman conversion, you can use the hosted version here.

josephpconley avatar Feb 21 '17 16:02 josephpconley

Joseph, thank you for your advise, I just have started your program and it works. But it parses only your v2petstore-swagger.json file. The swagger file generated by my API is not accepted: the program throws the following error: [info] Running com.josephpconley.swagger2postman.app.v2.Swagger2PostmanApp swagger.json postman.json Error converting Swagger v2 doc to Postman json { "obj.host" : [ { "msg" : "error.path.missing", "args" : [ ] } ], "obj.tags" : [ { "msg" : "error.path.missing", "args" : [ ] } ] } The screenshot is here

Could you please advise, why the problem occurred?

dakiryanov avatar Feb 22 '17 10:02 dakiryanov

This error indicates that your missing both a host property and a tags property in your JSON file. Can you post a link to your swagger.json?

You can also use http://bigstickcarpet.com/swagger-parser/www/index.html to validate your swagger JSON file.

josephpconley avatar Feb 22 '17 14:02 josephpconley

Doesn't work for me either, I use Swagger Petstore (Simple) specification from swagger examples, so the problem is obviously not in JSON file.

And tags, operationId and summery are not required according to Swagger 2.0 specification.

Error converting Swagger v2 doc to Postman json
{
  "obj.paths./pets.post.tags" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ],
  "obj.tags" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ],
  "obj.paths./pets/{id}.get.tags" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ],
  "obj.paths./pets.get.summary" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ],
  "obj.paths./pets.get.tags" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ],
  "obj.paths./pets/{id}.get.summary" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ],
  "obj.paths./pets/{id}.delete.tags" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ],
  "obj.paths./pets.post.summary" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ],
  "obj.paths./pets/{id}.delete.summary" : [ {
    "msg" : "error.path.missing",
    "args" : [ ]
  } ]
}
[success] Total time: 100 s, completed Mar 2, 2017 1:28:57 PM

AlexMoroz avatar Mar 02 '17 12:03 AlexMoroz

Can you post a link to the swagger JSON you're using just so I'm confident I'm testing the same file? Thanks.

josephpconley avatar Mar 10 '17 14:03 josephpconley

I used this specification, but the json version generated by swagger editor.

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Swagger Petstore (Simple)",
        "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
        "termsOfService": "http://helloreverb.com/terms/",
        "contact": {
            "name": "Swagger API team",
            "email": "[email protected]",
            "url": "http://swagger.io"
        },
        "license": {
            "name": "MIT",
            "url": "http://opensource.org/licenses/MIT"
        }
    },
    "host": "petstore.swagger.io",
    "basePath": "/api",
    "schemes": [
        "http"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/pets": {
            "get": {
                "description": "Returns all pets from the system that the user has access to",
                "operationId": "findPets",
                "produces": [
                    "application/json",
                    "application/xml",
                    "text/xml",
                    "text/html"
                ],
                "parameters": [
                    {
                        "name": "tags",
                        "in": "query",
                        "description": "tags to filter by",
                        "required": false,
                        "type": "array",
                        "items": {
                            "type": "string"
                        },
                        "collectionFormat": "csv"
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "description": "maximum number of results to return",
                        "required": false,
                        "type": "integer",
                        "format": "int32"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "pet response",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/pet"
                            }
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            },
            "post": {
                "description": "Creates a new pet in the store.  Duplicates are allowed",
                "operationId": "addPet",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "pet",
                        "in": "body",
                        "description": "Pet to add to the store",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/newPet"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "pet response",
                        "schema": {
                            "$ref": "#/definitions/pet"
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        },
        "/pets/{id}": {
            "get": {
                "description": "Returns a user based on a single ID, if the user does not have access to the pet",
                "operationId": "findPetById",
                "produces": [
                    "application/json",
                    "application/xml",
                    "text/xml",
                    "text/html"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "description": "ID of pet to fetch",
                        "required": true,
                        "type": "integer",
                        "format": "int64"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "pet response",
                        "schema": {
                            "$ref": "#/definitions/pet"
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            },
            "delete": {
                "description": "deletes a single pet based on the ID supplied",
                "operationId": "deletePet",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "description": "ID of pet to delete",
                        "required": true,
                        "type": "integer",
                        "format": "int64"
                    }
                ],
                "responses": {
                    "204": {
                        "description": "pet deleted"
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "pet": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer",
                    "format": "int64"
                },
                "name": {
                    "type": "string"
                },
                "tag": {
                    "type": "string"
                }
            }
        },
        "newPet": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer",
                    "format": "int64"
                },
                "name": {
                    "type": "string"
                },
                "tag": {
                    "type": "string"
                }
            }
        },
        "errorModel": {
            "type": "object",
            "required": [
                "code",
                "message"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "format": "int32"
                },
                "message": {
                    "type": "string"
                }
            }
        }
    }
}

AlexMoroz avatar Mar 10 '17 14:03 AlexMoroz

Gotcha, so I followed the convention from http://petstore.swagger.io/v2/swagger.json and assumed that the tags field would be populated for each path entry. I'm not sure what else to use if the tags field is missing, any ideas?

josephpconley avatar Mar 13 '17 19:03 josephpconley