-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code assist for format
keyword inserts empty quotes
#46
Comments
Just verified it on the latest build - it's still there. |
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 |
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 |
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 |
@ghillairet , good idea. I didn't realize that Swagger allowed custom formats. But IIUC, JSON Schema's |
JSON Schema http://json-schema.org/latest/json-schema-validation.html#anchor88 |
Not sure about this. oneOf > validates successfully against exactly one schema I would say oneOf is ok. |
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. |
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. |
[#46] Code assist for `format` keyword inserts empty quotes
Reopening, as I see a few problems remaining:
Using the schema as specified, with
Here's JSON Schema Lint on a non-string value, as a baseline test: Here's a random string, which matches the first schema, but not the second, and therefore satisfies Here's "double", which matches both schemas, and therefore fails Change the first schema to Or change it back to So I have to conclude that the JSON Schema validator we're using in SwagEdit / YEdit is not implementing |
I changed to use anyOf instead. Note for later that validation fails also here with oneOf http://json-schema-validator.herokuapp.com/ |
@ghillairet , this change looks good. Please open a PR for this. |
6c1a1d9 was committed directly to master. |
There is still no unit tests for this functionality, created #84 "Tests for code assist for |
The format key allows certain values according to the Swagger specification, and I expected to see these values from code assist. But it just inserted blank quotes, which is not so useful.
The text was updated successfully, but these errors were encountered: