GithubHelp home page GithubHelp logo

Comments (13)

ghillairet avatar ghillairet commented on June 27, 2024

We mentioned in our discussion that we could do that by forking the json-schema-validator repository. This repository is available here https://github.com/fge/json-schema-validator.

Looks like there has not been much development on it and the owner is looking for a new maintainer. Should we fork it under ModelSolv?

from kaizen-openapi-editor.

ghillairet avatar ghillairet commented on June 27, 2024

We could do it without having to fork this project, processing error messages should be possible to create more meaningful messages.

# fixture 4
# invalid responses type, should be an object

swagger: '2.0'
info:
  version: 0.0.0
  title: Simple API
paths:
  /:
    get:
      responses: 'Hello'

This is the error object that result from the validation of the above yaml:

{
  "level": "error",
  "schema": {
    "loadingURI": "http://swagger.io/v2/schema.json#",
    "pointer": "/definitions/responses"
  },
  "instance": {
    "pointer": "/paths/~1/get/responses"
  },
  "domain": "validation",
  "keyword": "type",
  "message": "instance type (string) does not match any allowed primitive type (allowed: [\"object\"])",
  "found": "string",
  "expected": [
    "object"
  ]
}

The default message says that the value for responses should be an object and not a string (here Hello).

But it should be doable to get a better message by getting meaningful information from the schema. The relevant part of the schema is given in the error field schema. Here the part of the schema:

"responses": {
      "type": "object",
      "description": "Response objects names can either be any valid HTTP status code or 'default'.",
      "minProperties": 1,
      "additionalProperties": false,
      "patternProperties": {
        "^([0-9]{3})$|^(default)$": {
          "$ref": "#/definitions/responseValue"
        },
        "^x-": {
          "$ref": "#/definitions/vendorExtension"
        }
      },
      "not": {
        "type": "object",
        "additionalProperties": false,
        "patternProperties": {
          "^x-": {
            "$ref": "#/definitions/vendorExtension"
          }
        }
      }
    }

from kaizen-openapi-editor.

tfesenko avatar tfesenko commented on June 27, 2024

A list of validation messages from JsonSchema Validation (provided by @ghillairet ) - https://github.com/fge/json-schema-validator/blob/master/src/main/resources/com/github/fge/jsonschema/validator/validation.properties

from kaizen-openapi-editor.

tfesenko avatar tfesenko commented on June 27, 2024

We decided to create a suite of tests for validation messages.
The tests will be specification - the YAML model under test and validation message should be in the same file. For example, line in Xtext Xpect or in https://github.com/ghillairet/emfjson/blob/emfjson-0.9.0/emfjson-jackson/src/test/java/org/emfjson/jackson/junit/tests/EnumTest.xtend#L38 when model text is pasted to the test.

JSON Schema for Swagger is here - https://github.com/swagger-api/swagger-spec/blob/master/schemas/v2.0/schema.json . It can be used to retrieve additional information for the validation message.

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 27, 2024

@tfesenko , I can provide better error messages, but think I will need some guidance as to how I can specify them, to make use of the information available in the schema. In some cases, I will need to use variables that don't seem to be defined yet.

Let's talk after tomorrow's SUM.

from kaizen-openapi-editor.

tfesenko avatar tfesenko commented on June 27, 2024

@tedepstein , @ghillairet started the "tests as documentation" in ValidationMessageTest.

The expected message is placed above the model text. In the model text, the " #validation error marker" are placed right above the place where we expect to see a validation error. It's for human convenience only and will be ignored by the test.

Does this format suit you? Do you have any suggestions to improve readability?

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 27, 2024

@tfesenko , this looks fine to me. Want to complete the inventory of tests, and then I'll review? Or do you want my input now?

from kaizen-openapi-editor.

tfesenko avatar tfesenko commented on June 27, 2024

@tedepstein , I don't plan to add more validation examples today.

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 27, 2024

I've added my comments. See commit f2a852c .

from kaizen-openapi-editor.

ghillairet avatar ghillairet commented on June 27, 2024

Some of the messages have been updated, as you can see in this commit 9988e42

It concerns the most common error messages.

The most interesting would be that this previous kind of messages

instance failed to match exactly one schema (matched 0 out of 2)

will be replaced by more meaningful ones, such as

value of type integer is not allowed, value should be of type string
object has properties "description" which are not allowed
object has missing required properties "$ref"

This excerpt represents in single message that replaces the previous one. It includes all the errors that apply at a position of the document.

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 27, 2024

@ghillairet , w.r.t. your last comment, I opened #60, which I think is partially caused by the replacement of "instance failed to match exactly one schema" with a list of errors related to each failed match.

We could try listing the schemas individually, like this:

Failed to match exactly one schema:
  schema 1 :
    - value of type integer is not allowed, value should be of type string
  schema 2:
    - object has properties "description" which are not allowed
    - object has missing required properties "$ref"

It's not ideal, because we cannot easily name or describe the schemas. The user has to guess what the different schemas are looking for.

But it's more informative than a single "failed to match", and it organizes the error messages in a way that might make it easier to interpret.

Thoughts?

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 27, 2024

Also, the example in #60 seems to show that schema validation failures can be recursive. We see "failed to match" errors, presumably arising from attempted schema validation of contained definitions.

I don't think it's wise to try to "unwrap" schema validation errors recursively. We could get a really large tree, and could even encounter cycles, unless we're sure that this kind of validation is acyclic... Regardless, it seems like we should not try to take the unwrapping too far.

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 27, 2024

@tfesenko , as discussed, please review and extract to separate issues if needed. Note that we already have #60 open for error messages on oneOf validation errors.

from kaizen-openapi-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.