1.4.19 • Published 16 days ago

@asyncapi/converter v1.4.19

Weekly downloads
51
License
Apache-2.0
Repository
github
Last release
16 days ago

AsyncAPI Converter

Convert AsyncAPI documents older to newer versions.

All Contributors

Installation

npm i @asyncapi/converter

Usage

From CLI

To convert an AsyncAPI document in the console needs the official AsyncAPI CLI.

If you don't have CLI installed, run this command to install the CLI globally on your system:

npm install -g @asyncapi/cli

Minimal usage example with output given:

asyncapi convert streetlights.yml -o streetlights2.yml

# Result:
asyncapi: '2.0.0'
channels:
...

Convert to a specific version:

asyncapi convert streetlights.yml -o streetlights2.yml -t 2.3.0

# Result:
asyncapi: '2.3.0'
channels:
...

In JS

const fs = require('fs');
const { convert } = require('@asyncapi/converter')

try {
  const asyncapi = fs.readFileSync('streetlights.yml', 'utf-8')
  console.log(convert(asyncapi, '2.6.0'));
} catch (e) {
  console.error(e);
}

In TS

import { convert } from '@asyncapi/converter';
import type { ConvertVersion, ConvertOptions } from '@asyncapi/converter';

try {
  const toVersion: ConvertVersion = '2.6.0';
  const asyncapi = fs.readFileSync('streetlights.yml', 'utf-8')
  console.log(convert(asyncapi, toVersion));
} catch (e) {
  console.error(e)
}

Conversion 2.x.x to 3.x.x

NOTE: This feature is still WIP, and is until the final release of 3.0.0.

Conversion to version 3.x.x from 2.x.x has several assumptions that should be known before converting:

  • The input must be valid AsyncAPI document.
  • External references are not resolved and converted, they remain untouched, even if they are incorrect.
  • In version 3.0.0, the channel identifier is no longer its address, but due to the difficulty of defining a unique identifier, we still treat the address as an identifier. If there is a need to assign an identifier other than an address, an x-channelId extension should be defined at the level of the given channel.

    # 2.x.x
    channels:
      users/signup:
        x-channelId: 'userSignUp'
        ...
      users/logout:
        ...
    
    # 3.0.0
    channels:
      userSignUp:
        ...
      users/logout:
        ...
  • The publish operation is treated as a receive action, and subscribe is treated as a send action. Conversion by default is embraced from the application perspective. If you want to change this logic, you need to specify v2tov3.pointOfView configuration as client.

  • If the operation does not have an operationId field defined, the unique identifier of the operation will be defined as a combination of the identifier of the channel on which the operation was defined + the type of operation, publish or subscribe. Identical situation is with messages. However, here the priority is the messageId field and then the concatenation {publish|subscribe}.messages.{optional index of oneOf messages}.

    # 2.x.x
    channels:
      users/signup:
        publish:
          message:
            ...
        subscribe:
          operationId: 'userSignUpEvent'
          message:
            oneOf:
              - messageId: 'userSignUpEventMessage'
                ...
              - ...
          

3.0.0

channels: users/signup: messages: publish.message: ... userSignUpEventMessage: ... userSignUpEvent.message.1: ... operations: users/signup.publish: action: receive ... userSignUpEvent: action: send ...

- Security requirements that use scopes are defined in the appropriate places inline, the rest as a reference to the `components.securitySchemes` objects.
- If servers are defined at the channel level, they are converted as references to the corresponding objects defined in the `servers` field.
- Channels and servers defined in components are also converted (unless configured otherwise).

## Known missing features

* When converting from 1.x to 2.x, Streaming APIs (those using `stream` instead of `topics` or `events`) are converted correctly but information about framing type and delimiter is missing until a [protocolInfo](https://github.com/asyncapi/extensions-catalog/issues/1) for that purpose is created.
* When converting from 2.x to 3.x, and `parameter.schema` is defined with a reference, it will NOT look into the schema reference and include any relevant keywords for the v3 parameter. It will just create an empty parameter but leave the schema in the components section as is.
```yaml
# 2.x.x
channels:
  "{myParameter}":
    parameters: 
      myParameter: 
        schema: 
          $ref: "#/components/schemas/mySchema"
components: 
  schemas:
    mySchema:
      enum: ["test"]
      default: "test"
      examples: ["test"]

# 3.0.0
channels:
  "{myParameter}":
    parameters: 
      myParameter: {}

components: 
  schemas:
    mySchema:
      enum: ["test"]
      default: "test"
      examples: ["test"]

Development

  1. Setup project by installing dependencies npm install
  2. Write code and tests.
  3. Make sure all tests pass npm test

Contribution

Read CONTRIBUTING guide.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

1.4.19

16 days ago

1.4.18

19 days ago

1.4.17

1 month ago

1.4.16

1 month ago

1.4.13

2 months ago

1.4.15

2 months ago

1.4.14

2 months ago

1.4.12

2 months ago

1.4.11

3 months ago

1.4.10

3 months ago

1.4.9

3 months ago

1.4.8

3 months ago

1.4.7

5 months ago

1.4.6

5 months ago

1.4.5

5 months ago

1.4.4

5 months ago

1.4.3

5 months ago

1.4.2

6 months ago

1.4.1

6 months ago

1.4.0

6 months ago

1.3.3

7 months ago

1.3.2

9 months ago

1.3.1

10 months ago

1.3.0

10 months ago

1.2.1

11 months ago

1.2.0

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago

0.11.0

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.7.2

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.6.2

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.3

3 years ago