Skip to content

Commit afbc96e

Browse files
charlespiercedandro
authored andcommitted
Merge pull request #173 from darrell-roberts/swift-decorators-generics
Allow swift decorator constraints to apply to generics Support CSharp Create basic language implementation. Start adding tests. Add snapshot tests Update slice type to map to IEnumerable instead of Array. Drop support for Unit type and return an error. Support anonymous structs Update slice of user type test snapshot Support namespace option Support serialization with json attributes Remove EnumLabel and use EnumMember attribute instead. Update all test snapshots according to the new changes. C# without naming convention option Add required attribute For newtonsoft json to require a non optional property, the property has to have the required attribute. Otherwise, it allows it to be null and a default value is provided.
2 parents 2262a56 + 8907868 commit afbc96e

File tree

15 files changed

+264
-142
lines changed

15 files changed

+264
-142
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Version 1.10.0-beta
22

3+
## 1.10.0-beta.5
4+
5+
- Added support for Swift generic constraints via `#[typeshare(swiftGenericConstraints)]` [#174](https://github.com/1Password/typeshare/pull/174)
6+
- Added Swift config option for defining constraints on `CodableVoid` generated type [#174](https://github.com/1Password/typeshare/pull/174)
7+
38
## 1.10.0-beta.4
49

510
Fixed a bug involving `#[typeshare(skip)]` on fields in struct variants of enums.
@@ -14,7 +19,7 @@ This release brings support for multiple file generation, allowing splitting gen
1419
files when used in large projects. This can dramatically increase compilation speed of
1520
the generated files and increase maintainability.
1621

17-
This is a *pre-release* version which may have bugs or break compatibility.
22+
This is a _pre-release_ version which may have bugs or break compatibility.
1823

1924
- Multiple file output [#166](https://github.com/1Password/typeshare/pull/166)
2025

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "typeshare-cli"
3-
version = "1.10.0-beta.4"
3+
version = "1.10.0-beta.5"
44
edition = "2021"
55
description = "Command Line Tool for generating language files with typeshare"
66
license = "MIT OR Apache-2.0"
@@ -22,5 +22,5 @@ once_cell = "1"
2222
rayon = "1.10"
2323
serde = { version = "1", features = ["derive"] }
2424
toml = "0.8"
25-
typeshare-core = { path = "../core", version = "1.10.0-beta.4" }
25+
typeshare-core = { path = "../core", version = "1.10.0-beta.5" }
2626
anyhow = "1"

cli/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub struct SwiftParams {
3434
pub type_mappings: HashMap<String, String>,
3535
pub default_decorators: Vec<String>,
3636
pub default_generic_constraints: Vec<String>,
37+
/// The contraints to apply to `CodableVoid`.
38+
pub codablevoid_constraints: Vec<String>,
3739
}
3840

3941
#[derive(Default, Serialize, Deserialize, PartialEq, Eq, Debug)]

cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fn language(
146146
config.swift.default_generic_constraints,
147147
),
148148
multi_file,
149+
codablevoid_constraints: config.swift.codablevoid_constraints,
149150
..Default::default()
150151
}),
151152
SupportedLanguage::Kotlin => Box::new(Kotlin {

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "typeshare-core"
3-
version = "1.10.0-beta.4"
3+
version = "1.10.0-beta.5"
44
license = "MIT OR Apache-2.0"
55
edition = "2021"
66
description = "The code generator used by Typeshare's command line tool"

core/data/tests/can_generate_generic_struct/output.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ public enum CoreEnumUsingGenericStruct: Codable {
8888
}
8989

9090
/// () isn't codable, so we use this instead to represent Rust's unit type
91-
public struct CodableVoid: Codable {}
91+
public struct CodableVoid: Codable, Equatable {}

core/data/tests/can_handle_unit_type/output.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ public enum EnumHasVoidType: Codable {
4646
}
4747

4848
/// () isn't codable, so we use this instead to represent Rust's unit type
49-
public struct CodableVoid: Codable {}
49+
public struct CodableVoid: Codable, Equatable {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#[typeshare(
2+
swift = "Equatable, Identifiable",
3+
swiftGenericConstraints = "T: Equatable & SomeThingElse, V: Equatable"
4+
)]
5+
pub struct Button<T, V, I> {
6+
/// Label of the button
7+
pub label: I,
8+
/// Accessibility label if it needed to be different than label
9+
pub accessibility_label: Option<String>,
10+
/// Optional tooltips that provide extra explanation for a button
11+
pub tooltip: Option<String>,
12+
/// Button action if there one
13+
pub action: Option<T>,
14+
/// Icon if there is one
15+
pub icon: Option<V>,
16+
/// Button state
17+
pub state: ButtonState,
18+
/// Button Mode
19+
pub style: ButtonStyle,
20+
}
21+
22+
#[typeshare]
23+
pub struct ButtonState;
24+
25+
#[typeshare]
26+
pub struct ButtonStyle;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Foundation
2+
3+
public struct ButtonState: Codable {
4+
public init() {}
5+
}
6+
7+
public struct ButtonStyle: Codable {
8+
public init() {}
9+
}
10+
11+
public struct Button<T: Codable & Equatable & SomeThingElse, V: Codable & Equatable, I: Codable>: Codable, Equatable, Identifiable {
12+
/// Label of the button
13+
public let label: I
14+
/// Accessibility label if it needed to be different than label
15+
public let accessibility_label: String?
16+
/// Optional tooltips that provide extra explanation for a button
17+
public let tooltip: String?
18+
/// Button action if there one
19+
public let action: T?
20+
/// Icon if there is one
21+
public let icon: V?
22+
/// Button state
23+
public let state: ButtonState
24+
/// Button Mode
25+
public let style: ButtonStyle
26+
27+
public init(label: I, accessibility_label: String?, tooltip: String?, action: T?, icon: V?, state: ButtonState, style: ButtonStyle) {
28+
self.label = label
29+
self.accessibility_label = accessibility_label
30+
self.tooltip = tooltip
31+
self.action = action
32+
self.icon = icon
33+
self.state = state
34+
self.style = style
35+
}
36+
}

0 commit comments

Comments
 (0)