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!: expand format for integer types for C# #2054

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
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
10 changes: 9 additions & 1 deletion test/generators/csharp/CSharpConstrainer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,22 @@
});
});
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 ConstrainedIntegerModel('test', undefined, { format: 'int64' }, '');

Check failure on line 87 in test/generators/csharp/CSharpConstrainer.spec.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - macos-latest

Replace `'test',·undefined,·{·format:·'int64'·},·''` with `⏎········'test',⏎········undefined,⏎········{·format:·'int64'·},⏎········''⏎······`
const type = CSharpDefaultTypeMapping.Integer({
constrainedModel: model,
...defaultOptions
});
expect(type).toEqual('long');
});
});
describe('String', () => {
test('should render type', () => {
Expand Down
Loading