Giter Club home page Giter Club logo

Comments (14)

tfesenko avatar tfesenko commented on June 20, 2024

Just verified it on the latest build - it's still there.

from kaizen-openapi-editor.

ghillairet avatar ghillairet commented on June 20, 2024

The problem is that the json-schema for swagger does not provide any values for this property. See https://github.com/ModelSolv/SwagEdit/blob/master/com.reprezen.swagedit/src/com/reprezen/swagedit/json/schema.json#L932

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 20, 2024

I'd recommend fixing this (and a few other issues) by amending the schema to add an appropriate enum restriction in each case.

In this particular case, I think we could submit our schema change as a pull request back to the swagger-spec project. But regardless of whether our PR is accepted, it makes sense for SwagEdit to own and control its own version of the schema.

(Note: In other cases, we'd maintain our changes locally because they aren't strictly required. For example, the spec doesn't require schemes to be specified; it defaults to a value of http; but the Swagger UI doesn't recognize this default, and therefore requires schemes to be explicitly specified. We might want to require it in API Studio for this reason, and a schema change might be the most expedient way to do that.)

from kaizen-openapi-editor.

ghillairet avatar ghillairet commented on June 20, 2024

I took the formats from here http://swagger.io/specification/#dataTypeFormat, and implemented like below in schema.json file. I left the default string type, so that users can still define their own formats.

 "format": {
    "oneOf": [
      {
        "type": "string"
      },
      {
        "type": "string",
        "enum": [
          "int32",
          "int64",
          "float",
          "double",
          "byte",
          "binary",
          "date",
          "date-time",
          "password"
        ]
      }
    ]
  }

Completion for format

screen shot 2016-01-15 at 11 46 58

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 20, 2024

@ghillairet , good idea. I didn't realize that Swagger allowed custom formats.

But IIUC, JSON Schema's oneOf will fail validation if a value matches more than one of the provided schemas. Would anyOf work better here?

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 20, 2024

JSON Schema oneOf doc:

http://json-schema.org/latest/json-schema-validation.html#anchor88

from kaizen-openapi-editor.

ghillairet avatar ghillairet commented on June 20, 2024

Not sure about this.

oneOf > validates successfully against exactly one schema
anyOf > validates successfully against at least one schema

I would say oneOf is ok.

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 20, 2024

Please try it with a JSON schema validator. I think the difference between oneOf and anyOf is as I described. oneOf has to match exactly one of the provided schemas. It's an XOR, whereas anyOf is an inclusive OR.

from kaizen-openapi-editor.

ghillairet avatar ghillairet commented on June 20, 2024

Both cases don't make any difference for the validator, since the first schema matches all string and the second matches a enum of strings. It's always the first schema that will be taken into account for validation. If it's not a string, then validation will fail.

So I believe for this case anyOf or oneOf are both valid.

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 20, 2024

Reopening, as I see a few problems remaining:

  1. The definition is repeated several times in the schema. It should be specified once, in the definitions section, and referenced there. In this milestone, even if we don't address any of the other points below, we should at least address that one.
  2. There are no unit tests to validate that the code assist suggestions are working correctly.
  3. I checked the JSON Schema Test Suite and tested in JSON-Schema Lint. It's clear that anyOf is the correct validation to use here.

Using the schema as specified, with oneOf:

{
  "oneOf": [
    {
      "type": "string"
    },
    {
      "type": "string",
      "enum": [
        "int32",
        "int64",
        "float",
        "double",
        "byte",
        "binary",
        "date",
        "date-time",
        "password"
      ]
    }
  ]
}

Here's JSON Schema Lint on a non-string value, as a baseline test:

image

Here's a random string, which matches the first schema, but not the second, and therefore satisfies oneOf:

image

Here's "double", which matches both schemas, and therefore fails oneOf

image

Change the first schema to number, and it passes validation:

image

Or change it back to string but use anyOf instead of oneOf. Again, it passes:

image

So I have to conclude that the JSON Schema validator we're using in SwagEdit / YEdit is not implementing oneOf semantics correctly. This is not caused any other problems that we've noticed so far, but it's something to be aware of. And we don't want our schema to start reporting validation errors if we upgrade to a new validator that fixes this problem.

from kaizen-openapi-editor.

ghillairet avatar ghillairet commented on June 20, 2024

I changed to use anyOf instead.

Note for later that validation fails also here with oneOf http://json-schema-validator.herokuapp.com/
This online validator uses the validation library we are using in SwagEdit, so there is maybe a bug in the library.

from kaizen-openapi-editor.

tedepstein avatar tedepstein commented on June 20, 2024

@ghillairet , this change looks good. Please open a PR for this.

from kaizen-openapi-editor.

tfesenko avatar tfesenko commented on June 20, 2024

6c1a1d9 was committed directly to master.

from kaizen-openapi-editor.

tfesenko avatar tfesenko commented on June 20, 2024

There is still no unit tests for this functionality, created #84 "Tests for code assist for format".
Closing this issue.

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.