-
Notifications
You must be signed in to change notification settings - Fork 90
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
Cannot read property 'type' of null when linting OpenAPI files #180
Comments
At the point of this processing, I don't believe we have a filename to print. This code is operating on a But there may be a clue that can help find the problem. The code that failed looks like this:
The last line is the line that failed, attempting to reference |
Recently, I ran across an issue where [if the validator throws an exception in a specific part of the code, the path to the exception-causing code is swallowed](IBM#180). After a moderate amount of digging, I decided that an option for providing more information about this code would be to put the path to the problematic element or elememnts into the exception message. This exception message is displayed whenever the code crashes out. So, for example, the previous error message output by lint-openapi was the following: ``` Validation Results for epic_tenant.json: [Error] There was a problem with a validator. Cannot read property 'type' of null TypeError: Cannot read property 'type' of null at arrayOctetSequences (/usr/local/lib/node_modules/ ibm-openapi-validator/src/ plugins/utils/ findOctetSequencePaths.js:39:20) at findOctetSequencePaths (/usr/local/lib/node_modules/ ibm-openapi-validator/src/ plugins/utils/ findOctetSequencePaths.js:22:34) at /usr/local/lib/node_modules/ibm-openapi-validator/ src/plugins/utils/ findOctetSequencePaths.js:72:14 at Array.forEach (<anonymous>) at objectOctetSequences (/usr/local/lib/node_modules/ ibm-openapi-validator/src/ plugins/utils/ findOctetSequencePaths.js:58:35) at findOctetSequencePaths (/usr/local/lib/node_modules/ ibm-openapi-validator/src/ plugins/utils/ findOctetSequencePaths.js:24:34) at /usr/local/lib/node_modules/ ibm-openapi-validator/src/ plugins/utils/ findOctetSequencePaths.js:72:14 at Array.forEach (<anonymous>) at objectOctetSequences (/usr/local/lib/node_modules/ ibm-openapi-validator/src/ plugins/utils/ findOctetSequencePaths.js:58:35) at findOctetSequencePaths (/usr/local/lib/node_modules/ ibm-openapi-validator/src/ plugins/utils/ findOctetSequencePaths.js:24:34) ``` After this change, the output should be the following: ``` [Error] There was a problem with a validator. items.type and items.format must resolve for the path "paths/my/datatype/path/etc/etc" TypeError: Cannot read property 'type' of null at arrayOctetSequences (/usr/local/lib/node_modules/ ibm-openapi-validator/src/ plugins/utils/ findOctetSequencePaths.js:39:22) (same stack as above, I would rather not edit it again) ``` Obviously this commit needs some help with unit testing. I would like to submit the PR first and then get feedback from the maintainer on how much testing is needed for this change.
… element on exception Recently, I ran across an issue where [if the validator throws an exception in a specific part of the code, the path to the exception-causing code is swallowed](IBM#180). After a moderate amount of digging, I decided that an option for providing more information about this code would be to put the path to the problematic element or elements into the exception message. This exception message is displayed whenever the code crashes out. So, for example, the previous error message output by lint-openapi would say "Cannot read property 'type' of null", whereas the new error would list the full path to the type that was causing the exception. re IBM#180
… element on exception Recently, I ran across an issue where [if the validator throws an exception in a specific part of the code, the path to the exception-causing code is swallowed](IBM#180). After a moderate amount of digging, I decided that an option for providing more information about this code would be to put the path to the problematic element or elements into the exception message. This exception message is displayed whenever the code crashes out. So, for example, the previous error message output by lint-openapi would say "Cannot read property 'type' of null", whereas the new error would list the full path to the type that was causing the exception. re IBM#180
… element on exception Recently, I ran across an issue where [if the validator throws an exception in a specific part of the code, the path to the exception-causing code is swallowed](IBM#180). After a moderate amount of digging, I decided that an option for providing more information about this code would be to put the path to the problematic element or elements into the exception message. This exception message is displayed whenever the code crashes out. So, for example, the previous error message output by lint-openapi would say "Cannot read property 'type' of null", whereas the new error would list the full path to the type that was causing the exception. re IBM#180
I was just about to tag somebody in the PR, but I see that there is activity on this ticket. I'll hold my peace for now. |
@jorge-ibm was @mkistler going to work on this? If not, @distortedsignal, we would welcome the PR! |
Yes I think @mkistler was going to take a look, but I agree. @distortedsignal if you have a PR for this already please feel free to submit it |
I sent a PR to add the path to the exception text. I figure the best way to report to the user that their OpenAPI spec is not valid is to point them to where the invalid spec is. Check out the PR here: #190 |
… element on exception Recently, I ran across an issue where [if the validator throws an exception in a specific part of the code, the path to the exception-causing code is swallowed](IBM#180). After a moderate amount of digging, I decided that an option for providing more information about this code would be to put the path to the problematic element or elements into the exception message. This exception message is displayed whenever the code crashes out. So, for example, the previous error message output by lint-openapi would say "Cannot read property 'type' of null", whereas the new error would list the full path to the type that was causing the exception. re IBM#180
* fix(src/plugins/utils/findOctetSequencePaths.js): Show path to erring element on exception Recently, I ran across an issue where [if the validator throws an exception in a specific part of the code, the path to the exception-causing code is swallowed](#180). After a moderate amount of digging, I decided that an option for providing more information about this code would be to put the path to the problematic element or elements into the exception message. This exception message is displayed whenever the code crashes out. So, for example, the previous error message output by lint-openapi would say "Cannot read property 'type' of null", whereas the new error would list the full path to the type that was causing the exception. re #180
Resolved in #190 @distortedsignal Let me know if that PR doesn't fully resolve the issue. Thanks for the PR! |
I think the PR resolves the issue enough. It will at least tell you where the data types are that are causing the issue. This is as much as can be asked for when dealing with faulty API documentation. |
I'm the same guy from this issue, this is a problem with a different Open API file.
My team is changing over to Open API 3.0 documentation from RAML, and I'm trying to build up a linter from this tool. Our API is (fairly) complex and our data structures are deeply nested. I recently ran into an issue where one of our *.json files couldn't be linted because of a type deref on a null.
Local information
Installed via
npm
with the-g
flag.In the directory that I'm linting:
> lint-openapi -v 0.28.0
The call that makes the error happen, and output:
I feel like this is pretty hard to debug because the file splay of our API documentation means that I'm not entirely sure where this error is being hit. Would it be possible to print the name of the file (or, even better, the name of the object/path of the object) that procs the error?
The text was updated successfully, but these errors were encountered: