-
Notifications
You must be signed in to change notification settings - Fork 45
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
Support for converting patternProperties? #19
Comments
Are there any specific draft-07 features you need, maybe in priority order? Then we can see which ones are representable in draft-04/05 constructs. |
I just checked specifications of draft-06 and draft-07 - and it seems that needed features were implemented even ealier... I don't know what exactly works but what I need:
"timingsCombined": {
"type": "array",
"items": {
"searchId": {
"type": "string",
"maxLength": 36,
"minLength": 36
},
"timings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"start": {
"type": "integer"
},
"timings": {
"type": "array",
"items": {
"type": "integer"
}
}
},
"additionalProperties": false
}
}
}
}, Seems like it is also not supported by openapi.
"rates": {
"type": "object",
"patternProperties": {
"^[A-Z]{6}$": {
"type": "string"
}
},
"additionalProperties": false
}, |
I can also provide a sample of schema that I want to convert. |
If I understand you right, OpenAPI does support "nested schemas" without It also supports objects within
If you could share a gist of the schema you want to convert (rather than pasting it here), then, yes, that would be helpful. |
Thanks for the explanation! My test schema for ajv (JSONSchema draft-07): I validated it using several online validators and ajv - I think that it fine. Then I validate this schema using online swagger editor and I think that the most important problem is the absense of |
I've got no way of validating https://github.com/jehy/jsonSchemaToOpenApi/blob/master/searchResultV2.js because it's js code not a schema document. If you have it as a plain JSON Schema document, please post a gist to that too. As above:
|
No problem, it just needs to be serilized: |
Thanks - confirmed that seems to be valid against Draft 07. Hmm, in the code |
I changed The schema looks like this now: OpenApi validator even has no warning and errors, but it seems that's because |
May be we can try downgrading https://www.e-learn.cn/content/wangluowenzhang/1657225 I think that we will lose regexp format, but retain the structure of document. |
Because |
I made a simple converter for the case when we have no Code is very simple: function isPrimitive(test) {
return (test !== Object(test));
}
function fixPatternProperties(obj)
{
const defaultValue = obj instanceof Array && [] || {};
return Object.entries(obj).reduce((res, [name, value])=>{
if(name==='additionalProperties')
{
if(!res.additionalProperties)
{
res.additionalProperties = value;
}
return res;
}
if(name==='patternProperties')
{
const inner = fixPatternProperties(Object.values(value)[0]);
res.additionalProperties = inner;
res['x-pattern'] = Object.keys(value)[0];
return res;
}
if(isPrimitive(value))
{
res[name]=value;
return res;
}
res[name]=fixPatternProperties(value);
return res;
}, defaultValue)
} With this, I managed to turn https://github.com/jehy/jsonSchemaToOpenApi/blob/master/jsonSchema.json into https://github.com/jehy/jsonSchemaToOpenApi/blob/master/swagger.json - and it renders in Swagger editor beautufully, without any errors, and with all the structure and examples: Full code is here if needed: https://github.com/jehy/jsonSchemaToOpenApi/blob/master/index.js |
Thanks. I think we would need to cope with more cases, but I like the method of preserving the pattern(s). Good idea! |
@MikeRalphson |
The cases would be where |
Hi! Great package! I'd like to know if there are plans to support JSON Schema draft-07.
I really dream abount converting ajv schemas to swagger specifications : )
The text was updated successfully, but these errors were encountered: