Skip to content

Commit

Permalink
Revert "Revert "Revert "feat: fixed data tags, description preset for…
Browse files Browse the repository at this point in the history
… Go, add goIncludeComments and goIncludeTags flags (asyncapi#2123)"""

This reverts commit 17c25ab.
  • Loading branch information
jonaslagoni committed Jan 24, 2025
1 parent 17c25ab commit 3cf151d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
3 changes: 1 addition & 2 deletions modelina-cli/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/lib
/tmp
/scripts
/test/helpers/init.js
/test/fixtures/generate
/test/helpers/init.js
4 changes: 2 additions & 2 deletions modelina-cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export default class Models extends ModelinaCommand {
try {
document = await readFile(file, 'utf8');
} catch {
throw new Error(`Unable to read input file content: ${file}`);
throw new Error('Unable to read input file content.');
}

const logger = {
info: (message: string) => {
this.log(message);
Expand Down
29 changes: 5 additions & 24 deletions modelina-cli/src/helpers/go.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import { GO_DESCRIPTION_PRESET, GO_COMMON_PRESET, GoCommonPresetOptions, GoFileGenerator } from "@asyncapi/modelina";
import { GoFileGenerator } from "@asyncapi/modelina";
import { BuilderReturnType } from "./generate";
import { Flags } from "@oclif/core";

export const GoOclifFlags = {
goIncludeComments: Flags.boolean({
description: 'Golang specific, if enabled add comments while generating models.',
required: false,
default: false,
}),
goIncludeTags: Flags.boolean({
description: 'Golang specific, if enabled add tags while generating models.',
required: false,
default: false,
}),
}
export const GoOclifFlags = { }

/**
* This function builds all the relevant information for the main generate command
Expand All @@ -22,20 +10,13 @@ export const GoOclifFlags = {
* @returns
*/
export function buildGoGenerator(flags: any): BuilderReturnType {
const { packageName, goIncludeComments, goIncludeTags } = flags;

const { packageName } = flags;
if (packageName === undefined) {
throw new Error('In order to generate models to Go, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.');
}

const presets = []
if (goIncludeTags) {
const options: GoCommonPresetOptions = { addJsonTag: true };
presets.push({ preset: GO_COMMON_PRESET, options })
}

if (goIncludeComments) { presets.push(GO_DESCRIPTION_PRESET); }
const fileGenerator = new GoFileGenerator({ presets });
const fileGenerator = new GoFileGenerator();
const fileOptions = {
packageName
};
Expand Down

0 comments on commit 3cf151d

Please sign in to comment.