-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from darrell-roberts/fix-typeshare-skip
Fix typeshare skip
- Loading branch information
Showing
13 changed files
with
262 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
core/data/tests/can_generate_anonymous_struct_with_skipped_fields/input.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// Enum keeping track of who autofilled a field | ||
#[typeshare] | ||
#[serde(tag = "type", content = "content")] | ||
pub enum AutofilledBy { | ||
/// This field was autofilled by us | ||
Us { | ||
/// The UUID for the fill | ||
uuid: String, | ||
}, | ||
/// Something else autofilled this field | ||
SomethingElse { | ||
/// The UUID for the fill | ||
uuid: String, | ||
/// Some other thing | ||
#[typeshare(skip)] | ||
thing: i32, | ||
}, | ||
} |
85 changes: 85 additions & 0 deletions
85
core/data/tests/can_generate_anonymous_struct_with_skipped_fields/output.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// Generated type representing the anonymous struct variant `Us` of the `AutofilledBy` Rust enum | ||
type AutofilledByUsInner struct { | ||
// The UUID for the fill | ||
Uuid string `json:"uuid"` | ||
} | ||
// Generated type representing the anonymous struct variant `SomethingElse` of the `AutofilledBy` Rust enum | ||
type AutofilledBySomethingElseInner struct { | ||
// The UUID for the fill | ||
Uuid string `json:"uuid"` | ||
} | ||
// Enum keeping track of who autofilled a field | ||
type AutofilledByTypes string | ||
const ( | ||
// This field was autofilled by us | ||
AutofilledByTypeVariantUs AutofilledByTypes = "Us" | ||
// Something else autofilled this field | ||
AutofilledByTypeVariantSomethingElse AutofilledByTypes = "SomethingElse" | ||
) | ||
type AutofilledBy struct{ | ||
Type AutofilledByTypes `json:"type"` | ||
content interface{} | ||
} | ||
|
||
func (a *AutofilledBy) UnmarshalJSON(data []byte) error { | ||
var enum struct { | ||
Tag AutofilledByTypes `json:"type"` | ||
Content json.RawMessage `json:"content"` | ||
} | ||
if err := json.Unmarshal(data, &enum); err != nil { | ||
return err | ||
} | ||
|
||
a.Type = enum.Tag | ||
switch a.Type { | ||
case AutofilledByTypeVariantUs: | ||
var res AutofilledByUsInner | ||
a.content = &res | ||
case AutofilledByTypeVariantSomethingElse: | ||
var res AutofilledBySomethingElseInner | ||
a.content = &res | ||
|
||
} | ||
if err := json.Unmarshal(enum.Content, &a.content); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a AutofilledBy) MarshalJSON() ([]byte, error) { | ||
var enum struct { | ||
Tag AutofilledByTypes `json:"type"` | ||
Content interface{} `json:"content,omitempty"` | ||
} | ||
enum.Tag = a.Type | ||
enum.Content = a.content | ||
return json.Marshal(enum) | ||
} | ||
|
||
func (a AutofilledBy) Us() *AutofilledByUsInner { | ||
res, _ := a.content.(*AutofilledByUsInner) | ||
return res | ||
} | ||
func (a AutofilledBy) SomethingElse() *AutofilledBySomethingElseInner { | ||
res, _ := a.content.(*AutofilledBySomethingElseInner) | ||
return res | ||
} | ||
|
||
func NewAutofilledByTypeVariantUs(content *AutofilledByUsInner) AutofilledBy { | ||
return AutofilledBy{ | ||
Type: AutofilledByTypeVariantUs, | ||
content: content, | ||
} | ||
} | ||
func NewAutofilledByTypeVariantSomethingElse(content *AutofilledBySomethingElseInner) AutofilledBy { | ||
return AutofilledBy{ | ||
Type: AutofilledByTypeVariantSomethingElse, | ||
content: content, | ||
} | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
core/data/tests/can_generate_anonymous_struct_with_skipped_fields/output.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.agilebits.onepassword | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerialName | ||
|
||
/// Generated type representing the anonymous struct variant `Us` of the `AutofilledBy` Rust enum | ||
@Serializable | ||
data class AutofilledByUsInner ( | ||
/// The UUID for the fill | ||
val uuid: String | ||
) | ||
|
||
/// Generated type representing the anonymous struct variant `SomethingElse` of the `AutofilledBy` Rust enum | ||
@Serializable | ||
data class AutofilledBySomethingElseInner ( | ||
/// The UUID for the fill | ||
val uuid: String | ||
) | ||
|
||
/// Enum keeping track of who autofilled a field | ||
@Serializable | ||
sealed class AutofilledBy { | ||
/// This field was autofilled by us | ||
@Serializable | ||
@SerialName("Us") | ||
data class Us(val content: AutofilledByUsInner): AutofilledBy() | ||
/// Something else autofilled this field | ||
@Serializable | ||
@SerialName("SomethingElse") | ||
data class SomethingElse(val content: AutofilledBySomethingElseInner): AutofilledBy() | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
core/data/tests/can_generate_anonymous_struct_with_skipped_fields/output.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.agilebits | ||
|
||
package onepassword { | ||
|
||
// Generated type representing the anonymous struct variant `Us` of the `AutofilledBy` Rust enum | ||
case class AutofilledByUsInner ( | ||
// The UUID for the fill | ||
uuid: String | ||
) | ||
|
||
// Generated type representing the anonymous struct variant `SomethingElse` of the `AutofilledBy` Rust enum | ||
case class AutofilledBySomethingElseInner ( | ||
// The UUID for the fill | ||
uuid: String | ||
) | ||
|
||
// Enum keeping track of who autofilled a field | ||
sealed trait AutofilledBy { | ||
def serialName: String | ||
} | ||
object AutofilledBy { | ||
// This field was autofilled by us | ||
case class Us(content: AutofilledByUsInner) extends AutofilledBy { | ||
val serialName: String = "Us" | ||
} | ||
// Something else autofilled this field | ||
case class SomethingElse(content: AutofilledBySomethingElseInner) extends AutofilledBy { | ||
val serialName: String = "SomethingElse" | ||
} | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
core/data/tests/can_generate_anonymous_struct_with_skipped_fields/output.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Foundation | ||
|
||
|
||
/// Generated type representing the anonymous struct variant `Us` of the `AutofilledBy` Rust enum | ||
public struct AutofilledByUsInner: Codable { | ||
/// The UUID for the fill | ||
public let uuid: String | ||
|
||
public init(uuid: String) { | ||
self.uuid = uuid | ||
} | ||
} | ||
|
||
/// Generated type representing the anonymous struct variant `SomethingElse` of the `AutofilledBy` Rust enum | ||
public struct AutofilledBySomethingElseInner: Codable { | ||
/// The UUID for the fill | ||
public let uuid: String | ||
|
||
public init(uuid: String) { | ||
self.uuid = uuid | ||
} | ||
} | ||
/// Enum keeping track of who autofilled a field | ||
public enum AutofilledBy: Codable { | ||
/// This field was autofilled by us | ||
case us(AutofilledByUsInner) | ||
/// Something else autofilled this field | ||
case somethingElse(AutofilledBySomethingElseInner) | ||
|
||
enum CodingKeys: String, CodingKey, Codable { | ||
case us = "Us", | ||
somethingElse = "SomethingElse" | ||
} | ||
|
||
private enum ContainerCodingKeys: String, CodingKey { | ||
case type, content | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: ContainerCodingKeys.self) | ||
if let type = try? container.decode(CodingKeys.self, forKey: .type) { | ||
switch type { | ||
case .us: | ||
if let content = try? container.decode(AutofilledByUsInner.self, forKey: .content) { | ||
self = .us(content) | ||
return | ||
} | ||
case .somethingElse: | ||
if let content = try? container.decode(AutofilledBySomethingElseInner.self, forKey: .content) { | ||
self = .somethingElse(content) | ||
return | ||
} | ||
} | ||
} | ||
throw DecodingError.typeMismatch(AutofilledBy.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for AutofilledBy")) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: ContainerCodingKeys.self) | ||
switch self { | ||
case .us(let content): | ||
try container.encode(CodingKeys.us, forKey: .type) | ||
try container.encode(content, forKey: .content) | ||
case .somethingElse(let content): | ||
try container.encode(CodingKeys.somethingElse, forKey: .type) | ||
try container.encode(content, forKey: .content) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
core/data/tests/can_generate_anonymous_struct_with_skipped_fields/output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** Enum keeping track of who autofilled a field */ | ||
export type AutofilledBy = | ||
/** This field was autofilled by us */ | ||
| { type: "Us", content: { | ||
/** The UUID for the fill */ | ||
uuid: string; | ||
}} | ||
/** Something else autofilled this field */ | ||
| { type: "SomethingElse", content: { | ||
/** The UUID for the fill */ | ||
uuid: string; | ||
}}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.