modelina
modelina copied to clipboard
feat: add nullable object in ts generator
Description
When a model with a composed type of ['object', 'null'], the TS generator will generate an Inner type for the object and create a nullable type alias.
Example (from the tests):
The following model,
{
$id: 'NullableObject',
type: ['object', 'null'],
properties: {
foo: {
type: 'string'
},
},
additionalProperties: false,
}
Will generate the following code:
interface NullableObjectInner {
foo?: string;
}
type NullableObject = NullableObjectInner | null;
or
class NullableObjectInner {
private _foo?: string;
constructor(input: {
foo?: string,
}) {
this._foo = input.foo;
}
get foo(): string | undefined { return this._foo; }
set foo(foo: string | undefined) { this._foo = foo; }
}
type NullableObject = NullableObjectInner | null;
Related issue(s)
Fixes #754
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
Pull Request Test Coverage Report for Build 2346704745
- 14 of 15 (93.33%) changed or added relevant lines in 3 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage decreased (-0.004%) to 92.101%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| src/generators/typescript/TypeScriptGenerator.ts | 8 | 9 | 88.89% |
| <!-- | Total: | 14 | 15 |
| Totals | |
|---|---|
| Change from base Build 2345953286: | -0.004% |
| Covered Lines: | 2817 |
| Relevant Lines: | 2916 |