-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat golang: fixed all the tests, added 'goIncludeTags' flag, added t…
…est for go description, removed previously added -i flag, removed unused code and fixed formatting, added modelina_cli/test/fixtures/generate to linter exclusions
- Loading branch information
Владислав Муранов
committed
Nov 5, 2024
1 parent
ddf971c
commit 9c471ce
Showing
23 changed files
with
319 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Go Data Models from AsyncAPI | ||
|
||
A basic example of how to use Modelina and output a Go data model from AsyncAPI, including data tags and comments from description. | ||
|
||
## How to run this example | ||
|
||
Run this example using: | ||
|
||
```sh | ||
npm i && npm run start | ||
``` | ||
|
||
If you are on Windows, use the `start:windows` script instead: | ||
|
||
```sh | ||
npm i && npm run start:windows | ||
``` |
14 changes: 14 additions & 0 deletions
14
examples/generate-go-asyncapi-comments/__snapshots__/index.spec.ts.snap
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,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Should be able to render Go Models and should log expected output to console 1`] = ` | ||
Array [ | ||
"// this is an object | ||
type ExampleStruct struct { | ||
Id int \`json:\\"id,omitempty\\"\` | ||
// this is example msg uid | ||
MsgUid string \`json:\\"msgUid\\" binding:\\"required\\"\` | ||
// this is example event name | ||
EvtName string \`json:\\"evtName,omitempty\\"\` | ||
}", | ||
] | ||
`; |
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,15 @@ | ||
const spy = jest.spyOn(global.console, 'log').mockImplementation(() => { | ||
return; | ||
}); | ||
import { generate } from './index'; | ||
|
||
describe('Should be able to render Go Models', () => { | ||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
test('and should log expected output to console', async () => { | ||
await generate(); | ||
expect(spy.mock.calls.length).toEqual(1); | ||
expect(spy.mock.calls[0]).toMatchSnapshot(); | ||
}); | ||
}); |
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,64 @@ | ||
import { | ||
GoGenerator, | ||
GO_DESCRIPTION_PRESET, | ||
GO_COMMON_PRESET, | ||
GoCommonPresetOptions | ||
} from '../../src'; | ||
import { Parser } from '@asyncapi/parser'; | ||
import { TypeScriptGenerator } from '../../src'; | ||
const generatorts = new TypeScriptGenerator(); | ||
const options: GoCommonPresetOptions = { addJsonTag: true }; | ||
const generator = new GoGenerator({ | ||
presets: [GO_DESCRIPTION_PRESET, { preset: GO_COMMON_PRESET, options }] | ||
}); | ||
|
||
const AsyncAPIDocumentText = ` | ||
asyncapi: 3.0.0 | ||
info: | ||
title: example | ||
version: 0.0.1 | ||
channels: | ||
root: | ||
address: / | ||
messages: | ||
exampleRequest: | ||
summary: example operation | ||
payload: | ||
title: exampleStruct | ||
type: object | ||
description: this is an object | ||
required: | ||
- msgUid | ||
additionalProperties: false | ||
properties: | ||
id: | ||
type: integer | ||
msgUid: | ||
type: string | ||
description: this is example msg uid | ||
evtName: | ||
type: string | ||
description: this is example event name | ||
operations: | ||
exampleOperation: | ||
title: This is an example operation | ||
summary: To do something | ||
channel: | ||
$ref: '#/channels/root' | ||
action: send | ||
messages: | ||
- $ref: '#/channels/root/messages/exampleRequest' | ||
`; | ||
|
||
export async function generate(): Promise<void> { | ||
const parser = new Parser(); | ||
const { document } = await parser.parse(AsyncAPIDocumentText); | ||
const models = await generator.generate(document); | ||
for (const model of models) { | ||
console.log(model.result); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
generate(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 @@ | ||
{ | ||
"config": { | ||
"example_name": "generate-go-asyncapi-comments" | ||
}, | ||
"scripts": { | ||
"install": "cd ../.. && npm i", | ||
"start": "../../node_modules/.bin/ts-node --cwd ../../ ./examples/$npm_package_config_example_name/index.ts", | ||
"start:windows": "..\\..\\node_modules\\.bin\\ts-node --cwd ..\\..\\ .\\examples\\%npm_package_config_example_name%\\index.ts", | ||
"test": "../../node_modules/.bin/jest --config=../../jest.config.js ./examples/$npm_package_config_example_name/index.spec.ts", | ||
"test:windows": "..\\..\\node_modules\\.bin\\jest --config=..\\..\\jest.config.js examples/%npm_package_config_example_name%/index.spec.ts" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/lib | ||
/tmp | ||
/scripts | ||
/test/helpers/init.js | ||
/test/helpers/init.js | ||
/test/fixtures/generate |
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
Oops, something went wrong.