Skip to content

Conversation

@bwetherfield
Copy link
Collaborator

Overview

Restricts the special case usage of "value" OR "" as a coding key, as implemented in #73 to just "". "value" resumes functioning as a normal coding key.

Example

As noted in #145, "value" is starting to collide awkwardly in one or two cases where it may be implicit per the special case usage

<value-containing>I am implicitly labeled</value-containing>

or explicit, as in

<value-containing>
    <value>I am explicitly labeled</value>
</value-containing>

With the change proposed, the latter example will be unambiguously captured by

struct ValueContaining: Codable {
    let value: String
}

while the former is equivalent to

struct ValueContaining: Codable {
    let value: String

    enum CodingKeys: String, CodingKey {
        case value = ""
    }
}

Source Compatability

This is a breaking change for downstream users of the special "value" coding key. All such uses should be replaced by case value = "" subject to this PR's inclusion.

@bwetherfield
Copy link
Collaborator Author

If this change goes through, and anyone, like us, find that a bunch of explicit CodingKey implementations are now needed (where before you just set-and-forgot a variable let value: String, for example), you may find this template helpful (for use with Sourcery).

@MaxDesiatov MaxDesiatov self-assigned this Nov 11, 2019
@MaxDesiatov MaxDesiatov added the breaking change The change is not backward compatible label Nov 11, 2019
@MaxDesiatov MaxDesiatov merged commit bf09326 into CoreOffice:master Nov 11, 2019
@MaxDesiatov
Copy link
Collaborator

@bwetherfield thanks for the PR!

arjungupta0107 pushed a commit to salido/XMLCoder that referenced this pull request Jun 26, 2020
## Overview
Restricts the special case usage of `"value"` OR `""` as a coding key, as implemented in CoreOffice#73 to just `""`. `"value"` resumes functioning as a normal coding key. 

## Example
As noted in CoreOffice#145, `"value"` is starting to collide awkwardly in one or two cases where it may be _implicit_ per the special case usage 
```swift
<value-containing>I am implicitly labeled</value-containing>
``` 
or _explicit_, as in 
```swift
<value-containing>
    <value>I am explicitly labeled</value>
</value-containing>
``` 
With the change proposed, the latter example will be unambiguously captured by
```swift
struct ValueContaining: Codable {
    let value: String
}
```
while the former is equivalent to
```swift
struct ValueContaining: Codable {
    let value: String

    enum CodingKeys: String, CodingKey {
        case value = ""
    }
}
```
## Source Compatability

This is a **breaking change** for downstream users of the special `"value"` coding key. All such uses should be replaced by `case value = ""` subject to this PR's inclusion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change The change is not backward compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants