json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

[bug] pass json-schema-to-typescript parser to refResolver as default .json resolver

Open Hulkmaster opened this issue 5 years ago • 5 comments

So we have project with structure like

project/apidocs/entitity project/apidocs/response project/ts-apidocs/entitity project/ts-apidocs/response

if we launch cli tool like cd apidocs && json2ts -i ./response/**/*.json -o ../ts-apidocs

we have a file ./apidocs/response/Something.json which has reference "$ref": "../entity/Something-2.json"

and our something-2.json

has required properties, for example, id

if we would generate Something-2.json directly, then .ts files will have property as required but if type would be generates via $ref, then property will be marked as optional

so i guess direct converting and converting via $ref uses different rules, and $ref converting has a bug

Hulkmaster avatar Jul 20 '20 11:07 Hulkmaster

i guess the reason is here https://github.com/bcherny/json-schema-to-typescript/blob/1ec105d1f00f23969bd057fe151ff952a7280e3d/src/index.ts#L64 https://github.com/APIDevTools/json-schema-ref-parser/blob/a4eec2ba56d793c410fb884a06f5eb9dfba4e412/lib/options.js#L32

so the solution will be to pass json parser to ref-parser that lib by default

also i'm not sure if its possible to pass it from cli currently

Hulkmaster avatar Jul 20 '20 12:07 Hulkmaster

We've run into this bug as well. It causes us some problems.

What are your thoughts on this @bcherny ?

memark avatar Aug 21 '20 15:08 memark

Hey, sorry for the delayed response. Not sure I totally understand the issue -- mind spelling it out a bit more, and providing a complete, whittled down repro case?

bcherny avatar Nov 29 '20 03:11 bcherny

When lib is trying to resolve references, it uses different parser

I would suggest to use recursive (using same lib) approach for resolving references

Hulkmaster avatar Nov 29 '20 10:11 Hulkmaster

accidentally closed

Hulkmaster avatar Nov 29 '20 19:11 Hulkmaster