Skip to content

Commit

Permalink
Merge branch 'asyncapi:master' into deploy-storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
devilkiller-ag authored Jan 8, 2025
2 parents 5584d52 + 4d002ce commit a3c6bc2
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 13 deletions.
98 changes: 98 additions & 0 deletions markdown/docs/tools/cli/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
title: 'CLI Architecture'
weight: 40
---

The AsyncAPI CLI uses oclif (Open CLI Framework) as its core framework, which enables developers to build powerful and scalable command-line applications.

**Structure of the AsyncAPI CLI**: The CLI is primarily divided into two components: commands and the core part.

1. **Command Component**: The commands include all the necessary functionalities that help developers interact with features like creating new AsyncAPI projects, validating AsyncAPI files, formatting AsyncAPI files, and more.
2. **Core Component**: The core part of the CLI contains various utilities that facilitate the efficient creation of new commands.

---

### **Detailed Explanation of Key Directories in the CLI**

#### **`src/commands/`**
- **Purpose:** Implements the CLI commands available to the user.
- **Subdirectories:**
- `config/`: Stores configuration-related files for commands.
- `generate/`: Generates typed models or other artifacts like clients, applications, or documentation using AsyncAPI Generator templates.
- **Files:**
- `fromTemplate.ts`: Contains logic for generating files using templates.
- `models.ts`: Defines the models used during generation.
- `new/`: Creates a new AsyncAPI file.
- **Files:**
- `file.ts`: Handles file creation logic.
- `glee.ts`: Related to Glee, a tool for event-driven microservices.
- `template.ts`: Manages templates for new projects.
- `start/`: Implements starting functionalities like launching a local server or studio.
- **Files:**
- `studio.ts`: Integrates with the AsyncAPI Studio.

- **Standalone Files:**
- `bundle.ts`: Bundles one or multiple AsyncAPI documents and their references together.
- `convert.ts`: Converts AsyncAPI documents from older to newer versions or transforms OpenAPI/Postman-collection documents into AsyncAPI.
- `diff.ts`: Compares two AsyncAPI documents.
- `format.ts`: Converts AsyncAPI documents from any format to YAML, YML, or JSON.
- `optimize.ts`: Optimizes AsyncAPI documents for performance.
- `pretty.ts`: Beautifies the AsyncAPI spec file (indentation, styling) in place or outputs the formatted spec to a new file.
- `validate.ts`: Validates AsyncAPI documents for correctness.

---

#### **`src/core/`**
- **Purpose:** Provides foundational components and utilities for the CLI.
- **Subdirectories:**
- `errors/`: Centralized error definitions.
- `flags/`: Defines CLI flags and their behavior.
- `hooks/`: Event hooks used for customization.
- `models/`: Core data models used across the application.
- `utils/`: Utility functions for common operations.

- **Standalone Files:**
- `base.ts`: Base class or logic for CLI commands.
- `global.d.ts`: Global TypeScript definitions.
- `globals.ts`: Stores global variables and configurations.
- `parser.ts`: Parses AsyncAPI documents.

---

#### **`test/`**
- **Purpose:** Implements the test suite for the CLI.
- **Subdirectories:**
- `fixtures/`: Contains mock data or files for testing.
- `hooks/`: Tests related to hooks.
- `integration/`: Integration tests to verify end-to-end functionality.
- `system/`: System-level tests.
- `unit/`: Unit tests for individual modules or functions.

---

### **Use Cases**

1. **Generate AsyncAPI Artifacts:**
- Use the `generate` command to create client/server code, documentation, or other artifacts based on AsyncAPI templates.

2. **Create New Projects:**
- The `new` command helps users scaffold new AsyncAPI projects with predefined templates.

3. **Validate AsyncAPI Documents:**
- The `validate` command ensures AsyncAPI documents conform to the specification.

4. **Optimize and Format Documents:**
- The `optimize` and `pretty` commands provide tools for improving document readability and performance.

5. **Compare Documents:**
- The `diff` command enables comparison between two AsyncAPI documents to track changes.

6. **Integration with AsyncAPI Studio:**
- The `start` command integrates with the AsyncAPI Studio for editing and visualizing documents.

7. **Convert Between Formats:**
- The `convert` command supports converting AsyncAPI documents between formats like YAML and JSON.

---

This structure ensures the CLI is modular, scalable, and easy to maintain. Let me know if you need further clarification or additional details!
2 changes: 1 addition & 1 deletion markdown/docs/tools/cli/context.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: 'Context concept'
weight: 50
weight: 60
---

## Overview
Expand Down
2 changes: 1 addition & 1 deletion markdown/docs/tools/cli/metrics_collection.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: 'Metrics Collection'
weight: 60
weight: 70
---

# Metrics collection guideline
Expand Down
35 changes: 24 additions & 11 deletions markdown/docs/tools/cli/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ USAGE
* [`asyncapi config context remove CONTEXT-NAME`](#asyncapi-config-context-remove-context-name)
* [`asyncapi config context use CONTEXT-NAME`](#asyncapi-config-context-use-context-name)
* [`asyncapi config versions`](#asyncapi-config-versions)
* [`asyncapi convert [SPEC-FILE]`](#asyncapi-convert-spec-file)
* [`asyncapi convert [SPEC-FILE] [PROXYHOST] [PROXYPORT]`](#asyncapi-convert-spec-file-proxyhost-proxyport)
* [`asyncapi diff OLD NEW`](#asyncapi-diff-old-new)
* [`asyncapi format [SPEC-FILE]`](#asyncapi-format-spec-file)
* [`asyncapi generate`](#asyncapi-generate)
Expand All @@ -60,11 +60,11 @@ USAGE
* [`asyncapi new file`](#asyncapi-new-file)
* [`asyncapi new glee`](#asyncapi-new-glee)
* [`asyncapi new template`](#asyncapi-new-template)
* [`asyncapi optimize [SPEC-FILE]`](#asyncapi-optimize-spec-file)
* [`asyncapi optimize [SPEC-FILE] [PROXYHOST] [PROXYPORT]`](#asyncapi-optimize-spec-file-proxyhost-proxyport)
* [`asyncapi pretty SPEC-FILE`](#asyncapi-pretty-spec-file)
* [`asyncapi start`](#asyncapi-start)
* [`asyncapi start studio`](#asyncapi-start-studio)
* [`asyncapi validate [SPEC-FILE]`](#asyncapi-validate-spec-file)
* [`asyncapi validate [SPEC-FILE] [PROXYHOST] [PROXYPORT]`](#asyncapi-validate-spec-file-proxyhost-proxyport)

## `asyncapi bundle`

Expand Down Expand Up @@ -308,17 +308,19 @@ DESCRIPTION

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

## `asyncapi convert [SPEC-FILE]`
## `asyncapi convert [SPEC-FILE] [PROXYHOST] [PROXYPORT]`

Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI

```
USAGE
$ asyncapi convert [SPEC-FILE] -f openapi|asyncapi|postman-collection [-h] [-o <value>] [-t <value>] [-p
client|server]
$ asyncapi convert [SPEC-FILE] [PROXYHOST] [PROXYPORT] -f openapi|asyncapi|postman-collection [-h] [-o
<value>] [-t <value>] [-p client|server] [--proxyHost <value>] [--proxyPort <value>]
ARGUMENTS
SPEC-FILE spec path, url, or context-name
PROXYHOST Name of the Proxy Host
PROXYPORT Name of the Port of the ProxyHost
FLAGS
-f, --format=<option> (required) [default: asyncapi] Specify the format to convert from (openapi or asyncapi)
Expand All @@ -329,6 +331,8 @@ FLAGS
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
--proxyHost=<value> Name of the ProxyHost
--proxyPort=<value> Port number number for the proxyHost.
DESCRIPTION
Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI
Expand Down Expand Up @@ -691,18 +695,20 @@ DESCRIPTION

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

## `asyncapi optimize [SPEC-FILE]`
## `asyncapi optimize [SPEC-FILE] [PROXYHOST] [PROXYPORT]`

optimize asyncapi specification file

```
USAGE
$ asyncapi optimize [SPEC-FILE] [-h] [-p
$ asyncapi optimize [SPEC-FILE] [PROXYHOST] [PROXYPORT] [-h] [-p
remove-components|reuse-components|move-duplicates-to-components|move-all-to-components...] [-i schema...] [-o
terminal|new-file|overwrite] [--no-tty]
terminal|new-file|overwrite] [--no-tty] [--proxyHost <value>] [--proxyPort <value>]
ARGUMENTS
SPEC-FILE spec path, url, or context-name
PROXYHOST Name of the Proxy Host
PROXYPORT Name of the Port of the ProxyHost
FLAGS
-h, --help Show CLI help.
Expand All @@ -715,6 +721,8 @@ FLAGS
<options: remove-components|reuse-components|move-duplicates-to-components|move-all-to
-components>
--no-tty do not use an interactive terminal
--proxyHost=<value> Name of the ProxyHost
--proxyPort=<value> Port number number for the proxyHost.
DESCRIPTION
optimize asyncapi specification file
Expand Down Expand Up @@ -791,17 +799,20 @@ DESCRIPTION

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

## `asyncapi validate [SPEC-FILE]`
## `asyncapi validate [SPEC-FILE] [PROXYHOST] [PROXYPORT]`

validate asyncapi file

```
USAGE
$ asyncapi validate [SPEC-FILE] [-h] [-w] [--log-diagnostics] [--diagnostics-format
$ asyncapi validate [SPEC-FILE] [PROXYHOST] [PROXYPORT] [-h] [-w] [--log-diagnostics] [--diagnostics-format
json|stylish|junit|html|text|teamcity|pretty] [--fail-severity error|warn|info|hint] [-o <value>] [--score]
[--proxyHost <value>] [--proxyPort <value>]
ARGUMENTS
SPEC-FILE spec path, url, or context-name
PROXYHOST Name of the Proxy Host
PROXYPORT Name of the Port of the ProxyHost
FLAGS
-h, --help Show CLI help.
Expand All @@ -813,6 +824,8 @@ FLAGS
code
<options: error|warn|info|hint>
--[no-]log-diagnostics log validation diagnostics or not
--proxyHost=<value> Name of the ProxyHost
--proxyPort=<value> Port number number for the proxyHost.
--score Compute the score of the AsyncAPI document. Scoring is based on whether the
document has description, license, server and/or channels.
Expand Down

0 comments on commit a3c6bc2

Please sign in to comment.