Skip to content

Commit 5078959

Browse files
committed
feat(runtime): map date formats to Date and verify TS marshalling
1 parent 7fea54f commit 5078959

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

examples/integrate-with-next/package-lock.json

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generators/typescript/TypeScriptConstrainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const TypeScriptDefaultTypeMapping: TypeScriptTypeMapping = {
3232
},
3333
String({ constrainedModel }): string {
3434
const format = constrainedModel?.options?.format;
35-
if(format ==="date-time" || format ==="date"|| format ==='time'){
35+
if (format === 'date-time' || format === 'date' || format === 'time') {
3636
return applyNullable(constrainedModel, 'Date');
3737
}
3838
return applyNullable(constrainedModel, 'string');

test/runtime/generic-input-all.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"string_type": {
77
"type": "string"
88
},
9+
"createdAt": {
10+
"type": "string",
11+
"format": "date-time"
12+
},
913
"number_type": {
1014
"type": "number"
1115
},

test/runtime/runtime-typescript/test/Marshalling.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ describe('Marshalling', () => {
99
test: 'test'
1010
});
1111
const testObject = new TestObject({
12-
stringType: 'test',
12+
createdAt: new Date('2023-01-01T10:00:00Z'),
13+
stringType: 'test',
1314
numberType: 1,
1415
booleanType: true,
1516
arrayType: [1, 'test'],
@@ -18,12 +19,13 @@ describe('Marshalling', () => {
1819
additionalProperties: new Map(Object.entries({"test": "test"})),
1920
enumType: EnumType.CURLYLEFT_QUOTATION_TEST_QUOTATION_COLON_2_CURLYRIGHT,
2021
tupleType: ['test', 1],
21-
unionType: 'test'
22+
unionType: 'test',
2223
});
2324
test('be able to serialize model', () => {
2425
const serialized = testObject.marshal();
25-
expect(serialized).toEqual("{\"string_type\": \"test\",\"number_type\": 1,\"boolean_type\": true,\"union_type\": \"test\",\"array_type\": [1,\"test\"],\"tuple_type\": [\"test\",1],\"object_type\": {\"test\": \"test\"},\"dictionary_type\": {},\"enum_type\": \"{\\\"test\\\":2}\",\"test\": \"test\"}");
26-
});
26+
expect(serialized).toEqual(
27+
"{\"string_type\": \"test\",\"createdAt\": \"2023-01-01T10:00:00.000Z\",\"number_type\": 1,\"boolean_type\": true,\"union_type\": \"test\",\"array_type\": [1,\"test\"],\"tuple_type\": [\"test\",1],\"object_type\": {\"test\": \"test\"},\"dictionary_type\": {},\"enum_type\": \"{\\\"test\\\":2}\",\"test\": \"test\"}"
28+
);});
2729
test('be able to serialize model and turning it back to a model with the same values', () => {
2830
const serialized = testObject.marshal();
2931
const newAddress = TestObject.unmarshal(serialized);

0 commit comments

Comments
 (0)