Skip to content

TypeError: Cannot convert undefined or null to object #360

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

Closed
rendall opened this issue Nov 12, 2020 · 4 comments
Closed

TypeError: Cannot convert undefined or null to object #360

rendall opened this issue Nov 12, 2020 · 4 comments

Comments

@rendall
Copy link
Contributor

rendall commented Nov 12, 2020

Summary: TypeError when attempting to convert valid spec

Detail: This spec passes validity tests https://github.com/rendall/simple-comment/blob/master/src/schema/simple-comment-api.json but attempting to convert it yields the following error (with stack trace):

✨ openapi-typescript 2.4.0
🤞 Loading spec from https://raw.githubusercontent.com/rendall/simple-comment/master/src/schema/simple-comment-api.json…
TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at transformOperation (...\npm-cache\_npx\13920\node_modules\openapi-typescript\dist-node\index.js:428:12)
    at ...\npm-cache\_npx\13920\node_modules\openapi-typescript\dist-node\index.js:461:39
    at Array.forEach (<anonymous>)
    at ...\npm-cache\_npx\13920\node_modules\openapi-typescript\dist-node\index.js:452:31
    at Array.forEach (<anonymous>)
    at transformPaths (...\Roaming\npm-cache\_npx\13920\node_modules\openapi-typescript\dist-node\index.js:450:27)
    at generateTypesV3 (...\npm-cache\_npx\13920\node_modules\openapi-typescript\dist-node\index.js:485:5)
    at swaggerToTS (...\npm-cache\_npx\13920\node_modules\openapi-typescript\dist-node\index.js:545:32)
    at ...\npm-cache\_npx\13920\node_modules\openapi-typescript\bin\cli.js:56:18

Reproduce:

npx openapi-typescript https://raw.githubusercontent.com/rendall/simple-comment/master/src/schema/simple-comment-api.json --output schema.ts

Expected:

Either conversion or helpful error message

Compliment, pep talk:

It's just great that you all have made this, and I want to congratulate you on making such a useful tool!

@gr2m
Copy link
Contributor

gr2m commented Nov 12, 2020

Bug seems to be that we do not handle the "summary" key on the paths level. We currently only ignore the parameters key: https://github.com/drwpow/openapi-typescript/blob/1a74e25b496ffa072c912a3fa57bb66462dbf0ca/src/v3.ts#L269 and don't do any further checks whether the operation value from line 528 is an actual operation.

I think we should make a hardcoded list of all http methods and iterate through them.

Would you like to attempt sending a pull request @rendall? I'd start by creating a failing test in tests/v3/index.test.ts, create a schema that has the summary on the same level as a get operation, that should reproduce the error you see, then we can take it from there?

@rendall
Copy link
Contributor Author

rendall commented Nov 13, 2020

I'll do this

@rendall
Copy link
Contributor Author

rendall commented Nov 19, 2020

A typo in that PR referred to the wrong issue, so, closing this manually

@rendall rendall closed this as completed Nov 19, 2020
@Bishwas-py
Copy link

Bishwas-py commented Mar 21, 2024

Was getting the same issue in the lastest installation:

TypeError: Cannot convert undefined or null to object

Fix:
In your dist/lib/utils.js, line 79:

export function getEntries(obj, options) {
    if (!obj) {
        return [];
    } // add this
    let entries = Object.entries(obj);
    if (options?.alphabetize) {
        entries.sort(([a], [b]) => a.localeCompare(b, "en-us", { numeric: true }));
    }
    if (options?.excludeDeprecated) {
        entries = entries.filter(([, v]) => !(v && typeof v === "object" && "deprecated" in v && v.deprecated));
    }
    return entries;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants