-
Notifications
You must be signed in to change notification settings - Fork 9.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
need a way to specify non-const default field values (e.g.: current timestamp) #554
Comments
+1 I actually even have a case where the timestamp field's default value is a delta on the current time (UTC + 5 Minutes). BTW, The field is defined as a number, since we pass unix epoch - like this one 1454942158. |
👍 |
Are there other use cases outside of timestamps for dynamic defaults you have in mind? This seems to open up a range of syntax we'd have to codify. |
@jasonh-n-austin - I agree and I was actually thinking about it a lot, and after looking at default value expressions in Databases, I've categorized main 4 types:
I think (2) is not a lot of support and (obviously) needed, but I agree (3) can be, and we should not support it (right now). I don't think (4) is a frequent use case for a REST API and I don't think we need it at all. |
@jasonh-n-austin - Personally, I only need to be able to pass timestamps relative to now (+delta) as default arguments. I didn't have any other specific use cases in mind, but I thought it best to make this request as generic as possible. I'd agree with @lieldulev 's description of the four main types of possible default values. Supporting type (3) would be really nice, but what I am really asking for is type (2) |
Excellent point to look at database defaults @lieldulev. To summarize requirements:
An obvious aspect of this would be a language-agnostic syntax for date expressions in the It would be really nice to have an existing syntax to work from; preferably something that already has existing specs & implementations. As I don't know of anything like this, the first thing that comes to mind is Excel syntax...? The other aspect to consider is a syntax for adding dynamically evaluation, something like:
|
@jasonh-n-austin, yep, nailed it.
And while I'm sure we can find a hundred more - I would actually stick to either Excel or SQL:
|
Definitely not liking any of the alternatives, as they are all pretty language or vendor specific. ANSI SQL might have some value, but it just seems odd to use database syntax in an API definition (not that Excel really feels right either). Playing with Excel formulas more, it's pretty gross in practice, when it comes to formatting dates. Examples:
Seems like something more date format friendly would be nice. This issue is tricky when it comes to the syntax piece. |
I agree, picking syntax is a big problem since it might affect other decisions down the road. How about we allow tagging the language? Something like
or maybe using the
Both languages will be "valid" but one of them might not be supported by all generators. |
I'd suggest if we go ahead and try to resolve this issue, that we keep it simple. We definitely shouldn't allow for something that's more language-specific, that would be a tooling nightmare. We can go with some basic construct of our own, even if it doesn't cover all cases. |
👍 for @webron being the voice of reason while I am getting carried away :) |
couple things to consider:
I think only good usage scenario for such field is interactive documentation. |
My 2 cents. It seems like this is a great candidate to leave as a vendor extension with specific conventions. A curated |
@IvanGoncharov - good points,
I agree it has more value in interactive apis (like swagger ui) or generators for unit/load testing (where the actual call needs to have "good" values to be meaningful). |
I am on the side of @dilipkrish. This seems very specific to tooling and probably too complicated to have in the spec itself. For a vendor extension, the tooling provider would optionally support the construct. |
After exploring the possibilities and stewing on it a bit, I agree. |
We have a requirement to indicate client whether a property has a default value or not. The client then can send the minimal set of data and exclude the ones with default value. |
I'm going to tag this as a tooling consideration. Seems like some construct of extensions + tooling support can make for dynamic content. But it should likely stay out of the spec itself. |
Tackling PR: #741 (even though it may not get it, that's the point of consideration. The result of the PR may close this ticket as "not supported"). |
I'm not sure such kind of "default" values are needed at all. Shouldn't the server be able to supply the value when it is missing? Why should this be provided by the client? |
As suspected, this did not make it into the spec, and it's marked as a potential tooling feature with the use of extensions. |
There currently is no standard way to specify a non-constant / computed value to be used as the default value of a field.
We have a few endpoints that take a timestamp as an argument. For the sake of our swagger documentation interacting with the most current data, we'd like this field to be pre-populated with the current timestamp, rather than a const value written in the swagger spec file.
Of course, we can hack the swagger UI somehow to treat certain specific fields differently, but I thought such a feature would be useful to others as well.
The text was updated successfully, but these errors were encountered: