-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement discriminator support in v3 generator #113
Changes from all commits
c5b1736
238fe60
2fe2c7a
c8528e0
e22d779
415e4e1
236966b
7718176
7a5644e
8e78dd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ public static CodeModelGo Cast(this CodeModel cm) | |
} | ||
|
||
/// <summary> | ||
/// This method changes string to sentence where is make the first word | ||
/// This method changes string to sentence where is make the first word | ||
/// of sentence to lowercase (unless it is an acronym). The sentence is coming directly from swagger. | ||
/// </summary> | ||
/// <param name="value"></param> | ||
|
@@ -54,15 +54,13 @@ public static string ToSentence(this string value) | |
{ | ||
return string.Empty; | ||
} | ||
else | ||
|
||
value = value.Trim(); | ||
if (value.StartsWithAcronym()) | ||
{ | ||
value = value.Trim(); | ||
if (value.StartsWithAcronym()) | ||
{ | ||
return value; | ||
} | ||
return value.First().ToString().ToLowerInvariant() + (value.Length > 1 ? value.Substring(1) : ""); | ||
return value; | ||
} | ||
return value.First().ToString().ToLowerInvariant() + (value.Length > 1 ? value.Substring(1) : ""); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -74,7 +72,7 @@ public static string ToSentence(this string value) | |
public static bool StartsWithAcronym(this string value) | ||
{ | ||
string firstWord = value.Trim().Split(' ', '-', '_').First(); | ||
return firstWord.Length > 1 && firstWord.All(c => char.IsUpper(c)); | ||
return firstWord.Length > 1 && firstWord.All(char.IsUpper); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -126,7 +124,7 @@ public static string ToShortName(this string longName) | |
} | ||
|
||
/// <summary> | ||
/// This method checks if MethodGroupName is plural of package name. | ||
/// This method checks if MethodGroupName is plural of package name. | ||
/// It returns false for packages not listed in dictionary 'plural'. | ||
/// Example, group EventHubs in package EventHub. | ||
/// Refactor -> Namer, but also could be used by the CodeModelTransformer | ||
|
@@ -296,24 +294,43 @@ public static bool CanBeNull(this IModelType type) | |
/// <param name="imports"></param> | ||
public static void AddImports(this IModelType type, HashSet<string> imports) | ||
{ | ||
if (type is DictionaryTypeGo) | ||
switch (type) | ||
{ | ||
(type as DictionaryTypeGo).AddImports(imports); | ||
} | ||
else if (type is PrimaryTypeGo) | ||
{ | ||
(type as PrimaryTypeGo).AddImports(imports); | ||
} | ||
else if (type is SequenceTypeGo) | ||
{ | ||
(type as SequenceTypeGo).AddImports(imports); | ||
case DictionaryTypeGo dictionaryType: | ||
dictionaryType.AddImports(imports); | ||
break; | ||
case PrimaryTypeGo primaryType: | ||
primaryType.AddImports(imports); | ||
break; | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could a different go type arrive here? Something different to a sequence? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have it the same in the v2 generator. looking at it, Composite Type also has AddImports but that will be just the imports of its fields |
||
(type as SequenceTypeGo)?.AddImports(imports); | ||
break; | ||
} | ||
} | ||
|
||
public static bool ShouldBeSyntheticType(this IModelType type) | ||
{ | ||
return (type is PrimaryType || type is SequenceType || type is DictionaryType || type is EnumType || | ||
(type is CompositeTypeGo && (type as CompositeTypeGo).IsPolymorphicResponse())); | ||
{ | ||
return (type is PrimaryType || type is SequenceType || type is DictionaryType || type is EnumType || | ||
(type is CompositeTypeGo && ((CompositeTypeGo) type).IsPolymorphicResponse())); | ||
} | ||
|
||
/// <summary> | ||
/// Gets if the type has an interface. | ||
/// </summary> | ||
public static bool HasInterface(this IModelType type) | ||
{ | ||
return (type is CompositeTypeGo compositeType) && | ||
(compositeType.IsRootType || compositeType.BaseIsPolymorphic && !compositeType.IsLeafType); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the interface name for the type. | ||
/// </summary> | ||
/// <param name="type"></param> | ||
/// <returns></returns> | ||
public static string GetInterfaceName(this IModelType type) | ||
{ | ||
return $"Basic{type.Name}"; | ||
} | ||
|
||
/// <summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that I removed the marshalling file from the output. it seems most of it should go to the models file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this file was to separate the exported types from the non-exported types/implementation details (i.e. the content of marshalling.go is interesting to us but not to consumers of the SDK). If merging this into the models file makes it easier to generate the content then we can leave it merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, but I think to keep the generator code cleaner its easier to put them in the models also would prefer to have all the publicly used types ( and their marshallers ) to be in the models.