You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
but I'm not sure if that's in the scope of this project. I saw #456, but as far as I understand it, that only allows changing the interface name before1 the incrementing number is appended, not after (so the same as just setting the title).
Ideally, I'd want a way to hard override the generated interface name. "Trust me, this is a Point, don't complain about duplicates"2.
As a more complex alternative, this package could "detect" identical properties (with or without matching titles) and reuse the interfacces generated from those. Again, this might be out of scope - we're starting to shift from parse+generate into ✨ magic ✨
Any advice? I'd also be fine with a hacky workaround, can't be worse than regexing through my .ts file3 :^)
I'm already committing a kind of crime here: I take in lots of schemas and compile them individually, all into one file. I run ts-dedupe on that file which gets rid of interfaces with the same name. This helps a lot when multiple schemas define a "title": "point" somewhere, but can't duplicates within a schema by itself. ts-dedupe only compares interface names, not their contents/definitions. ↩
As a final note: I don't have to have neat types, since I can just create my own Point interface and use that everywhere. After all, typescript will let identical types from different definitions "fit onto" each other. As long as nobody looks at the schemas' type definitions, the 10 different PointXX interfaces aren't noticable ↩
The text was updated successfully, but these errors were encountered:
One approach you suggested could work: if two schemas are (a) identical and (b) have the same explicit title, then emit just one type to represent the schema. We could implement this as a normalizer step that mutates a schema to instead be a $ref to the property it duplicates. Happy to stamp a PR if you'd like to take a pass at this.
Example: A rectangle schema with two corners. Both corners are the same type and most importantly share a
title
.I know this isn't an ideal schema (should ref in the points), but sometimes you just get bad data from somewhere.
this turns into
which is correct, I guess? after all, I'm putting garbage in and get garbage out. I'd prefer to get something like
but I'm not sure if that's in the scope of this project. I saw #456, but as far as I understand it, that only allows changing the interface name before1 the incrementing number is appended, not after (so the same as just setting the title).
Ideally, I'd want a way to hard override the generated interface name. "Trust me, this is a
Point
, don't complain about duplicates"2.As a more complex alternative, this package could "detect" identical properties (with or without matching titles) and reuse the interfacces generated from those. Again, this might be out of scope - we're starting to shift from parse+generate into ✨ magic ✨
Any advice? I'd also be fine with a hacky workaround, can't be worse than regexing through my .ts file3 :^)
Footnotes
see https://github.com/bcherny/json-schema-to-typescript/pull/456/files#diff-abe2818e9c29aadf84401cb7ef8286c7cbce9253eba09f6fa52e22ca4e57b17eR303-R305 -
generateName
is called after the override and adds a counter ↩I'm already committing a kind of crime here: I take in lots of schemas and compile them individually, all into one file. I run ts-dedupe on that file which gets rid of interfaces with the same name. This helps a lot when multiple schemas define a
"title": "point"
somewhere, but can't duplicates within a schema by itself. ts-dedupe only compares interface names, not their contents/definitions. ↩As a final note: I don't have to have neat types, since I can just create my own
Point
interface and use that everywhere. After all, typescript will let identical types from different definitions "fit onto" each other. As long as nobody looks at the schemas' type definitions, the 10 differentPointXX
interfaces aren't noticable ↩The text was updated successfully, but these errors were encountered: