Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
export type AsyncAPIDocument = { asyncapi: string } & Record<string, any>;
export type OpenAPIDocument = { openapi: string } & Record<string, any>;
export type AsyncAPIConvertVersion = '1.1.0' | '1.2.0' | '2.0.0-rc1' | '2.0.0-rc2' | '2.0.0' | '2.1.0' | '2.2.0' | '2.3.0' | '2.4.0' | '2.5.0' | '2.6.0' | '3.0.0';
export type AsyncAPIConvertVersion = '1.1.0' | '1.2.0' | '2.0.0-rc1' | '2.0.0-rc2' | '2.0.0' | '2.1.0' | '2.2.0' | '2.3.0' | '2.4.0' | '2.5.0' | '2.6.0' | '3.0.0' | '3.1.0';

export type OpenAPIConvertVersion = '3.0.0';
export type ConvertV2ToV3Options = {
Expand Down
7 changes: 7 additions & 0 deletions src/third-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import type { AsyncAPIDocument, ConvertOptions, ConvertV2ToV3Options, ConvertFun

export const converters: Record<string, ConvertFunction> = {
'3.0.0': from__2_6_0__to__3_0_0,
'3.1.0': from__3_0_0__to__3_1_0,
}

type RequiredConvertV2ToV3Options = Required<ConvertV2ToV3Options>;
type ConvertContext = {
refs: Map<string, string>;
};

function from__3_0_0__to__3_1_0(asyncapi: AsyncAPIDocument, options: ConvertOptions): AsyncAPIDocument {
// v3.1 only adds ROS bindings, so no only version bump is needed
asyncapi.asyncapi = '3.1.0';
return asyncapi;
}

function from__2_6_0__to__3_0_0(asyncapi: AsyncAPIDocument, options: ConvertOptions): AsyncAPIDocument {
asyncapi.asyncapi = '3.0.0';

Expand Down
260 changes: 260 additions & 0 deletions test/input/3.0.0/for-3.1.0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
asyncapi: 3.0.0
id: 'urn:example:com:smartylighting:streetlights:server'
info:
title: AsyncAPI Sample App
version: 1.0.1
description: This is a sample app.
termsOfService: 'https://asyncapi.com/terms/'
contact:
name: API Support
url: 'https://www.asyncapi.com/support'
email: support@asyncapi.org
license:
name: Apache 2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: e-commerce
- name: another-tag
description: Description...
externalDocs:
description: Find more info here
url: 'https://www.asyncapi.com'
defaultContentType: application/json
servers:
default:
host: 'api.streetlights.smartylighting.com:{port}'
protocol: mqtt
description: Test broker
variables:
port:
description: Secure connection (TLS) is available through port 8883.
default: '1883'
enum:
- '1883'
- '8883'
security:
- $ref: '#/components/securitySchemes/apiKey'
- type: oauth2
flows:
implicit:
authorizationUrl: 'https://example.com/api/oauth/dialog'
availableScopes:
'write:pets': modify pets in your account
'read:pets': read your pets
scopes:
- 'write:pets'
- type: openIdConnect
openIdConnectUrl: openIdConnectUrl
scopes:
- 'some:scope:1'
- 'some:scope:2'
production:
host: 'api.streetlights.smartylighting.com:{port}'
pathname: /some/path
protocol: mqtt
description: Test broker
variables:
port:
description: Secure connection (TLS) is available through port 8883.
default: '1883'
enum:
- '1883'
- '8883'
security:
- $ref: '#/components/securitySchemes/apiKey'
withProtocol:
host: 'api.streetlights.smartylighting.com:{port}'
pathname: /some/path
protocol: mqtt
description: Test broker
variables:
port:
description: Secure connection (TLS) is available through port 8883.
default: '1883'
enum:
- '1883'
- '8883'
security:
- $ref: '#/components/securitySchemes/apiKey'
channels:
'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured':
address: 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'
messages:
lightMeasured.message:
payload:
type: object
servers:
- $ref: '#/servers/production'
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on':
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on'
messages:
publish.message:
$ref: '#/components/messages/lightMeasured'
subscribe.message.0:
$ref: '#/components/messages/turnOnOff'
customMessageId:
payload:
type: object
subscribe.message.2:
payload:
type: object
subscribe.message.3:
$ref: 'https://example.com/message'
servers:
- $ref: '#/servers/default'
- $ref: '#/servers/production'
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
customChannelId:
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/off'
messages:
turnOnOff.message:
$ref: '#/components/messages/turnOnOff'
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
x-channelId: customChannelId
'smartylighting/streetlights/1/0/action/{streetlightId}/dim':
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/dim'
messages:
dimLight.message:
$ref: '#/components/messages/dimLight'
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
operations:
lightMeasured:
action: receive
channel:
$ref: >-
#/channels/smartylighting~1streetlights~11~10~1event~1{streetlightId}~1lighting~1measured
messages:
- $ref: >-
#/channels/smartylighting~1streetlights~11~10~1event~1{streetlightId}~1lighting~1measured/messages/lightMeasured.message
'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.publish':
action: receive
channel:
$ref: >-
#/channels/smartylighting~1streetlights~11~10~1action~1{streetlightId}~1turn~1on
messages:
- $ref: >-
#/channels/smartylighting~1streetlights~11~10~1action~1{streetlightId}~1turn~1on/messages/publish.message
'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.subscribe':
action: send
channel:
$ref: >-
#/channels/smartylighting~1streetlights~11~10~1action~1{streetlightId}~1turn~1on
messages:
- $ref: >-
#/channels/smartylighting~1streetlights~11~10~1action~1{streetlightId}~1turn~1on/messages/subscribe.message.0
- $ref: >-
#/channels/smartylighting~1streetlights~11~10~1action~1{streetlightId}~1turn~1on/messages/customMessageId
- $ref: >-
#/channels/smartylighting~1streetlights~11~10~1action~1{streetlightId}~1turn~1on/messages/subscribe.message.2
- $ref: 'https://example.com/message'
turnOnOff:
action: send
channel:
$ref: '#/channels/customChannelId'
messages:
- $ref: '#/channels/customChannelId/messages/turnOnOff.message'
dimLight:
action: send
channel:
$ref: >-
#/channels/smartylighting~1streetlights~11~10~1action~1{streetlightId}~1dim
security:
- type: oauth2
flows:
implicit:
authorizationUrl: 'https://example.com/api/oauth/dialog'
availableScopes:
'write:pets': modify pets in your account
'read:pets': read your pets
scopes:
- 'write:pets'
messages:
- $ref: >-
#/channels/smartylighting~1streetlights~11~10~1action~1{streetlightId}~1dim/messages/dimLight.message
components:
messages:
lightMeasured:
summary: >-
Inform about environmental lighting conditions for a particular
streetlight.
payload:
$ref: '#/components/schemas/lightMeasuredPayload'
turnOnOff:
summary: Command a particular streetlight to turn the lights on or off.
payload:
$ref: '#/components/schemas/turnOnOffPayload'
dimLight:
summary: Command a particular streetlight to dim the lights.
payload:
$ref: '#/components/schemas/dimLightPayload'
schemas:
lightMeasuredPayload:
type: object
properties:
lumens:
type: integer
minimum: 0
description: Light intensity measured in lumens.
sentAt:
$ref: '#/components/schemas/sentAt'
turnOnOffPayload:
type: object
properties:
command:
type: string
enum:
- 'on'
- 'off'
description: Whether to turn on or off the light.
sentAt:
$ref: '#/components/schemas/sentAt'
dimLightPayload:
type: object
properties:
percentage:
type: integer
description: Percentage to which the light should be dimmed to.
minimum: 0
maximum: 100
sentAt:
$ref: '#/components/schemas/sentAt'
sentAt:
type: string
format: date-time
description: Date and time when the message was sent.
securitySchemes:
apiKey:
type: apiKey
in: user
description: Provide your API key as the user and leave the password empty.
flows:
type: oauth2
flows:
implicit:
authorizationUrl: 'https://example.com/api/oauth/dialog'
availableScopes:
'write:pets': modify pets in your account
'read:pets': read your pets
openIdConnect:
type: openIdConnect
openIdConnectUrl: openIdConnectUrl
unusedFlows:
type: oauth2
flows:
implicit:
authorizationUrl: 'https://example.com/api/oauth/dialog'
availableScopes:
'write:pets': modify pets in your account
'read:pets': read your pets
parameters:
streetlightId:
description: The ID of the streetlight.
Loading