-
Notifications
You must be signed in to change notification settings - Fork 92
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
Getting 'UNRESOLVABLE_REFERENCE' Error even though the definition is present in the swagger spec #126
Comments
I can confirm this. I'll look into it. |
@whitlockjc - Sorry for bugging you. But any update on this? This will be a blocker for us. We are planning to take a dependency on this in our CI process before merging swaggers. Any update would be really helpful. Interesting feature in z-schema that can be used in SwayBtw, I found another way to validate examples against model definitions.
I followed the example provided in the z-schema repo over here. let valid = validator.validate(responseBodyExample, schema, { schemaPath: "definitions.RouteFilter" });
if (!valid) {
let error = validator.getLastErrors();
console.dir(error, {depth: null, colors: true});
} where:
If we use this approach then one need not depend on json-refs to fullyResolve references. It makes life simple when circular references are involved. I ran the above changes locally in my script and it did the right thing for me. What do you think about it? |
@whitlockjc - Any thoughts on the alternative approach (z-schema feature "validating against a sub-schema") provided in the previous comment? |
I implemented that at one point honestly and it worked fine but I needed the full schema to generate sample data anyways so I just went with one approach. The fully-resolved approach should just work once the |
I see. No worries. I have forked your repo and made changes based on the alternate solution. I am testing different scenarios to make sure everything works. Once things look good, will send a PR. Would love to take your feedback on it :). |
Did a PR ever come from this? |
With the latest on |
Closing this until there is more information. |
Hi @whitlockjc just one question! I'm dealing with this same issue. it's fine that it is fixed in master, but how can I tell to my node.js application to use sway from master? I can only tell to use version 1.0.0 which doesn't include this fix. Will there be soon, I mean very soon some new release? Thanks |
You can use |
Thanks! My fault, didn't check npm documentation in detail :/ |
Hi @whitlockjc I still have a problem with UNRESOLVABLE_REFERENCE. CategoryModel:
type: object
properties:
_id:
type: string
description: category name (id)
displayName:
type: string
description: category display name
imgUrl:
type: string
description: category image url
parent:
$ref: "#/definitions/CategoryModel"
ancestors:
type: array
items:
$ref: "#/definitions/CategoryModel" While sending a request I get the following error: {
"code": "INVALID_REQUEST_PARAMETER",
"errors": [
{
"code": "UNRESOLVABLE_REFERENCE",
"params": [
"#/definitions/CategoryModel"
],
"message": "Reference could not be resolved: #/definitions/CategoryModel",
"path": [
"properties",
"ancestors",
"items"
]
},
{
"code": "UNRESOLVABLE_REFERENCE",
"params": [
"#/definitions/CategoryModel"
],
"message": "Reference could not be resolved: #/definitions/CategoryModel",
"path": [
"properties",
"parent"
]
}
],
"in": "body",
"message": "Invalid parameter (CategoryModel): Value failed JSON Schema validation",
"name": "CategoryModel",
"path": [
"paths",
"/categories",
"post",
"parameters",
"0"
]
} Please could you take a look at it what am I missing? |
I'll need more information. What I see suggests there is no issue but I've no idea what you document(s) structure looks like. |
Here's my whole swagger.yaml And I'm sending the following documents in body: {
"_id": "cat1"
} example2: {
"_id": "cat2",
"parent": {
"_id": "cat1"
}
} If you need further information, just tell |
Can you tell me how the document is being used? If I validate the document, it validates without error. Are you using some APIs that might not be working properly? |
I use swagger-node with updated swagger-node-runner and swagger-express-mw and sway. This week I will try to debug the process if this doesn't help. |
|
Hi, I found the issue:) Please can you fix sway to call json-refs with Or maybe change the logic of the Thanks. |
I'll file a new issue. If you haven't seen it by the time you read this, feel free to do the same. |
Hi, thanks. I filed issue #165 |
You can already use |
Sway is a fantastic library for doing different swagger validations. However, in the initial days I had several issues with resolving json reference around relative paths or circular references. I ended up writing my swagger spec resolver such that all the references are local to the document. I then give the resolved swagger to sway for doing semantic and model validation. After that everything works like a charm. You can use the command |
I'm not sure this is the proper way to address concerns. I'd rather see issues that can be fixed than discussing things in one issue about other issues. Also, |
I have opened :
|
I'm getting this issue at the moment and am trying to debug to get more info for you. From what I can tell, it's from the following lines: sway/lib/types/parameter-value.js Lines 122 to 125 in ee83295
The call to |
this is with [email protected], sway@master and [email protected] @whitlockjc are you saying above that Or, if it can contain references, where is it supposed to look up the definitions. If the former, I guess the issue I'm having is with swagger-node-runner (the call to operation:validateRequest from fittings/swagger_validator) as it should be passing in an already resolved schema for the parameter but is not. |
would it help if I create an example that reproduces this? |
|
Since you mention |
I’m using a fork of swagger node runner and am using sway@master |
Then I'll need to know more about the reproduction. |
After writing the example, I am pretty sure it's the same as issue #165 |
Output
helper.validateAgainstSchema(validator, schema, value)
is called.Link to the spec is here.
Please run this script to verify the behavior.
The text was updated successfully, but these errors were encountered: