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

Support nested values #8

Closed
tfausak opened this issue Apr 18, 2020 · 4 comments
Closed

Support nested values #8

tfausak opened this issue Apr 18, 2020 · 4 comments

Comments

@tfausak
Copy link
Owner

tfausak commented Apr 18, 2020

I'm not sure how I missed this so far, but section 2.4.2 of the RFC says:

Structures are processed as if they are an associative array with names corresponding to the fields in the structure definition and "." separators used to indicate name hierarchy in substructures.

Currently Burrito only allows "simple" structures: a string, a list of strings, or a map from strings to strings. That should be expanded to allow nested values.

This also suggests that the representation for variable names should be some type of non-empty list. The elements would be separated by periods, representing potential nesting of values.

@tfausak
Copy link
Owner Author

tfausak commented Apr 18, 2020

This part of the RFC feels very under specified to me. For example, what should expanding {a.b} with a.b =: "foo" be? Both "foo" and "" make sense to me. Currently Burrito would return "foo", but perhaps "" makes more sense. Only a =: [b =: "foo"] would return "foo".

Annoyingly the official test suite doesn't touch on this at all.

@tfausak
Copy link
Owner Author

tfausak commented Apr 18, 2020

Ah, there actually is a test for this: https://github.com/uri-templates/uritemplate-test/blob/520fdd8b0f78779d12178c357a986e0e727f4bd0/extended-tests.json#L14

If that can be trusted, Burrito currently does the right thing.

@tfausak
Copy link
Owner Author

tfausak commented Apr 18, 2020

I'm not sure where I land on this. On one hand, the RFC does clearly allow for values to be nested. On the other hand, it's so under specified that I feel there's no way to implement it in an unsurprising way. For example:

  • How does {a.b} expand with a =: [b =: "1"], a.b =: "2"? In other words, which one wins?
    • Continuing on this, let's arbitrarily pick the dictionary to win, so the template expands to "1". What happens if we drop the dictionary from the values? Does the template then expand to "2" or ""?
  • Is it possible to index into lists? Would expanding {a.0} with a =: ["A"] result in "A"?
  • How are nested values expanded when the names are included? Would expanding {?a.b} with a =: [b =: "1"] result in ?a.b=1 or ?a=b%3D1 or ?a[b]=1 or something else entirely?
    • Same question but for the explode modifier. How would {a.b*} expand?

All this gets further complicated when you consider doing expansion in reverse (#4).

I think it would be reasonable to say that Burrito doesn't support this. If this is a feature that people are interested in, they can ask for it.

@tfausak
Copy link
Owner Author

tfausak commented Apr 19, 2020

For the time being I am not going to allow this.

@tfausak tfausak closed this as completed Apr 19, 2020
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

1 participant