zalando / intellij-swagger

A plugin to help you easily edit Swagger and OpenAPI specification files inside IntelliJ IDEA
https://plugins.jetbrains.com/plugin/8347
MIT License
1.18k stars 75 forks source link

Add ability to validate swagger file #118

Closed xp-vit closed 5 years ago

xp-vit commented 7 years ago

When I paste the content of my swagger file to http://editor.swagger.io/ it reports a lot of errors(bad indentation, semantic errors, schema errors), while plugin itself doesn't report anything.

This is the request to add the ability to provide the same level of validation in the plugin. To achieve this we can go following ways:

  1. Implement validations in plugin
  2. Use the http://editor.swagger.io/ api to validate and show erors reported.
  3. Add a shortcut which will open http://editor.swagger.io/ with the content of current swagger file already pasted.
semonte commented 6 years ago

@xp-vit Thanks for creating the issue. There is already some validation for Swagger files, but it is not complete. Can you post the spec file for testing purposes?

keilw commented 6 years ago

I changed a datatype to an incorrect "objekt" instead of "object" which the Swagger online editor flags as invalid, but the plugin currently does not.

semonte commented 6 years ago

@keilw Thanks for the feedback.

Validation has not been worked on recently. Now that the Open API support is mostly done, proper validation could be next in the priority list.

cognifloyd commented 5 years ago

I found that specifying a JSON schema (openapi-3.0 or swagger-2.0) warns about a lot of the errors that the Swagger Editor detects. Maybe this plugin can enable that by default. https://www.jetbrains.com/help/idea/json.html#ws_json_using_schemas

wabiloo commented 5 years ago

I also would like some additional validation. In particular, validating that the $ref references are pointing to valid files. Eg.

    /root/inputs:
        $ref: './paths/roots/inputs.yaml'

If there is no such inputs.yaml file, the plugin should detect it and give a warning

semonte commented 5 years ago

I found that specifying a JSON schema (openapi-3.0 or swagger-2.0) warns about a lot of the errors that the Swagger Editor detects. Maybe this plugin can enable that by default. https://www.jetbrains.com/help/idea/json.html#ws_json_using_schemas

I have been planning to take a look at this! This would likely be a big help with keeping spec files valid.

semonte commented 5 years ago

In particular, validating that the $ref references are pointing to valid files.

Agree, created an issue #226

cognifloyd commented 5 years ago

in #227, I was looking for libraries that could be integrated. In doing so I came across these linters. Most of them aren't Java, and those that are implement their own parser as well, so I'm not sure how embeddable these could be. But, all of them might offer hints about how to do validation logic beyond using the json schema.

semonte commented 5 years ago

Thanks for the list @cognifloyd I will start with a JSON Schema validation as a "low hanging fruit", and iterate on top of that.

semonte commented 5 years ago

A Swagger/OpenAPI specification file is currently validated with a JSON Schema. On top of that, we validate that references point to existing objects.

I will close this issue; validation issues should be handled by individual issues from now on.