-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add csharp payload generator (#63)
- Loading branch information
1 parent
b83d6d1
commit 5069e44
Showing
11 changed files
with
130 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { | ||
CsharpPayloadGenerator, | ||
generateCsharpPayload, | ||
defaultCsharpPayloadGenerator | ||
} from './payloads'; | ||
|
||
export { | ||
CsharpPayloadGenerator, | ||
generateCsharpPayload, | ||
defaultCsharpPayloadGenerator | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {CSHARP_JSON_SERIALIZER_PRESET, CSharpFileGenerator} from '@asyncapi/modelina'; | ||
import {GenericCodegenContext, PayloadRenderType} from '../../types'; | ||
import {AsyncAPIDocumentInterface} from '@asyncapi/parser'; | ||
import {generateAsyncAPIPayloads} from '../helpers/payloads'; | ||
import {z} from 'zod'; | ||
|
||
export const zodCsharpPayloadGenerator = z.object({ | ||
id: z.string().optional().default('payloads-csharp'), | ||
dependencies: z.array(z.string()).optional().default([]), | ||
preset: z.literal('payloads').default('payloads'), | ||
outputPath: z.string().default('src/__gen__/payloads'), | ||
serializationType: z.literal('json').optional().default('json'), | ||
language: z.literal('csharp').optional().default('csharp'), | ||
namespace: z.string().optional().default('the.codegen.project') | ||
}); | ||
export type CsharpPayloadGenerator = z.infer< | ||
typeof zodCsharpPayloadGenerator | ||
>; | ||
|
||
export const defaultCsharpPayloadGenerator: CsharpPayloadGenerator = | ||
zodCsharpPayloadGenerator.parse({}); | ||
|
||
export interface CsharpPayloadContext extends GenericCodegenContext { | ||
inputType: 'asyncapi'; | ||
asyncapiDocument?: AsyncAPIDocumentInterface; | ||
generator: CsharpPayloadGenerator; | ||
} | ||
|
||
export async function generateCsharpPayload( | ||
context: CsharpPayloadContext | ||
): Promise<PayloadRenderType<CsharpPayloadGenerator>> { | ||
const {asyncapiDocument, inputType, generator} = context; | ||
if (inputType === 'asyncapi' && asyncapiDocument === undefined) { | ||
throw new Error('Expected AsyncAPI input, was not given'); | ||
} | ||
|
||
const modelinaGenerator = new CSharpFileGenerator({ | ||
presets: [ | ||
CSHARP_JSON_SERIALIZER_PRESET | ||
] | ||
}); | ||
return generateAsyncAPIPayloads( | ||
asyncapiDocument!, | ||
(input) => | ||
modelinaGenerator.generateToFiles( | ||
input, | ||
generator.outputPath, | ||
{namespace: generator.namespace}, | ||
true | ||
), | ||
generator | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters