diff --git a/cli/src/config.rs b/cli/src/config.rs index 08b58a2b..1543e1e7 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -34,7 +34,7 @@ pub struct SwiftParams { pub prefix: String, pub default_decorators: Vec, pub default_generic_constraints: Vec, - /// The contraints to apply to `CodableVoid`. + /// The constraints to apply to `CodableVoid`. pub codablevoid_constraints: Vec, pub type_mappings: HashMap, } @@ -55,7 +55,7 @@ pub struct GoParams { pub type_mappings: HashMap, } -/// The paramters that are used to configure the behaviour of typeshare +/// The parameters that are used to configure the behaviour of typeshare /// from the configuration file `typeshare.toml` #[derive(Serialize, Deserialize, Default, Debug, PartialEq)] #[serde(default)] diff --git a/core/data/tests/excluded_by_target_os/input.rs b/core/data/tests/excluded_by_target_os/input.rs index 65b0f18d..ba4d1f0f 100644 --- a/core/data/tests/excluded_by_target_os/input.rs +++ b/core/data/tests/excluded_by_target_os/input.rs @@ -80,3 +80,14 @@ pub struct AndroidExcluded; #[typeshare] #[cfg(all(feature = "my-feature", not(target_os = "ios")))] pub struct NestedNotTarget1; + +/// A struct with no target_os. Should be generated when +/// we use --target-os. +#[typeshare] +pub struct AlwaysAccept; + +#[typeshare] +pub enum AlwaysAcceptEnum { + Variant1, + Variant2, +} diff --git a/core/data/tests/excluded_by_target_os/output.go b/core/data/tests/excluded_by_target_os/output.go index d57096d0..e091a602 100644 --- a/core/data/tests/excluded_by_target_os/output.go +++ b/core/data/tests/excluded_by_target_os/output.go @@ -2,6 +2,10 @@ package proto import "encoding/json" +// A struct with no target_os. Should be generated when +// we use --target-os. +type AlwaysAccept struct { +} type DefinedTwice struct { Field1 string `json:"field1"` } @@ -15,6 +19,11 @@ type NestedNotTarget1 struct { } type OtherExcluded struct { } +type AlwaysAcceptEnum string +const ( + AlwaysAcceptEnumVariant1 AlwaysAcceptEnum = "Variant1" + AlwaysAcceptEnumVariant2 AlwaysAcceptEnum = "Variant2" +) type SomeEnum string const ( ) diff --git a/core/data/tests/excluded_by_target_os/output.kt b/core/data/tests/excluded_by_target_os/output.kt index ba08f88f..05ab96de 100644 --- a/core/data/tests/excluded_by_target_os/output.kt +++ b/core/data/tests/excluded_by_target_os/output.kt @@ -3,6 +3,11 @@ package com.agilebits.onepassword import kotlinx.serialization.Serializable import kotlinx.serialization.SerialName +/// A struct with no target_os. Should be generated when +/// we use --target-os. +@Serializable +object AlwaysAccept + @Serializable data class DefinedTwice ( val field1: String @@ -23,6 +28,14 @@ object NestedNotTarget1 @Serializable object OtherExcluded +@Serializable +enum class AlwaysAcceptEnum(val string: String) { + @SerialName("Variant1") + Variant1("Variant1"), + @SerialName("Variant2") + Variant2("Variant2"), +} + @Serializable enum class SomeEnum(val string: String) { } diff --git a/core/data/tests/excluded_by_target_os/output.scala b/core/data/tests/excluded_by_target_os/output.scala index 2ff84738..6242718d 100644 --- a/core/data/tests/excluded_by_target_os/output.scala +++ b/core/data/tests/excluded_by_target_os/output.scala @@ -2,6 +2,10 @@ package com.agilebits package onepassword { +// A struct with no target_os. Should be generated when +// we use --target-os. +class AlwaysAccept extends Serializable + case class DefinedTwice ( field1: String ) @@ -16,6 +20,18 @@ class NestedNotTarget1 extends Serializable class OtherExcluded extends Serializable +sealed trait AlwaysAcceptEnum { + def serialName: String +} +object AlwaysAcceptEnum { + case object Variant1 extends AlwaysAcceptEnum { + val serialName: String = "Variant1" + } + case object Variant2 extends AlwaysAcceptEnum { + val serialName: String = "Variant2" + } +} + sealed trait SomeEnum { def serialName: String } diff --git a/core/data/tests/excluded_by_target_os/output.swift b/core/data/tests/excluded_by_target_os/output.swift index f91e99bd..331e6dc8 100644 --- a/core/data/tests/excluded_by_target_os/output.swift +++ b/core/data/tests/excluded_by_target_os/output.swift @@ -1,5 +1,11 @@ import Foundation +/// A struct with no target_os. Should be generated when +/// we use --target-os. +public struct AlwaysAccept: Codable { + public init() {} +} + public struct DefinedTwice: Codable { public let field1: String @@ -28,6 +34,11 @@ public struct OtherExcluded: Codable { public init() {} } +public enum AlwaysAcceptEnum: String, Codable { + case variant1 = "Variant1" + case variant2 = "Variant2" +} + public enum SomeEnum: String, Codable { } diff --git a/core/data/tests/excluded_by_target_os/output.ts b/core/data/tests/excluded_by_target_os/output.ts index 9ba8eacd..45067442 100644 --- a/core/data/tests/excluded_by_target_os/output.ts +++ b/core/data/tests/excluded_by_target_os/output.ts @@ -1,3 +1,10 @@ +/** + * A struct with no target_os. Should be generated when + * we use --target-os. + */ +export interface AlwaysAccept { +} + export interface DefinedTwice { field1: string; } @@ -17,6 +24,11 @@ export interface NestedNotTarget1 { export interface OtherExcluded { } +export enum AlwaysAcceptEnum { + Variant1 = "Variant1", + Variant2 = "Variant2", +} + export enum SomeEnum { } diff --git a/core/src/language/mod.rs b/core/src/language/mod.rs index 61e4ff67..4b5d0b35 100644 --- a/core/src/language/mod.rs +++ b/core/src/language/mod.rs @@ -88,7 +88,7 @@ pub type SortedCrateNames<'a> = &'a CrateName; /// A sorted type name ref. pub type SortedTypeNames<'a> = BTreeSet<&'a str>; -/// Refence types by crate that are scoped for a given output module. +/// Reference types by crate that are scoped for a given output module. pub type ScopedCrateTypes<'a> = BTreeMap, SortedTypeNames<'a>>; /// All supported programming languages. diff --git a/core/src/language/swift.rs b/core/src/language/swift.rs index 984ebe14..6d3cb210 100644 --- a/core/src/language/swift.rs +++ b/core/src/language/swift.rs @@ -150,9 +150,9 @@ pub struct Swift { /// Whether or not to exclude the version header that normally appears at the top of generated code. /// If you aren't generating a snapshot test, this setting can just be left as a default (false) pub no_version_header: bool, - /// Are we generating mutliple modules? + /// Are we generating multiple modules? pub multi_file: bool, - /// The contraints to apply to `CodableVoid`. + /// The constraints to apply to `CodableVoid`. pub codablevoid_constraints: Vec, } @@ -501,7 +501,7 @@ impl Language for Swift { writeln!(w, "}}") } - // TODO: This will be addded in the future. + // TODO: This will be added in the future. // fn write_imports( // &mut self, // w: &mut dyn Write, @@ -753,7 +753,7 @@ impl Swift { .chain(self.default_decorators.iter().map(|s| s.as_str())) } - /// When using mulitple file generation we write this into a separate module vs at the + /// When using multiple file generation we write this into a separate module vs at the /// end of the generated file. fn write_codable_file(&self, output_folder: &str) -> std::io::Result<()> { let mut w = File::create(Path::new(output_folder).join("Codable.swift"))?; @@ -789,7 +789,7 @@ impl Swift { decorator_map: &'a DecoratorMap, generic_types: &'a [String], ) -> String { - let swift_generic_contraints_annotated = decorator_map + let swift_generic_constraints_annotated = decorator_map .get(&DecoratorKind::SwiftGenericConstraints) .map(|generic_constraints| { generic_constraints @@ -814,7 +814,7 @@ impl Swift { generic_types .iter() .map( - |type_name| match swift_generic_contraints_annotated.get(type_name.as_str()) { + |type_name| match swift_generic_constraints_annotated.get(type_name.as_str()) { // Use constraints from swiftGenericConstraints decorator. Some(constraints) => (type_name, Either::Left(constraints.iter().copied())), // Use the default generic constraints if it is not part of a swiftGenericConstraints decorator. diff --git a/core/src/parser.rs b/core/src/parser.rs index 3cc86c49..c6dac11f 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -80,7 +80,7 @@ pub enum ParseError { /// Error with it's related data. #[derive(Debug)] pub struct ErrorInfo { - /// The crate where this error occured. + /// The crate where this error occurred. pub crate_name: CrateName, /// The file name being parsed. pub file_name: String, diff --git a/core/src/target_os_check.rs b/core/src/target_os_check.rs index c67e9c3f..f16e95ba 100644 --- a/core/src/target_os_check.rs +++ b/core/src/target_os_check.rs @@ -14,7 +14,7 @@ enum TargetScope { } #[derive(Default)] -/// An iterator that yeilds all meta items and their contained scope. +/// An iterator that yields all meta items and their contained scope. struct TargetOsIterator { meta: Vec<(TargetScope, Meta)>, } diff --git a/core/src/visitors.rs b/core/src/visitors.rs index 131ccb05..8a566060 100644 --- a/core/src/visitors.rs +++ b/core/src/visitors.rs @@ -191,7 +191,7 @@ impl<'a> TypeShareVisitor<'a> { self.parsed_data.import_types = diff; } - /// Is this type annoted with at `#[cfg(target_os = "target")]` that does + /// Is this type annotated with at `#[cfg(target_os = "target")]` that does /// not match `--target-os` argument? #[inline(always)] fn target_os_accepted(&self, attrs: &[Attribute]) -> bool { @@ -217,8 +217,8 @@ impl<'ast, 'a> Visit<'ast> for TypeShareVisitor<'a> { // field: some_module::RefType // } // - // vist_path would be after vist_item_use so we could retain imported module references - // and reconcile aftewards. visit_item_use would have to retain non type import types + // visit_path would be after visit_item_use so we could retain imported module references + // and reconcile afterwards. visit_item_use would have to retain non type import types // which it discards right now. // let crate_candidate = p.segments.first()?.ident.to_string();