swagger-api / validator-badge

Validate your Swagger JSON/YAML today!
http://swagger.io
Apache License 2.0
210 stars 85 forks source link

invalid swagger version "2.0" #31

Closed danielm64 closed 8 years ago

danielm64 commented 9 years ago

When I export in json with Swagger UI, the swagger version is generated as: "swagger": "2.0",

but validator badge reports this as invalid:

[
    {
        "level": "error",
        "domain": "validation",
        "keyword": "enum",
        "message": "instance value (\"2.0\") not found in enum (possible values: [2.0])",
        "schema": {
            "loadingURI": "#",
            "pointer": "/properties/swagger"
        },
        "instance": {
            "pointer": "/swagger"
        }
    },
    {
        "level": "error",
        "domain": "validation",
        "keyword": "type",
        "message": "instance type (string) does not match any allowed primitive type (allowed: [\"integer\",\"number\"])",
        "schema": {
            "loadingURI": "#",
            "pointer": "/properties/swagger"
        },
        "instance": {
            "pointer": "/swagger"
        }
    }
]
danielm64 commented 9 years ago

the json export should be: "swagger": 2.0,

webron commented 9 years ago

@danielm64 - this is definitely not a validator-badge issue, so not sure why you opened it here.

It's also not swagger-ui, as it doesn't have exporting capabilities. Do you mean swagger-editor? Something else?

danielm64 commented 9 years ago

Sorry... I've not been that much clear in my first post...

I'm using swagger-editor, export to JSON format my API spec. The json generated with swagger-editor is:

"swagger": "2.0",

When I load the json in swagger-ui, the validator bagde reports that it is invalid:

[
 {
 "level": "error",
 "domain": "validation",
 "keyword": "enum",
 "message": "instance value (\"2.0\") not found in enum (possible values: [2.0])",
 "schema": {
 "loadingURI": "#",
 "pointer": "/properties/swagger"
 },
 "instance": {
 "pointer": "/swagger"
 }
 },
 {
 "level": "error",
 "domain": "validation",
 "keyword": "type",
 "message": "instance type (string) does not match any allowed primitive type (allowed: [\"integer\",\"number\"])",
 "schema": {
 "loadingURI": "#",
 "pointer": "/properties/swagger"
 },
 "instance": {
 "pointer": "/swagger"
 }
 }
 ]

Seems that

"swagger": 2.0,

(without quotes for the version number) is expected...

webron commented 9 years ago

Can you share the actual Swagger definition that's generated?

danielm64 commented 9 years ago

yaml in swagger-editor:

swagger: "2.0"
info:
  version: "1.0"
  title: "Example"
paths:
  /wapi/example/{id}:
    get:
      operationId: "example"
      parameters:
      - name: "id"
        in: "path"
        required: true
        type: "string"
      responses:
        default:
          description: Unexpected error
        200:
          description: Successful response
          # A schema describing your response object.
          # Use JSON Schema format
          schema:
            title: ArrayOfPersons
            type: array
            items:
              title: Person
              type: object
              properties:
                name:
                  type: string
                single:
                  type: boolean

json generated:

{
    "swagger": "2.0",
    "info": {
        "version": "1.0",
        "title": "Example"
    },
    "paths": {
        "/wapi/example/{id}": {
            "get": {
                "operationId": "example",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful response",
                        "schema": {
                            "title": "ArrayOfPersons",
                            "type": "array",
                            "items": {
                                "title": "Person",
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    },
                                    "single": {
                                        "type": "boolean"
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Unexpected error"
                    }
                }
            }
        }
    }
}
webron commented 9 years ago

@danielm64 - do you use your own instance of the validator-badge or the online one? If it's hosted locally, does it have access to the internet or is it in a closed intranet?

danielm64 commented 9 years ago

yes, using my own instance and in a closed intranet... However, I tried the "http://petstore.swagger.io/v2/swagger.json" available on the online ui demo, and my instance also reports the version issue while the online not. I'm going to refresh my validator bagde...

webron commented 9 years ago

Try upgrading to the develop branch.

danielm64 commented 9 years ago

@webron Got it works but I needed some dirty adaptation, probably because I don't have an internet access on my server. The error reported was:

com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: unable to dereference URI "http://swagger.io/v2/schema.json#"
    level: "fatal"
    uri: "http://swagger.io/v2/schema.json#"
    exceptionMessage: "swagger.io"

I don't share my workaround as it is really dirty...

webron commented 9 years ago

Actually, if you share it, no matter how dirty it is, it may help us overcome the issue for intranet installations which would help both you and other users. There's nothing wrong with a dirty solution if it's the only one you can fine, but if we can provide a better solution, all the better.

danielm64 commented 9 years ago

@webron Ok, here is what I've done to bypass the problem. It's dirty, but I don't have time to look for an acceptable solution... :-(

In my intranet configuration, without Internet access, there is no access to the online json schema (http://swagger.io/v2/schema.json), so it uses the local file included in the delivery (SCHEMA_FILE). In this file, the "id" also references the online schema, and it seems to also be a problem. My dirty workaround has been to modifiy the "id" in the schema.json of the delivery to point a local copy of this file (http://_myIntranetDomain_/swagger/2.0/schema.json).

webron commented 9 years ago

That's actually a reasonable solution considering the situation. It also brings up a problem with closed intranets which we haven't taken into account, so thank you for sharing. We need to resolve it.

cariadeccleston commented 9 years ago

Just in case anyone finds this thread the same way I did, looking to fix this exception:

com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: unable to dereference URI "http://swagger.io/v2/schema.json#"

My machine has access to the web, but only via a proxy.

I had the proxy set for maven via its settings file, but I had to specify the proxies for the JRE too.

In my script which starts the validator badge server, I added:

export MAVEN_OPTS="-Dhttp.proxyHost={{proxy}} -Dhttp.proxyPort={{proxy port}} -Dhttps.proxyHost={{proxy}} -Dhttps.proxyPort={{proxy port}}"

(...but replace the {{proxy}} and {{proxy port}} placeholders with your actual values.)

I know this doesn't have anything to do with the validator badge, but it was a stumbling block for me getting it up and running (albeit with no previous maven experience at all) so I wanted to share it.

pdemello commented 9 years ago

@cariadeccleston This was also a stumbling block for me. Works, thanks.

narender2031 commented 7 years ago

"/api/v1/auth/login": { "post": { "summary": "Creates and returns access_token if valid login", "description": "Creates and returns access_token if valid login", "produces": [ "application/json" ], "consumes": [ "application/json" ], "parameters": [ { "in": "formData", "name": "login", "description": "Username or email address", "type": "string", "required": true }, { "in": "formData", "name": "password", "description": "Password", "type": "string", "required": true } ],

hyy ! friend i am getting issue that my body data is invalid becouse it is not in json format.

mikeholler commented 7 years ago

I'm getting:

Caused by: com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: unable to dereference URI "http://swagger.io/v2/schema.json#"
    level: "fatal"
    uri: "http://swagger.io/v2/schema.json#"
    exceptionMessage: "Connection refused (Connection refused)"

From the id field just like @danielm64. I see this issue has been closed without reason (as far as I can tell) and untouched for over a year. What is Swagger's official stance on this issue? Right now the site's down completely, even with Internet access. We should not need Internet access to validate a Swagger specification is compliant with the official JSON schema. To fix my issue, I'm going to use @danielm64's dirty fix, but would love to know if there's anything else in the pipeline so that we can use the official spec, unmodified.

Thanks for your help!