Skip to content

Commit 8aafe6e

Browse files
committed
Merge branch 'feature/csharp' of github.com:dandro/typeshare into feature/csharp
Update snapshots
2 parents afbc96e + 75644fa commit 8aafe6e

File tree

47 files changed

+1499
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1499
-54
lines changed

cli/src/args.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ pub const ARG_SCALA_PACKAGE: &str = "SCALAPACKAGE";
1212
pub const ARG_SCALA_MODULE_NAME: &str = "SCALAMODULENAME";
1313
#[cfg(feature = "go")]
1414
pub const ARG_GO_PACKAGE: &str = "GOPACKAGE";
15+
pub const ARG_CSHARP_NAMESPACE: &str = "CSHARP_NAMESPACE";
1516
pub const ARG_CONFIG_FILE_NAME: &str = "CONFIGFILENAME";
1617
pub const ARG_GENERATE_CONFIG: &str = "generate-config-file";
1718
pub const ARG_OUTPUT_FILE: &str = "output-file";
1819
pub const ARG_OUTPUT_FOLDER: &str = "output-folder";
1920
pub const ARG_FOLLOW_LINKS: &str = "follow-links";
2021

2122
#[cfg(feature = "go")]
22-
const AVAILABLE_LANGUAGES: [&str; 5] = ["kotlin", "scala", "swift", "typescript", "go"];
23+
const AVAILABLE_LANGUAGES: [&str; 6] = ["kotlin", "scala", "swift", "typescript", "go", "csharp"];
2324

2425
#[cfg(not(feature = "go"))]
25-
const AVAILABLE_LANGUAGES: [&str; 4] = ["kotlin", "scala", "swift", "typescript"];
26+
const AVAILABLE_LANGUAGES: [&str; 5] = ["kotlin", "scala", "swift", "typescript", "csharp"];
2627

2728
/// Parse command line arguments.
2829
pub(crate) fn build_command() -> Command<'static> {
@@ -96,7 +97,13 @@ pub(crate) fn build_command() -> Command<'static> {
9697
.takes_value(true)
9798
.required(false),
9899
)
99-
100+
.arg(
101+
Arg::new(ARG_CSHARP_NAMESPACE)
102+
.long("namespace")
103+
.help("C# namespace")
104+
.takes_value(true)
105+
.required(false)
106+
)
100107
.arg(
101108
Arg::new(ARG_CONFIG_FILE_NAME)
102109
.short('c')

cli/src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ pub struct GoParams {
5353
pub uppercase_acronyms: Vec<String>,
5454
}
5555

56+
#[derive(Default, Serialize, Deserialize, PartialEq, Eq, Debug)]
57+
#[serde(default)]
58+
pub struct CSharpParams {
59+
pub type_mappings: HashMap<String, String>,
60+
pub namespace: String,
61+
pub without_csharp_naming_convention: bool,
62+
}
63+
5664
/// The paramters that are used to configure the behaviour of typeshare
5765
/// from the configuration file `typeshare.toml`
5866
#[derive(Serialize, Deserialize, Default, Debug, PartialEq)]
@@ -64,6 +72,7 @@ pub(crate) struct Config {
6472
pub scala: ScalaParams,
6573
#[cfg(feature = "go")]
6674
pub go: GoParams,
75+
pub csharp: CSharpParams,
6776
}
6877

6978
pub(crate) fn store_config(config: &Config, file_path: Option<&str>) -> anyhow::Result<()> {

cli/src/main.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
44
use anyhow::{anyhow, Context};
55
use args::{
6-
build_command, ARG_CONFIG_FILE_NAME, ARG_FOLLOW_LINKS, ARG_GENERATE_CONFIG, ARG_JAVA_PACKAGE,
7-
ARG_KOTLIN_PREFIX, ARG_MODULE_NAME, ARG_OUTPUT_FOLDER, ARG_SCALA_MODULE_NAME,
8-
ARG_SCALA_PACKAGE, ARG_SWIFT_PREFIX, ARG_TYPE,
6+
build_command, ARG_CONFIG_FILE_NAME, ARG_CSHARP_NAMESPACE, ARG_FOLLOW_LINKS,
7+
ARG_GENERATE_CONFIG, ARG_JAVA_PACKAGE, ARG_KOTLIN_PREFIX, ARG_MODULE_NAME, ARG_OUTPUT_FOLDER,
8+
ARG_SCALA_MODULE_NAME, ARG_SCALA_PACKAGE, ARG_SWIFT_PREFIX, ARG_TYPE,
99
};
1010
use clap::ArgMatches;
1111
use config::Config;
@@ -16,7 +16,7 @@ use std::collections::HashMap;
1616
use typeshare_core::language::Go;
1717
use typeshare_core::{
1818
language::{
19-
CrateName, GenericConstraints, Kotlin, Language, Scala, SupportedLanguage, Swift,
19+
CSharp, CrateName, GenericConstraints, Kotlin, Language, Scala, SupportedLanguage, Swift,
2020
TypeScript,
2121
},
2222
parser::ParsedData,
@@ -166,6 +166,12 @@ fn language(
166166
type_mappings: config.typescript.type_mappings,
167167
..Default::default()
168168
}),
169+
SupportedLanguage::CSharp => Box::new(CSharp {
170+
namespace: config.csharp.namespace,
171+
type_mappings: config.csharp.type_mappings,
172+
without_csharp_naming_convention: config.csharp.without_csharp_naming_convention,
173+
..Default::default()
174+
}),
169175
#[cfg(feature = "go")]
170176
SupportedLanguage::Go => Box::new(Go {
171177
package: config.go.package,
@@ -206,6 +212,10 @@ fn override_configuration(mut config: Config, options: &ArgMatches) -> Config {
206212
config.scala.module_name = scala_module_name.to_string();
207213
}
208214

215+
if let Some(csharp_namespace) = options.value_of(ARG_CSHARP_NAMESPACE) {
216+
config.csharp.namespace = csharp_namespace.to_string();
217+
}
218+
209219
#[cfg(feature = "go")]
210220
if let Some(go_package) = options.value_of(args::ARG_GO_PACKAGE) {
211221
config.go.package = go_package.to_string();

cli/src/parse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn output_file_name(language_type: SupportedLanguage, crate_name: &CrateName) ->
6363
SupportedLanguage::Scala => snake_case(),
6464
SupportedLanguage::Swift => pascal_case(),
6565
SupportedLanguage::TypeScript => snake_case(),
66+
SupportedLanguage::CSharp => pascal_case(),
6667
}
6768
}
6869

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#nullable enable
2+
3+
using System.Reflection;
4+
using JsonSubTypes;
5+
using Newtonsoft.Json;
6+
using System.Runtime.Serialization;
7+
8+
/** Generated type representing the anonymous struct variant `List` of the `AnonymousStructWithRename` Rust enum */
9+
public class AnonymousStructWithRenameListInner {
10+
public IEnumerable<string> list { get; set; }
11+
}
12+
13+
/** Generated type representing the anonymous struct variant `LongFieldNames` of the `AnonymousStructWithRename` Rust enum */
14+
public class AnonymousStructWithRenameLongFieldNamesInner {
15+
public string some_long_field_name { get; set; }
16+
public bool and { get; set; }
17+
public IEnumerable<string> but_one_more { get; set; }
18+
}
19+
20+
/** Generated type representing the anonymous struct variant `KebabCase` of the `AnonymousStructWithRename` Rust enum */
21+
public class AnonymousStructWithRenameKebabCaseInner {
22+
public IEnumerable<string> another-list { get; set; }
23+
public string camelCaseStringField { get; set; }
24+
public bool something-else { get; set; }
25+
}
26+
27+
[JsonConverter(typeof(JsonSubtypes), "type")]
28+
[JsonSubtypes.KnownSubType(typeof(List), "List")]
29+
[JsonSubtypes.KnownSubType(typeof(LongFieldNames), "LongFieldNames")]
30+
[JsonSubtypes.KnownSubType(typeof(KebabCase), "KebabCase")]
31+
public abstract record AnonymousStructWithRename
32+
{
33+
public record list(AnonymousStructWithRenameListInner Content): AnonymousStructWithRename();
34+
public record longFieldNames(AnonymousStructWithRenameLongFieldNamesInner Content): AnonymousStructWithRename();
35+
public record kebabCase(AnonymousStructWithRenameKebabCaseInner Content): AnonymousStructWithRename();
36+
}
37+
38+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#nullable enable
2+
3+
using System.Reflection;
4+
using JsonSubTypes;
5+
using Newtonsoft.Json;
6+
using System.Runtime.Serialization;
7+
8+
public class ItemDetailsFieldValue {
9+
public string Hello { get; set; }
10+
}
11+
12+
[JsonConverter(typeof(JsonSubtypes), "t")]
13+
[JsonSubtypes.KnownSubType(typeof(String), "String")]
14+
[JsonSubtypes.KnownSubType(typeof(Number), "Number")]
15+
[JsonSubtypes.KnownSubType(typeof(NumberArray), "NumberArray")]
16+
[JsonSubtypes.KnownSubType(typeof(ReallyCoolType), "ReallyCoolType")]
17+
[JsonSubtypes.KnownSubType(typeof(ArrayReallyCoolType), "ArrayReallyCoolType")]
18+
[JsonSubtypes.KnownSubType(typeof(DictionaryReallyCoolType), "DictionaryReallyCoolType")]
19+
public abstract record AdvancedColors
20+
{
21+
public record String(string C) : AdvancedColors();
22+
public record Number(int C) : AdvancedColors();
23+
public record NumberArray(IEnumerable<int> C) : AdvancedColors();
24+
public record ReallyCoolType(ItemDetailsFieldValue C) : AdvancedColors();
25+
public record ArrayReallyCoolType(IEnumerable<ItemDetailsFieldValue> C) : AdvancedColors();
26+
public record DictionaryReallyCoolType(IDictionary<string, ItemDetailsFieldValue> C) : AdvancedColors();
27+
}
28+
29+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#nullable enable
2+
3+
using System.Reflection;
4+
using JsonSubTypes;
5+
using Newtonsoft.Json;
6+
using System.Runtime.Serialization;
7+
8+
namespace Company.Domain.Models;
9+
10+
/** Struct comment */
11+
public class ItemDetailsFieldValue {
12+
}
13+
14+
/** Enum comment */
15+
[JsonConverter(typeof(JsonSubtypes), "type")]
16+
[JsonSubtypes.KnownSubType(typeof(String), "String")]
17+
[JsonSubtypes.KnownSubType(typeof(Number), "Number")]
18+
[JsonSubtypes.KnownSubType(typeof(UnsignedNumber), "UnsignedNumber")]
19+
[JsonSubtypes.KnownSubType(typeof(NumberArray), "NumberArray")]
20+
[JsonSubtypes.KnownSubType(typeof(ReallyCoolType), "ReallyCoolType")]
21+
public abstract record AdvancedColors
22+
{
23+
/** This is a case comment */
24+
public record String(string Content) : AdvancedColors();
25+
public record Number(int Content) : AdvancedColors();
26+
public record UnsignedNumber(uint Content) : AdvancedColors();
27+
public record NumberArray(IEnumerable<int> Content) : AdvancedColors();
28+
/** Comment on the last element */
29+
public record ReallyCoolType(ItemDetailsFieldValue Content) : AdvancedColors();
30+
}
31+
32+
33+
[JsonConverter(typeof(JsonSubtypes), "type")]
34+
[JsonSubtypes.KnownSubType(typeof(String), "String")]
35+
[JsonSubtypes.KnownSubType(typeof(Number), "Number")]
36+
[JsonSubtypes.KnownSubType(typeof(NumberArray), "NumberArray")]
37+
[JsonSubtypes.KnownSubType(typeof(ReallyCoolType), "ReallyCoolType")]
38+
public abstract record AdvancedColors2
39+
{
40+
/** This is a case comment */
41+
public record String(string Content) : AdvancedColors2();
42+
public record Number(int Content) : AdvancedColors2();
43+
public record NumberArray(IEnumerable<int> Content) : AdvancedColors2();
44+
/** Comment on the last element */
45+
public record ReallyCoolType(ItemDetailsFieldValue Content) : AdvancedColors2();
46+
}
47+
48+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#nullable enable
2+
3+
using System.Reflection;
4+
using JsonSubTypes;
5+
using Newtonsoft.Json;
6+
using System.Runtime.Serialization;
7+
8+
[JsonConverter(typeof(JsonSubtypes), "type")]
9+
[JsonSubtypes.KnownSubType(typeof(A), "A")]
10+
[JsonSubtypes.KnownSubType(typeof(C), "C")]
11+
public abstract record SomeEnum
12+
{
13+
public record A(): SomeEnum();
14+
public record C(int Content) : SomeEnum();
15+
}
16+
17+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#nullable enable
2+
3+
using System.Reflection;
4+
using JsonSubTypes;
5+
using Newtonsoft.Json;
6+
using System.Runtime.Serialization;
7+
8+
/** This is a comment. */
9+
public enum Colors
10+
{
11+
Red,
12+
13+
Blue,
14+
15+
Green,
16+
17+
}
18+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#nullable enable
2+
3+
using System.Reflection;
4+
using JsonSubTypes;
5+
using Newtonsoft.Json;
6+
using System.Runtime.Serialization;
7+
8+
public class AddressDetails {
9+
}
10+
11+
[JsonConverter(typeof(JsonSubtypes), "type")]
12+
[JsonSubtypes.KnownSubType(typeof(FixedAddress), "FixedAddress")]
13+
[JsonSubtypes.KnownSubType(typeof(NoFixedAddress), "NoFixedAddress")]
14+
public abstract record Address
15+
{
16+
public record FixedAddress(AddressDetails Content) : Address();
17+
public record NoFixedAddress(): Address();
18+
}
19+
20+

0 commit comments

Comments
 (0)