Skip to content

Commit

Permalink
Fixed examples/csharp-overwrite-enum-naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Jul 28, 2022
1 parent 5532439 commit 8bcd5c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Array [
{
Ordered,
UnderDelivery,
Deliveret,
Delivered,
Cancelled
}
Expand All @@ -18,7 +18,7 @@ public static class OrderStatusExtensions
{
case OrderStatus.Ordered: return 30;
case OrderStatus.UnderDelivery: return 40;
case OrderStatus.Deliveret: return 50;
case OrderStatus.Delivered: return 50;
case OrderStatus.Cancelled: return 99;
}
return null;
Expand All @@ -30,7 +30,7 @@ public static class OrderStatusExtensions
{
case 30: return OrderStatus.Ordered;
case 40: return OrderStatus.UnderDelivery;
case 50: return OrderStatus.Deliveret;
case 50: return OrderStatus.Delivered;
case 99: return OrderStatus.Cancelled;
}
return null;
Expand Down
30 changes: 13 additions & 17 deletions examples/csharp-overwrite-enum-naming/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { CSharpGenerator } from '../../src';
import { DefaultEnumKeyConstraints } from '../../src/generators/csharp/constrainer/EnumConstrainer';

const generator = new CSharpGenerator({
presets: [
{
enum: {
item: ({model, item, content}) => {
// Lets see if an enum has any associated names
const hasCustomName = model.originalInput !== undefined && model.originalInput['x-enumNames'] !== undefined;
if (hasCustomName) {
// Lets see if the specific value has an associated name
const customName = model.originalInput['x-enumNames'][item];
if (customName !== undefined) {
return customName;
}
}
return content;
const generator = new CSharpGenerator({
constraints: {
enumKey: ({enumModel, enumKey}) => {
// Lets see if an enum has an associated custom name
const hasCustomName = enumModel.originalInput !== undefined && enumModel.originalInput['x-enumNames'] !== undefined;
if (hasCustomName) {
// Lets see if the specific value has an associated name
const customName = enumModel.originalInput['x-enumNames'][enumKey];
if (customName !== undefined) {
return customName;
}
}
}
]
}
});

const jsonSchemaDraft7 = {
Expand All @@ -34,7 +30,7 @@ const jsonSchemaDraft7 = {
'x-enumNames': {
30: 'Ordered',
40: 'UnderDelivery',
50: 'Deliveret',
50: 'Delivered',
99: 'Cancelled'
}
};
Expand Down

0 comments on commit 8bcd5c7

Please sign in to comment.