Consideration for moving from objects to arrays. #32
Replies: 10 comments 16 replies
-
Related: #25 |
Beta Was this translation helpful? Give feedback.
-
The AJV validator already supports a Maybe this could become a standard keyword in a future JSON Schema version, or part of a vocabulary? |
Beta Was this translation helpful? Give feedback.
-
I believe this proposal is interesting, however it creates a tradeoff between the importance of running query filters on user-provided keys and accessing individual elements. Let's start by analyzing the motivation behind this proposal. According to the author, the goal of the proposed change is to make it easier for API practitioners to work with the data represented by OpenAPI definitions.
The examples provided to obtain all the paths that contain the word "pets" make sense. You can clearly see that using JSON object structures makes it harder to obtain all the elements where their keys contain a given string. On the other hand, accessing individual elements becomes more difficult after the proposed changes. Let's take the
While M1 doesn't convey the big difference in effort when using The value of this proposal is, in my opinion, affected by the importance of how you want to read information from an OpenAPI definition. If you feel it's more important to easily filter name-value pairs, then JSON array structures seem to be the appropriate solution. If, on the other hand, you want to access individual elements as easily as possible, then JSON object structures are the preferred solution. |
Beta Was this translation helpful? Give feedback.
-
My initial concern with this is authoring/reading documents would become much harder. For example, Then you have to think about how changes will propagate. Let's say I have a collection of paths and I want to insert one into the middle. I now have to find all places that reference any paths (or children) that are at the inserted index or after and update their values. The authoring experience here is heavily impacted by such a change. I've never been a fan of changes to OAS that were purely for tooling because it often made the authoring/reading of OAS documents more complex. To me, that is the case here. Tooling is exactly where the complexities should be hidden in my opinion, not making it harder for me to author/read documents. |
Beta Was this translation helpful? Give feedback.
-
Just a couple of notes on the plus side of the argument (though I'm not discounting the many cons listed above):
|
Beta Was this translation helpful? Give feedback.
-
IMO the main benefit of using arrays is flexibility. If If you keep using map keys, v5, v6, v7, etc are likely to see more structural changes that send everyone scrambling. Consumers can transform the in-memory structure to anything they want on read. IMO it's better to keep the persisted format consistent, and arrays make that easier. |
Beta Was this translation helpful? Give feedback.
-
One benefit of moving to arrays is that naming things is hard, and it could enable optional names. Requiring names may also make it harder to automatically migrate specs from OAIv3 to v4, as (Personally I'm ambivalent about this proposal, just noting something I hadn't seen previously mentioned) |
Beta Was this translation helpful? Give feedback.
-
From @arno-di-loreto in #25, consolidated here: Thinking aloud about Unless I missed something, the reusable part of a response is what is inside the key.
If
In that case (list), I wonder if sets of responses couldn't be defined. When a $ref is used, it could be a reference to a single response or a set of responses (defined in components.responsesSets) (but that's another story). This question is also a general concern: Are some guidelines defined to help choose one or another in OpenAPI v4 design? Responses as a map:
Responses as a list
|
Beta Was this translation helpful? Give feedback.
-
From @spacether at #90 (comment) How about limiting tag names to the same set of characters that component names are limited to ( Also have tags be a map where the key is the tagName. That structurally prevents tag collisions. |
Beta Was this translation helpful? Give feedback.
-
Coming back to this, I feel like there are a couple of things to resolve: How do we identify things within OADs?This is critical as many of the arguments on this topic have to do with whether things work with JSON Pointers. But JSON Pointers are not our only options, and have downsides beyond difficulty with arrays. This is why JSON Schema offers a location-independent alternative for referencing. OAS 3.x uses several different mechanisms:
It's important to note that we could define URI fragment syntax based on component types and names, which combines aspects of several of the above. How do tags fit in?Tags are different from unique identification (you can tag many things with the same tag). Can we handle all ordering or other organizational/presentation metadata through tags regardless of the underlying structure? Do we want mandatory or optional names?As @rattrayalex noted, naming things is hard, and it might be nicer to not have to do that unless there's a need for a name. That would point towards something like identification option 2 above. Of course some of our objects have natural names (status codes, media types), although in some cases those "natural" mappings have proven problematic when we would ideally have multiple different values for a supposedly "natural" key. Do we want mandatory or optional ordering?Arrays have inherent ordering, and sometimes we might not want that. We could allow a way to indicate that something is unordered. Alternatively, we could add a field to various map entries that sets their relative order. I'm thinking a non-negative integer field where the values need not be contiguous. If we want to get fancy we could allow negative integers to set order from the end as well as the beginnign (off the top of my head, I'd say all negative-ordered entries go at the end, all positive at the beginning, and any missing an ordering go in arbitrary order between the ordered blocks- we would not want to have to compute some sort of overlap between negative and positive relative ordered). Do we want re-use to include names or not?Re-using a map entry divorces it from its name in the map, while re-using an array entry that sets its own name keeps them together. Either way can be either a disadvantage or an advantage. Does this impact what we do? Do we want the same approach or would different use cases be better served by different approaches? I think that if we delve into these questions, it will become more clear what the answer is. Choosing objects or arrays should be about solving some sort of problem, and we first need to figure out what problem(s) it might solve, and then figure out whether there are already better alternatives that we can use. |
Beta Was this translation helpful? Give feedback.
-
With a major version bump and an acceptance of breaking changes from OpenAPI 3.x, I'd like to propose moving from JSON object structures to JSON array structures.
For the purposes of this document, JSON will be the format referenced. Assume YAML support as well.
Motivation
Tooling. That's it. 😅 And the API practitioner experience in using that tooling.
Specifically, running query filters on names in JSON name-value pairs is difficult for lots of tooling and requires deconstructing the definition into an intermediary format. This proposal suggests the OpenAPI document itself could look closer to that intermediary format.
Proposal
With the exception of
components
, convert all objects with dynamic, user-provided keys to arrays of objects, moving the JSON name to aname
property in that object. Modifying the example from the OAI/moonwalk README, it would look something like this:The reasoning behind leaving
components
as-is relates to an attempt to stay close to referencing compatibility with JSON Schema, which relies on JSON Pointer and doesn't have advanced filtering capabilities.Potential Downsides
Curious to hear anyone's thoughts on this!
Beta Was this translation helpful? Give feedback.
All reactions