Skip to content

Commit

Permalink
Fix composed serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Oct 8, 2024
1 parent 070f0ac commit dd97eb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 0 additions & 4 deletions it/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@
},
"apisguru::stripe.com": {
"Suppressions": [
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/5256"
},
{
"Language": "java",
"Rationale": "https://github.com/microsoft/kiota/issues/2842"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,25 @@ public override string GetAccessModifier(AccessModifier access)
public override string GetParameterSignature(CodeParameter parameter, CodeElement targetElement, LanguageWriter? writer = null)
{
ArgumentNullException.ThrowIfNull(parameter);
var paramType = GetTypescriptTypeString(parameter.Type, targetElement, includeCollectionInformation: true, inlineComposedTypeString: true);
var composedType = GetOriginalComposedType(parameter.Type);
var paramType = GetTypescriptTypeString(parameter.Type, targetElement, includeCollectionInformation: true, inlineComposedTypeString: true);

if (composedType != null && parameter.Parent is CodeMethod cm && cm.IsOfKind(CodeMethodKind.Serializer))
{
// eliminate primitive types from serializers with composed type signature
var newType = (CodeComposedTypeBase)composedType.Clone();
var nonPrimitiveTypes = composedType.Types.Where(x => !IsPrimitiveTypeOrPrimitiveCollection(x, composedType)).ToArray();
newType.SetTypes(nonPrimitiveTypes);
paramType = GetTypescriptTypeString(newType, targetElement, includeCollectionInformation: true, inlineComposedTypeString: true);
}
var isComposedOfPrimitives = composedType != null && composedType.IsComposedOfPrimitives(IsPrimitiveType);

// add a 'Parsable' suffix to composed parameters of primitives only if they are not deserialization targets
// add a 'Parsable' type to the parameter if it is composed of non-Parsable types
var parsableTypes = (
composedType != null && composedType.IsComposedOfPrimitives(IsPrimitiveTypeOrPrimitiveCollection),
parameter.Parent is CodeMethod method && method.IsOfKind(CodeMethodKind.Deserializer)
composedType != null,
parameter.Parent is CodeMethod method && (method.IsOfKind(CodeMethodKind.Deserializer) || method.IsOfKind(CodeMethodKind.Serializer))
) switch
{
(true, false) => string.Empty,
(true, true) => "Parsable | ",
_ => string.Empty,
};
Expand Down

0 comments on commit dd97eb8

Please sign in to comment.