Skip to content

Commit

Permalink
feat!: expand format for integer types for C# (#2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
jespitae authored Jun 21, 2024
1 parent 3d2d085 commit e717c00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/generators/csharp/CSharpConstrainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 14 additions & 1 deletion test/generators/csharp/CSharpConstrainer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,27 @@ describe('CSharpConstrainer', () => {
});
});
describe('Integer', () => {
test('should render type', () => {
test('should render int', () => {
const model = new ConstrainedIntegerModel('test', undefined, {}, '');
const type = CSharpDefaultTypeMapping.Integer({
constrainedModel: model,
...defaultOptions
});
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', () => {
Expand Down

0 comments on commit e717c00

Please sign in to comment.