Skip to content

Commit

Permalink
Merge branch 'master' into multiple-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Souvikns authored Sep 24, 2024
2 parents 2a68e4d + 60b352d commit a1f4928
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 49 deletions.
63 changes: 34 additions & 29 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $ npm install -g @asyncapi/cli
$ asyncapi COMMAND
running command...
$ asyncapi (--version)
@asyncapi/cli/2.3.12 linux-x64 node-v18.20.4
@asyncapi/cli/2.4.0 linux-x64 node-v18.20.4
$ asyncapi --help [COMMAND]
USAGE
$ asyncapi COMMAND
Expand Down Expand Up @@ -99,7 +99,7 @@ EXAMPLES
$ asyncapi bundle ./asyncapi.yaml -o final-asyncapi.yaml --base ../public-api/main.yaml --baseDir ./social-media/comments-service
```

_See code: [src/commands/bundle.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/bundle.ts)_
_See code: [src/commands/bundle.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/bundle.ts)_

## `asyncapi config`

Expand All @@ -113,7 +113,7 @@ DESCRIPTION
CLI config settings
```

_See code: [src/commands/config/index.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/index.ts)_
_See code: [src/commands/config/index.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/index.ts)_

## `asyncapi config analytics`

Expand All @@ -133,7 +133,7 @@ DESCRIPTION
Enable or disable analytics for metrics collection
```

_See code: [src/commands/config/analytics.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/analytics.ts)_
_See code: [src/commands/config/analytics.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/analytics.ts)_

## `asyncapi config context`

Expand All @@ -147,7 +147,7 @@ DESCRIPTION
Manage short aliases for full paths to AsyncAPI documents
```

_See code: [src/commands/config/context/index.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/context/index.ts)_
_See code: [src/commands/config/context/index.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/context/index.ts)_

## `asyncapi config context add CONTEXT-NAME SPEC-FILE-PATH`

Expand All @@ -169,7 +169,7 @@ DESCRIPTION
Add a context to the store
```

_See code: [src/commands/config/context/add.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/context/add.ts)_
_See code: [src/commands/config/context/add.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/context/add.ts)_

## `asyncapi config context current`

Expand All @@ -186,7 +186,7 @@ DESCRIPTION
Shows the current context that is being used
```

_See code: [src/commands/config/context/current.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/context/current.ts)_
_See code: [src/commands/config/context/current.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/context/current.ts)_

## `asyncapi config context edit CONTEXT-NAME NEW-SPEC-FILE-PATH`

Expand All @@ -207,7 +207,7 @@ DESCRIPTION
Edit a context in the store
```

_See code: [src/commands/config/context/edit.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/context/edit.ts)_
_See code: [src/commands/config/context/edit.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/context/edit.ts)_

## `asyncapi config context init [CONTEXT-FILE-PATH]`

Expand All @@ -230,7 +230,7 @@ DESCRIPTION
Initialize context
```

_See code: [src/commands/config/context/init.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/context/init.ts)_
_See code: [src/commands/config/context/init.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/context/init.ts)_

## `asyncapi config context list`

Expand All @@ -247,7 +247,7 @@ DESCRIPTION
List all the stored contexts in the store
```

_See code: [src/commands/config/context/list.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/context/list.ts)_
_See code: [src/commands/config/context/list.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/context/list.ts)_

## `asyncapi config context remove CONTEXT-NAME`

Expand All @@ -267,7 +267,7 @@ DESCRIPTION
Delete a context from the store
```

_See code: [src/commands/config/context/remove.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/context/remove.ts)_
_See code: [src/commands/config/context/remove.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/context/remove.ts)_

## `asyncapi config context use CONTEXT-NAME`

Expand All @@ -287,7 +287,7 @@ DESCRIPTION
Set a context as current
```

_See code: [src/commands/config/context/use.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/context/use.ts)_
_See code: [src/commands/config/context/use.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/context/use.ts)_

## `asyncapi config versions`

Expand All @@ -304,29 +304,34 @@ DESCRIPTION
Show versions of AsyncAPI tools used
```

_See code: [src/commands/config/versions.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/config/versions.ts)_
_See code: [src/commands/config/versions.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/config/versions.ts)_

## `asyncapi convert [SPEC-FILE]`

Convert asyncapi documents older to newer versions
Convert asyncapi documents older to newer versions or OpenAPI documents to AsyncAPI

```
USAGE
$ asyncapi convert [SPEC-FILE] [-h] [-o <value>] [-t <value>]
$ asyncapi convert [SPEC-FILE] -f openapi|asyncapi [-h] [-o <value>] [-t <value>] [-p client|server]
ARGUMENTS
SPEC-FILE spec path, url, or context-name
FLAGS
-f, --format=<option> (required) [default: asyncapi] Specify the format to convert from (openapi or asyncapi)
<options: openapi|asyncapi>
-h, --help Show CLI help.
-o, --output=<value> path to the file where the result is saved
-p, --perspective=<option> [default: server] Perspective to use when converting OpenAPI to AsyncAPI (client or
server). Note: This option is only applicable for OpenAPI to AsyncAPI conversions.
<options: client|server>
-t, --target-version=<value> [default: 3.0.0] asyncapi version to convert to
DESCRIPTION
Convert asyncapi documents older to newer versions
Convert asyncapi documents older to newer versions or OpenAPI documents to AsyncAPI
```

_See code: [src/commands/convert.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/convert.ts)_
_See code: [src/commands/convert.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/convert.ts)_

## `asyncapi diff OLD NEW`

Expand Down Expand Up @@ -366,7 +371,7 @@ DESCRIPTION
Find diff between two asyncapi files
```

_See code: [src/commands/diff.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/diff.ts)_
_See code: [src/commands/diff.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/diff.ts)_

## `asyncapi generate`

Expand All @@ -380,7 +385,7 @@ DESCRIPTION
Generate typed models or other things like clients, applications or docs using AsyncAPI Generator templates.
```

_See code: [src/commands/generate/index.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/generate/index.ts)_
_See code: [src/commands/generate/index.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/generate/index.ts)_

## `asyncapi generate fromTemplate ASYNCAPI TEMPLATE`

Expand Down Expand Up @@ -424,7 +429,7 @@ EXAMPLES
$ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --param version=1.0.0 singleFile=true --output ./docs --force-write
```

_See code: [src/commands/generate/fromTemplate.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/generate/fromTemplate.ts)_
_See code: [src/commands/generate/fromTemplate.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/generate/fromTemplate.ts)_

## `asyncapi generate models LANGUAGE FILE`

Expand Down Expand Up @@ -495,7 +500,7 @@ DESCRIPTION
Generates typed models
```

_See code: [src/commands/generate/models.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/generate/models.ts)_
_See code: [src/commands/generate/models.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/generate/models.ts)_

## `asyncapi new`

Expand Down Expand Up @@ -553,7 +558,7 @@ EXAMPLES
$ asyncapi new --file-name=my-asyncapi.yml --example=default-example.yml --no-tty - create a new file with a specific name, using one of the examples and without interactive mode
```

_See code: [src/commands/new/index.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/new/index.ts)_
_See code: [src/commands/new/index.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/new/index.ts)_

## `asyncapi new file`

Expand Down Expand Up @@ -611,7 +616,7 @@ EXAMPLES
$ asyncapi new --file-name=my-asyncapi.yml --example=default-example.yml --no-tty - create a new file with a specific name, using one of the examples and without interactive mode
```

_See code: [src/commands/new/file.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/new/file.ts)_
_See code: [src/commands/new/file.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/new/file.ts)_

## `asyncapi new glee`

Expand All @@ -633,7 +638,7 @@ DESCRIPTION
Creates a new Glee project
```

_See code: [src/commands/new/glee.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/new/glee.ts)_
_See code: [src/commands/new/glee.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/new/glee.ts)_

## `asyncapi new template`

Expand All @@ -657,7 +662,7 @@ DESCRIPTION
Creates a new template
```

_See code: [src/commands/new/template.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/new/template.ts)_
_See code: [src/commands/new/template.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/new/template.ts)_

## `asyncapi optimize [SPEC-FILE]`

Expand Down Expand Up @@ -699,7 +704,7 @@ EXAMPLES
$ asyncapi optimize ./asyncapi.yaml --ignore=schema
```

_See code: [src/commands/optimize.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/optimize.ts)_
_See code: [src/commands/optimize.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/optimize.ts)_

## `asyncapi start`

Expand All @@ -708,7 +713,7 @@ USAGE
$ asyncapi start
```

_See code: [src/commands/start/index.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/start/index.ts)_
_See code: [src/commands/start/index.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/start/index.ts)_

## `asyncapi start studio`

Expand All @@ -727,7 +732,7 @@ DESCRIPTION
starts a new local instance of Studio
```

_See code: [src/commands/start/studio.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/start/studio.ts)_
_See code: [src/commands/start/studio.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/start/studio.ts)_

## `asyncapi validate [SPEC-FILE]`

Expand Down Expand Up @@ -757,5 +762,5 @@ DESCRIPTION
validate asyncapi file
```

_See code: [src/commands/validate.ts](https://github.com/asyncapi/cli/blob/v2.3.12/src/commands/validate.ts)_
_See code: [src/commands/validate.ts](https://github.com/asyncapi/cli/blob/v2.4.0/src/commands/validate.ts)_
<!-- commandsstop -->
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@asyncapi/cli",
"description": "All in one CLI for all AsyncAPI tools",
"version": "2.3.13",
"version": "2.4.1",
"author": "@asyncapi",
"bin": {
"asyncapi": "./bin/run_bin"
Expand All @@ -10,7 +10,7 @@
"dependencies": {
"@asyncapi/avro-schema-parser": "^3.0.23",
"@asyncapi/bundler": "^0.6.3",
"@asyncapi/converter": "^1.6.1",
"@asyncapi/converter": "^1.6.2",
"@asyncapi/diff": "^0.4.1",
"@asyncapi/generator": "^1.17.25",
"generator-v2": "npm:@asyncapi/generator@^2.4.1",
Expand Down
20 changes: 15 additions & 5 deletions src/commands/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Command from '../core/base';
import { ValidationError } from '../core/errors/validation-error';
import { load } from '../core/models/SpecificationFile';
import { SpecificationFileNotFound } from '../core/errors/specification-file';
import { convert } from '@asyncapi/converter';
import type { AsyncAPIConvertVersion } from '@asyncapi/converter';
import { convert, convertOpenAPI } from '@asyncapi/converter';
import type { AsyncAPIConvertVersion, OpenAPIConvertVersion } from '@asyncapi/converter';
import { cyan, green } from 'picocolors';

// @ts-ignore
Expand All @@ -16,7 +16,7 @@ import { convertFlags } from '../core/flags/convert.flags';
const latestVersion = Object.keys(specs.schemas).pop() as string;

export default class Convert extends Command {
static description = 'Convert asyncapi documents older to newer versions';
static description = 'Convert asyncapi documents older to newer versions or OpenAPI documents to AsyncAPI';

static flags = convertFlags(latestVersion);

Expand All @@ -36,9 +36,19 @@ export default class Convert extends Command {
// eslint-disable-next-line sonarjs/no-duplicate-string
this.metricsMetadata.to_version = flags['target-version'];

// Determine if the input is OpenAPI or AsyncAPI
const specJson = this.specFile.toJson();
const isOpenAPI = flags['format'] === 'openapi';
const isAsyncAPI = flags['format'] === 'asyncapi';

// CONVERSION
convertedFile = convert(this.specFile.text(), flags['target-version'] as AsyncAPIConvertVersion);
if (convertedFile) {
if (isOpenAPI) {
convertedFile = convertOpenAPI(this.specFile.text(), specJson.openapi as OpenAPIConvertVersion, {
perspective: flags['perspective'] as 'client' | 'server'
});
this.log(`🎉 The OpenAPI document has been successfully converted to AsyncAPI version ${green(flags['target-version'])}!`);
} else if (isAsyncAPI) {
convertedFile = convert(this.specFile.text(), flags['target-version'] as AsyncAPIConvertVersion);
if (this.specFile.getFilePath()) {
this.log(`🎉 The ${cyan(this.specFile.getFilePath())} file has been successfully converted to version ${green(flags['target-version'])}!!`);
} else if (this.specFile.getFileURL()) {
Expand Down
15 changes: 14 additions & 1 deletion src/core/flags/convert.flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ export const convertFlags = (latestVersion: string) => {
return {
help: Flags.help({ char: 'h' }),
output: Flags.string({ char: 'o', description: 'path to the file where the result is saved' }),
'target-version': Flags.string({ char: 't', description: 'asyncapi version to convert to', default: latestVersion })
format: Flags.string({
char: 'f',
description: 'Specify the format to convert from (openapi or asyncapi)',
options: ['openapi', 'asyncapi'],
required: true,
default: 'asyncapi',
}),
'target-version': Flags.string({ char: 't', description: 'asyncapi version to convert to', default: latestVersion }),
perspective: Flags.string({
char: 'p',
description: 'Perspective to use when converting OpenAPI to AsyncAPI (client or server). Note: This option is only applicable for OpenAPI to AsyncAPI conversions.',
options: ['client', 'server'],
default: 'server',
}),
};
};
Loading

0 comments on commit a1f4928

Please sign in to comment.