# OpenAPIKit

**URL:** <https://forums.swift.org/t/openapikit/32572>\
**Category:** Pitches\
**Tags:** openapi\
**Created:** [January 14, 2020, 8:07am UTC](https://forums.swift.org/t/openapikit/32572 "2020-01-14T08:07:22Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![tonyarnold](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tonyarnold/32/30924_2.png) [@tonyarnold](https://forums.swift.org/u/tonyarnold)\
**Post date:** [March 6, 2020, 12:03am UTC](https://forums.swift.org/t/openapikit/32572/21 "2020-03-06T00:03:59Z")

</div>

Does raise the question whether there should be an OutputFormatting option for `stableKeyOrder` or similar. I feel an SE proposal coming on… 💫

---

<div class="post-metadata">

**Author:** ![mattpolzin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mattpolzin/32/6041_2.png) [@mattpolzin](https://forums.swift.org/u/mattpolzin)\
**Post date:** [March 6, 2020, 12:21am UTC](https://forums.swift.org/t/openapikit/32572/22 "2020-03-06T00:21:48Z")

</div>

Easier said than done, I fear. `JSONEncoder` and `JSONDecoder` use Foundation `NSDictionary` under the hood (at least for the open source version of Foundation). That would need to be swapped out for an ordered hash of some kind in order to facilitate the new feature and even then I am not sure off the top of my head whether `JSONSerialization` would play nicely with the goal of stable ordering.

---

<div class="post-metadata">

**Author:** ![tonyarnold](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tonyarnold/32/30924_2.png) [@tonyarnold](https://forums.swift.org/u/tonyarnold)\
**Post date:** [March 6, 2020, 12:28am UTC](https://forums.swift.org/t/openapikit/32572/23 "2020-03-06T00:28:47Z")

</div>

Is stable ordering even a feature of JSON in other implementations, or have I wandered off into the bushes here?

---

<div class="post-metadata">

**Author:** ![mattpolzin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mattpolzin/32/6041_2.png) [@mattpolzin](https://forums.swift.org/u/mattpolzin)\
**Post date:** [March 6, 2020, 1:01am UTC](https://forums.swift.org/t/openapikit/32572/24 "2020-03-06T01:01:44Z")

</div>

Yeah, it’s pretty common in my experience for ordering of hashes to remain stable while parsing JSON. `FineJSON` is an example of a Swift Encoder/Decoder that retains ordering. The popular `Yams` Encoder/Decoder for YAML also retains ordering. So, given an implementation like OpenAPIKit that is capable of holding onto that ordering, we do already have some options for encoding and decoding. Of course, if ordering is not important for a particular use-case, the Foundation’s JSONEncoder and JSONDecoder are great!

---

<div class="post-metadata">

**Author:** ![tonyarnold](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tonyarnold/32/30924_2.png) [@tonyarnold](https://forums.swift.org/u/tonyarnold)\
**Post date:** [March 6, 2020, 1:04am UTC](https://forums.swift.org/t/openapikit/32572/25 "2020-03-06T01:04:53Z")

</div>

Then gosh, if it's common elsewhere, Foundation's implementation should probably be doing the correct thing here, too. I've hit it in a few places when working with things like the `PropertyListSerialization` classes, where order can be important but is lost anytime you run through one of the serializers.

Anyway, sorry to derail the OpenAPIKit thread - back on topic - I'm super excited about this work, too!

---

<div class="post-metadata">

**Author:** ![mattpolzin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mattpolzin/32/6041_2.png) [@mattpolzin](https://forums.swift.org/u/mattpolzin)\
**Post date:** [March 7, 2020, 2:14am UTC](https://forums.swift.org/t/openapikit/32572/26 "2020-03-07T02:14:29Z")

</div>

Proposal thread created [here](https://forums.swift.org/t/discussion-openapikit/34374).

[Previous page](https://forums.swift.org/t/openapikit/32572.md?page=1)
