-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
The word "Items" appears in swagger-editor after resolving $ref using json-refs #105
Comments
I'm not sure I fully understand the question. |
Ok, do you see the word "items" on the image attached right pane. I was wondering whether is it appropriate to display "items"? I've json schema for swagger-editor and have many $ref's to resolve which in turn the swagger is not able to resolve using url so, I used your tool to convert to full definitions. Another question, whether swagger-editor uses your nodejs module "json-refs" to resolve the $ref? |
|
Thank you for the quick reply! When I refer a json schema on swagger-editor which is in another json file. it shows undefined (attached image below marked red), Can you please help resolve this issue? Here's the example below: id.json |
If you ever get See if that helps and I will try to see if I can reproduce the issue where a missing reference is given the value of Note: I'm not sure if |
sorry my mistake, copy/paste error, it's "definitions" not "descriptions" |
Do you have a sample that can be ran via |
Example, please paste it on the swagger-editor below code: (removed spaces for compact view) { "swagger": "2.0", "info": { "version": "1.0.0", "title": "Sites" }, "path": {}, "definitions": { "A1": { "title": "A1", "type": "object", "description": "", "properties": { "a2": { "type": "array", "items": { "title": "A2", "type": "object", "description": "", "properties": { "$ref": "http://localhost/swagger-editor/Json/id.json#/definitions/ids" } }, "x-tag": 11, "description": "some comments" } } } } } Save the below json in file named "id.json" under folder named "json" (removed spaces for compact view) { "swagger": "2.0", "info": { "version": "1.0.0", "title": "id" }, "paths": { }, "definitions": { "ids": { "type": "object", "properties": { "items": { "title": "IDS", "type": "object", "description": "", "properties": { "id": { "type": "string", "x-tag": 11, "description": "Specifies a mandatory id" }, "name": { "type": "string", "x-tag": 12, "description": "Specifies the name" }, "description": { "type": "string", "x-tag": 13, "description": "Specifies some description" }, "config": { "type": "array", "items": { "$ref": "http://localhost/swagger-editor/Json/id.json#/definitions/properties/Config" }, "x-tag": 11, "description": "Specifies list of configured items in the System." } } } } }, "Config": { "title": "SomeConfig", "type": "object", "description": "", "properties": { "identifiers": { "type": "object", "properties": { "$ref": "http://localhost/swagger-editor/Json/id.json#/definitions/properties/Identifiers" }, "x-tag": 11, "description": "Specifies identifier" }, "algorithmName": { "type": "string", "x-tag": 13, "description": "Specifies algorithm names" }, "State": { "type": "boolean", "x-tag": 14, "description": "if set to true , indicates that is enabled" } } }, "Identifiers": { "title": "SomeIdentifiers", "type": "object", "description": "This will be used to identify", "properties": { "id": { "type": "string", "x-tag": 11, "description": "Specifies a mandatory identifier to uniquely represent" }, "name": { "type": "string", "x-tag": 12, "description": "Specifies the name" }, "description": { "type": "string", "x-tag": 13, "description": "Specifies some description" }, "state": { "type": "object", "properties": { "$ref": "http://localhost/swagger-editor/Json/id.json#/definitions/properties/AState" }, "x-tag": 31, "description": "Specifies the status" } } }, "AState": { "title": "AnalyticState", "type": "object", "description": "Specifies the states of Analytics", "properties": { "id": { "type": "string", "x-tag": 11, "description": "Specifies a mandatory identifier" } } } } You'll notice that for a2(A2) it shows "undefined" on right pane of swagger-editior. The json has nested $ref's which also it must resolve. but it doesn't. please let me know of any issues. Thank you for your valuable time again! |
I'm not seeing this when using {
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Sites"
},
"path": {},
"definitions": {
"A1": {
"title": "A1",
"type": "object",
"description": "",
"properties": {
"a2": {
"type": "array",
"items": {
"title": "A2",
"type": "object",
"description": "",
"properties": {
"type": "object",
"properties": {
"items": {
"title": "IDS",
"type": "object",
"description": "",
"properties": {
"id": {
"type": "string",
"x-tag": 11,
"description": "Specifies a mandatory id"
},
"name": {
"type": "string",
"x-tag": 12,
"description": "Specifies the name"
},
"description": {
"type": "string",
"x-tag": 13,
"description": "Specifies some description"
},
"config": {
"type": "array",
"items": {
"$ref": "id.json#/definitions/properties/Config"
},
"x-tag": 11,
"description": "Specifies list of configured items in the System."
}
}
}
}
}
},
"x-tag": 11,
"description": "some comments"
}
}
}
}
} And here is a test I ran using {
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Sites"
},
"path": {},
"definitions": {
"A1": {
"title": "A1",
"type": "object",
"description": "",
"properties": {
"a2": {
"type": "array",
"items": {
"title": "A2",
"type": "object",
"description": "",
"properties": {
"type": "object",
"properties": {
"items": {
"title": "IDS",
"type": "object",
"description": "",
"properties": {
"id": {
"type": "string",
"x-tag": 11,
"description": "Specifies a mandatory id"
},
"name": {
"type": "string",
"x-tag": 12,
"description": "Specifies the name"
},
"description": {
"type": "string",
"x-tag": 13,
"description": "Specifies some description"
},
"config": {
"type": "array",
"items": {
"$ref": "id.json#/definitions/properties/Config"
},
"x-tag": 11,
"description": "Specifies list of configured items in the System."
}
}
}
}
}
},
"x-tag": 11,
"description": "some comments"
}
}
}
}
} Here is the var Sway = require('sway')
Sway.create({
definition: 'swagger.json'
})
.then(function (api) {
console.log(JSON.stringify(api.definitionFullyResolved, null, 2))
})
.catch(function (err) {
console.log(err.stack);
}) So if |
I agree with you that json-refs & sway are working fine when used independently, it's only with swagger-editor that it happens which in turn uses sway & json-refs module. Besides, since sway & json-refs is able to resolve $ref I've a instance where the outputn of resolve has $ref which is nested again.... If sway/json-refs can identify if the output also has $ref and resolve it then it would be really nice may be some kind of option whether you want to resolve nested $refs, just a thought.... |
If there are unresolved |
correct, swagger-editor reports error: message: "Reference could not be resolved:" |
Did you get an chance to run the above json in swagger-editor? |
I've not. I will give it a shot and see if I can find out where the issue is. The error is somewhat suspect because I don't use the "in" JavaScript keyword so I'm betting that |
Thank you, even I'm trying to setup swagger code base and test it....
…On 15-Feb-2017 10:46 PM, "Jeremy Whitlock" ***@***.***> wrote:
I've not. I will give it a shot and see if I can find out where the issue
is. The error is somewhat suspect because I don't use the *"in"*
JavaScript keyword so I'm betting that swagger-editor itself has a bug.
I'll let you know.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#105 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYa8tBs1ED7RBJ-LCmZzENUyLqZmn3TIks5rczLmgaJpZM4L5Xmg>
.
|
I loaded the file you provided into http://editor.swagger.io/#/ and I see the error you're talking about. One thing that I can't fully explain is the error message. The error from I'll keep looking. |
I think the error is in |
But just know, |
Thank you whitlockjc! I'll follow up and check on my side too. |
And, suppose a json has nested $ref's then, does it resolves the nested ones too? While viewing in swagger-editor? I'm debugging the sway & json-refs using swagger-editor on chrome will be able to pinpoint the code which is not getting the values for nested $ref probably in json-refs..... |
Yes, |
I may have fixed the nested $ref issue (which I mention in my earlier post) in json-refs but the problem now with my fix is it resolves all the nested $refs but cannot return resolved output to the resolveRefs() return object. Can you just help me out here? And, let me know if it works out. I believe the calls might be repeated due to async.... The below I've placed just before the resolveRefs() ruturn line:
|
I believe you should call the resolveRefs again inside the success function of then, `function processResult(result) { //resolve $refs var refs = findRefs(obj, options); //checking if any $ref's |
My earlier code was issuing warning on chaining, cleaned it but still the outer return doesn't give the inner return resolved refs object. here is the code...
|
After using the json-refs resolve for $ref's the converted json is placed on swagger-editor and result show "items" which may not be appropriate per Swagger Specs.
Please clarify.
Sample Json:
"definitions": { "A1": { "title": "A1", "type": "object", "description": "", "properties": { "a2": { "type": "array", "items": { "title": "A2", "type": "object", "description": "", "properties": { "ids": { "type": "object", "properties": { "items": { "title": "IDS", "type": "object", "description": "", "properties": { "id": { "type": "string", "x-tag": 11, "description": "Specifies a mandatory id" }, "name": { "type": "string", "x-tag": 12, "description": "Specifies the name" }, "description": { "type": "string", "x-tag": 13, "description": "Specifies some description" } } } }, "x-tag": 11, "description": "some comments" } } }, "x-tag": 11, "description": "some comments" } } } }
The text was updated successfully, but these errors were encountered: