From e717c00cfecbed88ef87d2cc18cec633f3a2c01e Mon Sep 17 00:00:00 2001 From: jespitae Date: Fri, 21 Jun 2024 11:47:18 +0200 Subject: [PATCH] feat!: expand format for integer types for C# (#2054) --- src/generators/csharp/CSharpConstrainer.ts | 9 +++++++-- test/generators/csharp/CSharpConstrainer.spec.ts | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/generators/csharp/CSharpConstrainer.ts b/src/generators/csharp/CSharpConstrainer.ts index 8b880be84d..15dcb6e459 100644 --- a/src/generators/csharp/CSharpConstrainer.ts +++ b/src/generators/csharp/CSharpConstrainer.ts @@ -51,8 +51,13 @@ export const CSharpDefaultTypeMapping: CSharpTypeMapping = { Float({ partOfProperty }): string { return getFullTypeDefinition('double', partOfProperty); }, - Integer({ partOfProperty }): string { - return getFullTypeDefinition('int', partOfProperty); + Integer({ constrainedModel, partOfProperty }): string { + switch (constrainedModel.options.format) { + case 'int64': + return getFullTypeDefinition('long', partOfProperty); + default: + return getFullTypeDefinition('int', partOfProperty); + } }, String({ constrainedModel, partOfProperty }): string { switch (constrainedModel.options.format) { diff --git a/test/generators/csharp/CSharpConstrainer.spec.ts b/test/generators/csharp/CSharpConstrainer.spec.ts index 69c55382db..d3b0368e06 100644 --- a/test/generators/csharp/CSharpConstrainer.spec.ts +++ b/test/generators/csharp/CSharpConstrainer.spec.ts @@ -75,7 +75,7 @@ describe('CSharpConstrainer', () => { }); }); describe('Integer', () => { - test('should render type', () => { + test('should render int', () => { const model = new ConstrainedIntegerModel('test', undefined, {}, ''); const type = CSharpDefaultTypeMapping.Integer({ constrainedModel: model, @@ -83,6 +83,19 @@ describe('CSharpConstrainer', () => { }); expect(type).toEqual('int'); }); + test('should render long', () => { + const model = new ConstrainedStringModel( + 'test', + undefined, + { format: 'int64' }, + '' + ); + const type = CSharpDefaultTypeMapping.Integer({ + constrainedModel: model, + ...defaultOptions + }); + expect(type).toEqual('long'); + }); }); describe('String', () => { test('should render type', () => {