|
| 1 | +import { |
| 2 | + GoGenerator, |
| 3 | + GO_DESCRIPTION_PRESET, |
| 4 | + GO_COMMON_PRESET, |
| 5 | + GoCommonPresetOptions |
| 6 | +} from '../../src'; |
| 7 | + |
| 8 | +const options: GoCommonPresetOptions = { addJsonTag: true }; |
| 9 | +const generator = new GoGenerator({ |
| 10 | + presets: [GO_DESCRIPTION_PRESET, { preset: GO_COMMON_PRESET, options }] |
| 11 | +}); |
| 12 | + |
| 13 | +const asyncAPIDocument = { |
| 14 | + asyncapi: '3.0.0', |
| 15 | + info: { |
| 16 | + title: 'inventoryService', |
| 17 | + version: '2.1.0' |
| 18 | + }, |
| 19 | + channels: { |
| 20 | + inventory: { |
| 21 | + address: '/inventory', |
| 22 | + messages: { |
| 23 | + updateStock: { |
| 24 | + summary: 'Update stock levels', |
| 25 | + payload: { |
| 26 | + title: 'stockUpdatePayload', |
| 27 | + type: 'object', |
| 28 | + description: 'Payload for updating stock information', |
| 29 | + required: ['productId'], |
| 30 | + additionalProperties: false, |
| 31 | + properties: { |
| 32 | + productId: { |
| 33 | + type: 'string' |
| 34 | + }, |
| 35 | + quantity: { |
| 36 | + type: 'integer', |
| 37 | + description: 'The updated quantity of the product' |
| 38 | + }, |
| 39 | + location: { |
| 40 | + type: 'string', |
| 41 | + description: 'Warehouse location of the product' |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + }, |
| 48 | + alerts: { |
| 49 | + address: '/alerts', |
| 50 | + messages: { |
| 51 | + lowStockAlert: { |
| 52 | + summary: 'Low stock level alert', |
| 53 | + payload: { |
| 54 | + title: 'lowStockPayload', |
| 55 | + type: 'object', |
| 56 | + description: 'Payload for low stock alerts', |
| 57 | + required: ['productId', 'threshold'], |
| 58 | + additionalProperties: false, |
| 59 | + properties: { |
| 60 | + productId: { |
| 61 | + type: 'string' |
| 62 | + }, |
| 63 | + threshold: { |
| 64 | + type: 'integer', |
| 65 | + description: 'The stock level threshold' |
| 66 | + }, |
| 67 | + currentStock: { |
| 68 | + type: 'integer', |
| 69 | + description: 'The current stock level' |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + }, |
| 77 | + operations: { |
| 78 | + updateInventory: { |
| 79 | + title: 'Update Inventory Operation', |
| 80 | + summary: 'Operation to update inventory stock levels', |
| 81 | + channel: { |
| 82 | + $ref: '#/channels/inventory' |
| 83 | + }, |
| 84 | + action: 'send', |
| 85 | + messages: [ |
| 86 | + { |
| 87 | + $ref: '#/channels/inventory/messages/updateStock' |
| 88 | + } |
| 89 | + ] |
| 90 | + }, |
| 91 | + notifyLowStock: { |
| 92 | + title: 'Notify Low Stock Operation', |
| 93 | + summary: 'Operation to notify when stock is low', |
| 94 | + channel: { |
| 95 | + $ref: '#/channels/alerts' |
| 96 | + }, |
| 97 | + action: 'receive', |
| 98 | + messages: [ |
| 99 | + { |
| 100 | + $ref: '#/channels/alerts/messages/lowStockAlert' |
| 101 | + } |
| 102 | + ] |
| 103 | + } |
| 104 | + } |
| 105 | +}; |
| 106 | + |
| 107 | +export async function generate(): Promise<void> { |
| 108 | + const models = await generator.generate(asyncAPIDocument); |
| 109 | + for (const model of models) { |
| 110 | + console.log(model.result); |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +if (require.main === module) { |
| 115 | + generate(); |
| 116 | +} |
0 commit comments