Skip to content
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

feat: Add support for composed types in Typescript #4602

Merged
merged 162 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 159 commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
b6644d4
initial commit for composed types implementation for typescript
koros Apr 26, 2024
43a7efb
Merge branch 'main' into feature/typescript/composed-types
koros May 2, 2024
1aa3a62
use inline declaration of composed types instead of wrapper types
koros May 3, 2024
bc9b323
Merge branch 'main' into feature/typescript/composed-types
koros May 3, 2024
11a33f0
serialize primitive union types
koros May 7, 2024
a57dc2f
Merge branch 'main' into feature/typescript/composed-types
koros May 8, 2024
87518d2
finished adding support for composed types comprised of union of prim…
koros May 9, 2024
67c2872
use more meaningful naming & semantics
koros May 10, 2024
5225bdb
refactor large methods
koros May 13, 2024
507db72
Merge branch 'main' into feature/typescript/composed-types
koros May 13, 2024
99650f1
unit test for TypescriptRefiner
koros May 13, 2024
2d88aa8
ad dopen api test file
koros May 13, 2024
442532f
unit tests for Typescript refiner
koros May 14, 2024
a7e3102
Merge branch 'main' into feature/typescript/composed-types
koros May 14, 2024
55d9a66
Merge branch 'main' into feature/typescript/composed-types
koros May 15, 2024
bec7828
test coverage - cover all cases
koros May 15, 2024
325fcab
minor cleanup refactor for TypeScript/CodeFunctionWriter.cs
koros May 16, 2024
d2782ad
access the conventions service from static context
koros May 16, 2024
dfe28b1
move the method to get factory name to the conventions service
koros May 16, 2024
6a07f54
Merge branch 'main' into feature/typescript/composed-types
koros May 16, 2024
75022fc
refactor composed type to use specific writers
koros May 16, 2024
5c43b9d
increase coverage
koros May 17, 2024
7b3a92a
increase code coverage
koros May 17, 2024
4f36114
Merge branch 'main' into feature/typescript/composed-types
koros May 17, 2024
663798e
handle union of objects in typescript
koros May 21, 2024
9385ac0
Merge branch 'main' into feature/typescript/composed-types
koros May 21, 2024
8c6e25b
remove unused code
koros May 21, 2024
5e41e0d
add serialization for union objects
koros May 22, 2024
3814a86
Merge branch 'main' into feature/typescript/composed-types
koros May 22, 2024
15a5140
fix failing test and improve coverage
koros May 22, 2024
9b27708
add pets union test yml file
koros May 22, 2024
d61a5be
remove unused parameter
koros May 23, 2024
9a9d267
Merge branch 'main' into feature/typescript/composed-types
koros May 23, 2024
f44220b
retrieve serialization method correctly
koros May 28, 2024
39648b6
Merge branch 'main' into feature/typescript/composed-types
koros May 28, 2024
14ee8cb
rectify the serilaization function for CodeUnion types
koros May 29, 2024
b1086de
Merge branch 'main' into feature/typescript/composed-types
koros May 29, 2024
2f2d855
**allow primitive intersection types as per existing yml test file
koros May 29, 2024
615b3fa
typescript: add support for intersection type objects
koros May 29, 2024
ae857c5
fix primitive intersection bug
koros May 30, 2024
6084d07
refactor the factory method for primitive composed type values
koros Jun 5, 2024
dc7592b
Merge branch 'main' into feature/typescript/composed-types
koros Jun 5, 2024
35b6120
removed unused import statement
koros Jun 7, 2024
d8d3145
Merge branch 'main' into feature/typescript/composed-types
koros Jun 7, 2024
b5baad2
inline composed types
koros Jun 7, 2024
9d20950
Merge branch 'main' into feature/typescript/composed-types
koros Jun 7, 2024
37e78fa
remove unused param
koros Jun 7, 2024
5688854
fix sonar warnings
koros Jun 7, 2024
d101bf9
format code
koros Jun 7, 2024
f71be97
address pr comments
koros Jun 10, 2024
4a7c5da
Merge branch 'main' into feature/typescript/composed-types
koros Jun 10, 2024
84b8792
adress pr comments
koros Jun 12, 2024
c247ea1
address pr comments
koros Jun 12, 2024
9cb0f84
address pr comments
koros Jun 12, 2024
73517d0
Merge branch 'main' into feature/typescript/composed-types
koros Jun 12, 2024
dba8f83
address pr coments
koros Jun 12, 2024
2966b66
format code
koros Jun 12, 2024
8c52767
address pr comments
koros Jun 12, 2024
1f82494
increase test coverage
koros Jun 12, 2024
16d848c
increase test coverage
koros Jun 12, 2024
4507925
Merge branch 'main' into feature/typescript/composed-types
koros Jun 12, 2024
c86251d
address pr comments
koros Jun 13, 2024
8b5615e
Merge branch 'main' into feature/typescript/composed-types
koros Jun 13, 2024
111b0e1
address pr comments
koros Jun 13, 2024
8f0f5d6
address pr comments
koros Jun 13, 2024
cc2e34b
address pr comments
koros Jun 13, 2024
b3e5655
remove reference to external urls on tests
koros Jun 14, 2024
8c26bde
Merge branch 'main' into feature/typescript/composed-types
koros Jun 14, 2024
c42969c
Merge branch 'main' into feature/typescript/composed-types
koros Jun 18, 2024
8eddb41
simplify open api sample test files
koros Jun 18, 2024
b9b5474
Merge branch 'main' into feature/typescript/composed-types
koros Jun 18, 2024
5ba007c
address pr comments
koros Jun 20, 2024
719082b
Merge branch 'main' into feature/typescript/composed-types
koros Jun 20, 2024
9665e19
address pr comments, format code
koros Jun 20, 2024
63abe19
address pr comments
koros Jun 20, 2024
edf1a7f
fix failing test
koros Jun 20, 2024
d334d4c
address pr comments
koros Jun 21, 2024
3ecff4e
format code
koros Jun 21, 2024
57d4253
Merge branch 'main' into feature/typescript/composed-types
koros Jun 21, 2024
ca06ae9
apply pr suggestion to other places for consistency
koros Jun 21, 2024
448a4e1
Merge branch 'main' into feature/typescript/composed-types
koros Jun 21, 2024
d75489a
Merge branch 'main' into feature/typescript/composed-types
koros Jun 24, 2024
8a6922f
Merge branch 'main' into feature/typescript/composed-types
koros Jun 25, 2024
799b0d6
enable supressed typescript tests
koros Jun 25, 2024
fc8e892
allow generation to constinue when the discriminator property is missing
koros Jun 25, 2024
89b5a87
fix failing it tests
koros Jun 25, 2024
9797869
fix it test compilation error 'parseNode' is possibly 'undefined' for…
koros Jun 25, 2024
a818bda
Merge branch 'main' into feature/typescript/composed-types
koros Jun 26, 2024
1b8cb7e
fix failing test
koros Jun 26, 2024
f62886a
fix failing it test
koros Jun 26, 2024
ce4b4a1
ignore null default values
koros Jun 26, 2024
1df1e8f
ignore 'null' default values
koros Jun 26, 2024
6df873d
omit null from default values while serializing
koros Jun 26, 2024
9b0f3eb
exclude apisguru::stripe.com integration test from running since it c…
koros Jun 26, 2024
d3e9bb0
address pr comments
koros Jun 27, 2024
83b8bb8
Merge branch 'main' into feature/typescript/composed-types
koros Jun 27, 2024
e4b1f2d
format code
koros Jun 27, 2024
4787e3b
fix sonar warnings
koros Jun 27, 2024
881f0dd
search for factory function using namespace only
koros Jun 28, 2024
fe5ac63
use a more meaningful method name
koros Jul 1, 2024
26abee4
Merge branch 'main' into feature/typescript/composed-types
koros Jul 1, 2024
7a662c4
appply pr suggestion
koros Jul 1, 2024
8fefc3b
refactor code remove new enum values
koros Jul 3, 2024
1de703d
format code
koros Jul 3, 2024
d5bf8a7
remove unused parameters
koros Jul 3, 2024
af80621
fix compilation issue
koros Jul 3, 2024
681b900
remove unused deserializer
koros Jul 3, 2024
a17523a
simplify statement
koros Jul 3, 2024
2575217
Merge branch 'main' into feature/typescript/composed-types
koros Jul 3, 2024
02d880b
apply pr review suggestions
koros Jul 4, 2024
997a64f
Merge branch 'main' into feature/typescript/composed-types
koros Jul 4, 2024
cb60924
Merge branch 'main' into feature/typescript/composed-types
koros Jul 15, 2024
90f681a
Merge branch 'main' into feature/typescript/composed-types
koros Jul 16, 2024
8d1278e
remove unused parameter
koros Jul 16, 2024
c054766
Merge branch 'main' into feature/typescript/composed-types
koros Jul 16, 2024
a0ceb85
Merge branch 'main' into feature/typescript/composed-types
koros Jul 22, 2024
04a4178
use | symbol for code intersection in typescript
koros Jul 23, 2024
9d4e679
Merge branch 'main' into feature/typescript/composed-types
koros Jul 23, 2024
33becc4
move composed-type utility method to extensions
koros Jul 23, 2024
4dec28d
remove CodeComposedTypeBase extension class
koros Jul 23, 2024
515c872
use Nullish Coalescing Operator ?? over logical or ||
koros Jul 23, 2024
6cd579d
handle edge cases for composed types - Union of objects and primitive…
koros Jul 29, 2024
5072ec6
format code
koros Jul 29, 2024
4fdd941
remove unused code in CodeMethod.cs
koros Jul 29, 2024
a9ecd07
Merge branch 'main' into feature/typescript/composed-types
koros Jul 29, 2024
0cb4684
delete unused method
koros Jul 29, 2024
fc32d31
import all associated deserializers for composed types
koros Jul 30, 2024
83f95bf
remove collection symbol for composed type param in serailizer and de…
koros Aug 1, 2024
40c226f
handle endge cases where composed type is a mix of objects and/or arr…
koros Aug 5, 2024
f31bad4
fix casing
koros Aug 5, 2024
9a34c23
add serialization functions to obsolete class definitions to prevent …
koros Aug 6, 2024
c725e83
use correct serialization method for composed type collection
koros Aug 6, 2024
1d7937b
improve code coverage
koros Aug 6, 2024
04cd4d6
Merge branch 'main' of github.com:microsoft/kiota into feature/typesc…
rkodev Aug 19, 2024
d6953fb
Refactor composed types
rkodev Aug 19, 2024
ed4888d
fix: null check on composed types
rkodev Aug 19, 2024
a69e620
fix: type casting
rkodev Aug 19, 2024
69a6c1a
Fix serialization
rkodev Aug 20, 2024
305b01b
Fix serialization with differenterent types
rkodev Aug 21, 2024
429d1a9
Fixes import collition for types
rkodev Aug 22, 2024
b6ac6b3
Fix import types
rkodev Aug 23, 2024
4a5c2c3
Merge branch 'main' into feature/typescript/composed-types
rkodev Aug 23, 2024
fbdb569
Fix import
rkodev Aug 26, 2024
940017e
Fix unit tests
rkodev Aug 26, 2024
9ef966b
minor refactr
rkodev Aug 27, 2024
2b7f992
Find correct function
rkodev Aug 27, 2024
af4a934
fix: formatting
rkodev Aug 27, 2024
c5a4ce1
fix: unit tests
rkodev Aug 27, 2024
3c8c85b
fix: tests
rkodev Aug 27, 2024
1d69c3c
format code
rkodev Aug 27, 2024
fc5bbb9
rafactor: reduce code complexity
rkodev Aug 27, 2024
5ca3aa9
fix: String as value
rkodev Aug 27, 2024
68aefac
Merge branch 'main' into feature/typescript/composed-types
rkodev Aug 27, 2024
08469bf
feat: add unit tests
rkodev Aug 27, 2024
6ef11d5
code cleanup
rkodev Aug 28, 2024
527c700
sonar cleanup
rkodev Aug 28, 2024
7cc8f44
Merge branch 'main' into feature/typescript/composed-types
rkodev Aug 28, 2024
41efaf3
Merge branch 'main' into feature/typescript/composed-types
rkodev Aug 29, 2024
3bb9d6d
fix: compilation errors from main branch
rkodev Aug 29, 2024
d4c29c2
Update src/Kiota.Builder/CodeDOM/CodeComposedTypeBase.cs
baywet Aug 29, 2024
bbee168
fix: typo
baywet Aug 29, 2024
0b5128f
Merge branch 'main' into feature/typescript/composed-types
rkodev Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions it/config.json
andrueastman marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
}
],
"Suppressions": [
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/1812"
},
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/1816"
Expand Down Expand Up @@ -156,10 +152,6 @@
"Language": "go",
"Rationale": "https://github.com/microsoft/kiota/issues/3436"
},
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/1812"
},
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/2484"
Expand All @@ -170,10 +162,6 @@
}
],
"IdempotencySuppressions": [
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/1812"
}
]
},
"apisguru::twilio.com:api": {
Expand Down Expand Up @@ -248,7 +236,7 @@
"Suppressions": [
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/1812"
"Rationale": "https://github.com/microsoft/kiota/issues/5256"
},
{
"Language": "go",
Expand Down Expand Up @@ -280,10 +268,6 @@
"Language": "python",
"Rationale": "https://github.com/microsoft/kiota/issues/2842"
},
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/1812"
},
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/1816"
Expand Down Expand Up @@ -312,20 +296,12 @@
},
"apisguru::twitter.com:current": {
"Suppressions": [
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/1812"
},
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/1816"
}
],
"IdempotencySuppressions": [
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/1812"
}
]
},
"apisguru::apis.guru": {
Expand Down
20 changes: 20 additions & 0 deletions src/Kiota.Builder/CodeDOM/CodeComposedTypeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using static Kiota.Builder.Writers.TypeScript.TypeScriptConventionService;

namespace Kiota.Builder.CodeDOM;
/// <summary>
Expand All @@ -25,6 +26,13 @@ public bool ContainsType(CodeType codeType)
ArgumentNullException.ThrowIfNull(codeType);
return types.ContainsKey(NormalizeKey(codeType));
}
public void SetTypes(params CodeType[] codeTypes)
{
ArgumentNullException.ThrowIfNull(codeTypes);
types.Clear();
foreach (var codeType in codeTypes)
AddType(codeType);
}
private readonly ConcurrentDictionary<string, CodeType> types = new(StringComparer.OrdinalIgnoreCase);
public IEnumerable<CodeType> Types
{
Expand Down Expand Up @@ -66,9 +74,21 @@ public CodeNamespace? TargetNamespace
{
get; set;
}

public DeprecationInformation? Deprecation
{
get;
set;
}

public bool IsComposedOfPrimitives(Func<CodeType, CodeComposedTypeBase, bool> checkIfPrimitive) => Types.All(x => checkIfPrimitive(x, this));
public bool IsComposedOfObjectsAndPrimitives(Func<CodeType, CodeComposedTypeBase, bool> checkIfPrimitive)
{
// Count the number of primitives in Types
int primitiveCount = Types.Count(x => checkIfPrimitive(x, this));

// If the number of primitives is less than the total count, it means the rest are objects
return primitiveCount > 0 && primitiveCount < Types.Count();
baywet marked this conversation as resolved.
Show resolved Hide resolved
}

}
4 changes: 3 additions & 1 deletion src/Kiota.Builder/CodeDOM/CodeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public IEnumerable<T> AddElements<T>(params T[] elements) where T : CodeElement
{
if (elements == null || elements.Any(static x => x == null))

Check warning on line 16 in src/Kiota.Builder/CodeDOM/CodeFile.cs

View workflow job for this annotation

GitHub Actions / Build

Collection-specific "Exists" method should be used instead of the "Any" extension. (https://rules.sonarsource.com/csharp/RSPEC-6605)
throw new ArgumentNullException(nameof(elements));
if (elements.Length == 0)
throw new ArgumentOutOfRangeException(nameof(elements));
Expand All @@ -24,12 +24,14 @@
public IEnumerable<CodeUsing> AllUsingsFromChildElements => GetChildElements(true)
.SelectMany(static x => x.GetChildElements(false))
.OfType<ProprietableBlockDeclaration>()
.SelectMany(static x => x.Usings);
.SelectMany(static x => x.Usings)
.Union(GetChildElements(true).Where(static x => x is CodeConstant).Cast<CodeConstant>()
.SelectMany(static x => x.StartBlock.Usings));
}
public class CodeFileDeclaration : ProprietableBlockDeclaration

Check warning on line 31 in src/Kiota.Builder/CodeDOM/CodeFile.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this empty class, write its code or make it an "interface". (https://rules.sonarsource.com/csharp/RSPEC-2094)
{
}

public class CodeFileBlockEnd : BlockEnd

Check warning on line 35 in src/Kiota.Builder/CodeDOM/CodeFile.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this empty class, write its code or make it an "interface". (https://rules.sonarsource.com/csharp/RSPEC-2094)
{
}
Loading
Loading