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
Feature Request: Convert object patternProperties string regex to Record<string, type> #341
Comments
That sounds interesting 🤔 I will need to read up on patternproperties to fully wrap my head around this. To further understand your proposal, are you using |
Yeah so patternProperties just provides a way for you to enforce object property value types based on dynamic property key names that aren't known in advance. The JSON spec only provides support for regular expressions, so the convention is to use a regex like Again this transformation would only be applied in this specific case - when patternProperties is set to exactly one known regular expression that means "any string" and no other object properties are explicitly specified. Despite types of the form |
Thank you for elaborating. As of now I'd say: Not this year since I'll be minimizing OSS work during December. In general I agree with your points. I would also like to see a plugin system (ref #293) If it only requires minimal changes to the codebase it would help me access the impact of the change if you could provide a PR. I can't promise I'll be able to merge it soon though. |
I've often validated types like
Record<string, SomeInterface>
using json schema's "patternProperties" option with the regular expression^.*$
. Currently oazapfts converts a spec like:to
object
when ideally it could produceRecord<string, { name: string }>
Checking for a specific regular expression string like
^.*$
feels a little wonky, but then again, this approach is fairly ubiquitous in the wild. Libraries like typebox convert Record<string, SomeInterface> to exactly this and I think support could be included with very little code and no breaking changes. If the type included any other regular expression for patternProperties or the top level object had any explicitly defined properties, the existing behavior would be preserved.Would a PR supporting this feature get merged?
The text was updated successfully, but these errors were encountered: