Skip to content
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

feat request: Schema.prototype.meta(key, value) #20

Closed
undefined-moe opened this issue Aug 18, 2022 · 7 comments
Closed

feat request: Schema.prototype.meta(key, value) #20

undefined-moe opened this issue Aug 18, 2022 · 7 comments

Comments

@undefined-moe
Copy link
Contributor

const bar = Schema.dict(Schema.string().meta(key, value))

seems much better than

const foo = Schema.string();
foo.meta || = {};
foo.meta[key] = value
const bar = Schema.dict(foo)
@shigma
Copy link
Owner

shigma commented Aug 18, 2022

schema.meta is not designed to be extensible, and the requested feature may lead to incompatible behavior. If you need more meta fields, please specify your needs directly.

@undefined-moe
Copy link
Contributor Author

  1. Schema.string().pattern(regex)
  2. Schema.string().examples(values)
  3. Schema.string().deprecated()
  4. Schema.array().minLength(min).maxLength(max)

@undefined-moe
Copy link
Contributor Author

related to #8 and #11 .

@shigma
Copy link
Owner

shigma commented Aug 18, 2022

None of the ones you mentioned should be meta properties. You can request these features in separate issues.

@shigma
Copy link
Owner

shigma commented Aug 18, 2022

Even if they are meta properties, I don't think this should be freely specified by the user. All constraints should be given by methods on the prototype chain.

@undefined-moe
Copy link
Contributor Author

As meta field designed to be a dict with no type limitations, It should allow users store whatever they want, JSON-safe of course, and simply transmit the schema and what they need between backend and frontend. It provides a possibility. Otherwise, if an extra field is really needed in some special case, users might use something like Schema.string().description('{"foo":1,"bar":true}') and decode them in client-side, which I think would be much worse.

@shigma
Copy link
Owner

shigma commented Aug 18, 2022

You have already given a workaround at the beginning of this issue, so the requested API is not necessary. Instead, the requested API increases vulnerability both in typings and runtime. If you just need schema.example() or other methods, PRs are always welcome.

@shigma shigma closed this as completed in 10ea36d Sep 17, 2023
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

2 participants