Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

(node:46891) UnhandledPromiseRejectionWarning: Error: Not found #30

Open
cyberixae opened this issue Apr 9, 2019 · 12 comments
Open

(node:46891) UnhandledPromiseRejectionWarning: Error: Not found #30

cyberixae opened this issue Apr 9, 2019 · 12 comments

Comments

@cyberixae
Copy link

I'm getting a crash while running schema-script against schemas from maas-schemas npm package

(node:46894) UnhandledPromiseRejectionWarning: Error: Not found
    at SchemaSet.lookup (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/lib/SchemaSet.js:13:19)
    at toIR (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/lib/generator.js:35:22)
    at t.interfaceCombinator.Object.keys.map (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/lib/generator.js:20:32)
    at Array.map (<anonymous>)
    at toInterfaceCombinator (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/lib/generator.js:15:10)
    at Object.toIR (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/lib/generator.js:60:20)
    at Preprocessor.generateStaticCode (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/lib/Preprocessor.js:50:54)
    at Preprocessor.compileSchema (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/lib/Preprocessor.js:44:19)
    at Preprocessor.compile (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/lib/Preprocessor.js:27:33)
    at App.run (/Users/twruottu/.config/yarn/global/node_modules/schema-script/dist/app.js:12:35)
(node:46894) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:46894) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@cyberixae
Copy link
Author

I renamed the files to have the .schema.json suffix and added "$comment": "+ts +iots", to schemas/core/booking.schema.json.

@OrKoN
Copy link
Owner

OrKoN commented Apr 9, 2019

@cyberixae thanks for reporting it! Would it be possible to open a PR and add the failing schema to the examples folder https://github.com/OrKoN/schema-script/tree/master/examples? Otherwise, I will try to take a look as soon as I can. I suspect that the schema you use references some other schema which is missing.

@cyberixae
Copy link
Author

The error seems to be caused by the reference "$ref": "components/units.json#/definitions/uuid". The said reference is relative to the defining schema document and it also contains a path to a specific part fo the referred schema document. Maybe one or the other is the reason for the problem. The file is available in GitHub at https://github.com/maasglobal/maas-schemas/blob/develop/schemas/core/booking.json but including the entire file as test data for schema-script feels a bit excessive.

@cyberixae
Copy link
Author

@OrKoN
Copy link
Owner

OrKoN commented Apr 9, 2019

@cyberixae I checked the case and, yeah, it won't work with the current implementation. Currently, schema-script requires a model per JSON schema and the support for the JSON schema references is limited.

If you'd like to try to solve this problem, I had some thoughts:

  1. maybe $comment attribute can indicate specific schemas or sub-schemas as a model so that within one file there could be multiple models
  2. relative references need to be supported completely
  3. support for schemas that only contain definitions need to be better

So to summarize, only JSON schema patterns you see in the examples folder are supported. If you'd like to contribute improvements, I will be happy.

@OrKoN
Copy link
Owner

OrKoN commented Apr 9, 2019

I was looking to utilize https://github.com/APIDevTools/json-schema-ref-parser to resolve $ref but didn't have time to learn it

@cyberixae
Copy link
Author

Getting this issue resolved is not a high priority for me at the moment. I only need a few fields so typing them by hand is not a problem. However, schema-script might be a nice solution at some point if the amount of types we are using increases.

@cyberixae
Copy link
Author

Have you considered replacing the test schemas with an existing schema examples package? Maybe https://github.com/json-schema-org/JSON-Schema-Test-Suite It seems to be available as an npm package. Perhaps it would be possible to skip tests that are not passing at the moment. It would be interesting to know how many test cases are passing/failing at the moment.

@OrKoN
Copy link
Owner

OrKoN commented Apr 10, 2019

That would be interesting but, honestly, I won't have time for it at the moment. I am open for contributions though :-)

Btw, you could try https://quicktype.io/, https://github.com/bcherny/json-schema-to-typescript These are some alternatives that I know.

@cyberixae
Copy link
Author

Ok. No problem. It's good to have alternatives, although I would imagine schema-script is the only tool that generates io-ts types in addition to static typing.

@cyberixae
Copy link
Author

I started drafting a conversion utility that targets the specific features set that we have in maas-schemas code base. The code lives at https://github.com/maasglobal/maas-schemas-ts/blob/master/converter.ts for the time being.

@cyberixae
Copy link
Author

I moved the tool into a separate package. See https://www.npmjs.com/package/io-ts-from-json-schema

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

No branches or pull requests

2 participants