-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Define a required parameter using a sugar API #1940
Comments
i think @param.query.required() format: string it's very cool isn't? |
@mdbetancourt Your proposal looks nice. Please keep in mind that the parameter name cannot be inferred at runtime, it must be provided by the developer. @param.query.required('format') format: string Often the developer needs to provide the type too, so we will end up with quite few @param.path.number.required('id') id: number In general, there are more |
I had certainly forgotten 😄 since required is a common use case we can use @param.query.require.string('format') or @param.require.query.string('format') feels natural and similar to chai style (which we are already using for tests) and of course we should try to keep it simple (at least for builtin type which can be inferred) @param.require.query('format')
format: string
// for complex types
@param.require.type(Type).query('format')
format: Type
// arrays
@param.require.array.type(Type).query('format')
format: Type[]
// or
@param.require.string.array.query('format')
format: Type[] what do you think? maybe too large? |
I don't have a strong opinion. I guess it depends on how much time you want to invest into building a chain-style API? I think it would be best to start with adding a new argument accepting I feel it's important to preserve backwards compatibility here, so even if we implement |
I'm not a big fan to have a very long decorator. It would be better to add an optional argument for the sugar decorators to accept additional information, such as: @param.query.string('access_token', {required: true}) The 2nd argument should be typed as |
I'm interested in contributing to this one!
|
Cool! Sorry for the long silence on our side 🙈
I believe that's already handled by our REST validation layer. This GH issue is about adding a shorter way how to define required parameters in the code.
Yes please 👍 |
Hello @bajtos, no worries, and sorry it took me a while to answer too :)
Ok thanks
Can I still take a look at this one, if still available ? |
At the moment, it is not possible to use
@param
shortcuts like@param.query.string
to define a required parameter.One has to use
@param
directly (but don't have to specify the type since LB4 can infer the type from TypeScript metadata). For example:Ideally, I would like LB4 to provide the following syntax for annotating parameters as required:
Acceptance criteria
@param.SOURCE.TYPE()
shortcuts (and possibly other similar shortucts) to accept a new optional argument of typePartial<ParameterObject>
and use the provided properties to enhance (or amend) the spec generated by the decorator.@param.array()
in a similar way, the new optional argument will be the fourth arg.@param.query.object()
similarly, the new optional argument will be the third arg.🎆 Hacktoberfest 2020
Greetings 👋 to all Hacktoberfest 2020 participants!
Here are few tips 👀 to make your start easier, see also #6456:
#loopback-contributors
channel, you can join our Slack workspace here.The text was updated successfully, but these errors were encountered: