Skip to content

Commit

Permalink
Fix unwanted sorting components (#11)
Browse files Browse the repository at this point in the history
* Fix for unwanted sorting of components

Co-authored-by: Tim <>
  • Loading branch information
thim81 authored Jan 28, 2022
1 parent 69a9f46 commit bf0d7e4
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 15 deletions.
16 changes: 10 additions & 6 deletions asyncapi-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@ async function asyncapiSort(oaObj, options) {
sortedObj[keyRes] = prioritySort(sortedObj[keyRes], sortSet[this.key]);
}
this.update(sortedObj);
} else if (this.path[0] === 'components' && this.path[3] === 'examples') {
// debugStep = 'Generic sorting - skip nested components>examples'
// Skip nested components>examples values
} else {
debugStep = 'Generic sorting - properties'
// Sort list of properties
this.update(prioritySort(node, sortSet[this.key]));
if (this.path[0] === 'components' && (this.path[3] === 'examples' ||
(this.parent && this.parent.key === 'components'))) {
// debugStep = 'Generic sorting - skip nested components>examples'
// Skip nested components>examples values
// Skip component objects that are not in the sortComponentsSet
} else {
// debugStep = 'Generic sorting - properties'
// Sort list of properties
this.update(prioritySort(node, sortSet[this.key]));
}
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions test/yaml-custom/output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ components:
schema:
type: string
messages:
dimLight:
name: dimLight
title: Dim light
summary: Command a particular streetlight to dim the lights.
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: '#/components/schemas/dimLightPayload'
lightMeasured:
name: lightMeasured
title: Light measured
Expand All @@ -74,6 +66,14 @@ components:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: '#/components/schemas/turnOnOffPayload'
dimLight:
name: dimLight
title: Dim light
summary: Command a particular streetlight to dim the lights.
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: '#/components/schemas/dimLightPayload'
schemas:
lightMeasuredPayload:
type: object
Expand Down
2 changes: 1 addition & 1 deletion test/yaml-filter-unused-components-period/output.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: '2.2.0'
asyncapi: 2.2.0
channels:
smartylighting.streetlights.1.0.action.{streetlightId}.turn.on:
subscribe:
Expand Down
6 changes: 6 additions & 0 deletions test/yaml-sort-skip-components/customSortComponents.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- schemas
#- messages
- parameters
- messageTraits
- operationTraits
- securitySchemes
249 changes: 249 additions & 0 deletions test/yaml-sort-skip-components/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
asyncapi: 2.2.0
info:
title: Streetlights Kafka API
version: 1.0.0
description: |
The Smartylighting Streetlights API allows you to remotely manage the city lights.
### Check out its awesome features:
* Turn a specific streetlight on/off 🌃
* Dim a specific streetlight 😎
* Receive real-time information about environmental lighting conditions 📈
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0
servers:
production:
url: test.mosquitto.org:{port}
protocol: mqtt
description: Test broker
variables:
port:
description: Secure connection (TLS) is available through port 8883.
default: '1883'
enum:
- '1883'
- '8883'
security:
- apiKey: []
- supportedOauthFlows:
- streetlights:on
- streetlights:off
- streetlights:dim
- openIdConnectWellKnown: []
defaultContentType: application/json
channels:
smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured:
description: The topic on which measured values may be produced and consumed.
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
subscribe:
operationId: measuredStreetlight
message:
$ref: '#/components/messages/turnOnOff'
traits:
- $ref: '#/components/operationTraits/kafka'
publish:
operationId: receiveLightMeasurement
summary: Inform about environmental lighting conditions of a particular streetlight.
message:
$ref: '#/components/messages/lightMeasured'
traits:
- $ref: '#/components/operationTraits/kafka'
smartylighting.streetlights.1.0.action.{streetlightId}.turn.on:
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
subscribe:
operationId: turnOn
message:
$ref: '#/components/messages/turnOnOff'
traits:
- $ref: '#/components/operationTraits/kafka'
smartylighting.streetlights.1.0.action.{streetlightId}.turn.off:
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
subscribe:
operationId: turnOff
message:
$ref: '#/components/messages/turnOnOff'
traits:
- $ref: '#/components/operationTraits/kafka'
smartylighting.streetlights.1.0.action.{streetlightId}.dim:
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
subscribe:
operationId: dimLight
message:
title: Dim light
summary: Command a particular streetlight to dim the lights.
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
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'
traits:
- $ref: '#/components/operationTraits/kafka'
components:
parameters:
streetlightId:
description: The ID of the streetlight.
schema:
type: string
dimId:
description: The ID of the dimmer.
schema:
type: string
abcId:
description: The ID of the abc.
schema:
type: number
messages:
lightMeasured:
name: lightMeasured
title: Light measured
summary: Inform about environmental lighting conditions of a particular streetlight.
contentType: application/json
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: '#/components/schemas/lightMeasuredPayload'
turnOnOff:
name: turnOnOff
title: Turn on/off
summary: Command a particular streetlight to turn the lights on or off.
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: '#/components/schemas/turnOnOffPayload'
dimLight:
name: dimLight
title: Dim light
summary: Command a particular streetlight to dim the lights.
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
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'
schemas:
lightMeasuredPayload:
type: object
properties:
lumens:
description: Light intensity measured in lumens.
type: integer
minimum: 0
sentAt:
$ref: '#/components/schemas/sentAt'
turnOnOffPayload:
type: object
properties:
command:
description: Whether to turn on or off the light.
type: string
enum:
- 'on'
- 'off'
sentAt:
$ref: '#/components/schemas/sentAt'
dimLightPayload:
type: object
properties:
percentage:
description: Percentage to which the light should be dimmed to.
type: integer
minimum: 0
maximum: 100
sentAt:
$ref: '#/components/schemas/sentAt'
sentAt:
description: Date and time when the message was sent.
type: string
format: date-time
messageTraits:
eventHeaders:
headers:
type: object
properties:
event-header:
type: integer
minimum: 0
maximum: 100
commonHeaders:
headers:
type: object
properties:
my-app-header:
type: integer
minimum: 0
maximum: 100
operationTraits:
ws:
bindings:
ws:
clientId: ws-id
kafka:
bindings:
kafka:
clientId: my-app-id
http:
bindings:
http:
clientId: http-id
securitySchemes:
supportedOauthFlows:
type: oauth2
description: Flows to support OAuth 2.0
flows:
implicit:
authorizationUrl: https://authserver.example/auth
scopes:
streetlights:on: Ability to switch lights on
streetlights:off: Ability to switch lights off
streetlights:dim: Ability to dim the lights
password:
tokenUrl: https://authserver.example/token
scopes:
streetlights:on: Ability to switch lights on
streetlights:off: Ability to switch lights off
streetlights:dim: Ability to dim the lights
clientCredentials:
tokenUrl: https://authserver.example/token
scopes:
streetlights:on: Ability to switch lights on
streetlights:off: Ability to switch lights off
streetlights:dim: Ability to dim the lights
authorizationCode:
authorizationUrl: https://authserver.example/auth
tokenUrl: https://authserver.example/token
refreshUrl: https://authserver.example/refresh
scopes:
streetlights:on: Ability to switch lights on
streetlights:off: Ability to switch lights off
streetlights:dim: Ability to dim the lights
openIdConnectWellKnown:
type: openIdConnect
openIdConnectUrl: https://authserver.example/.well-known
apiKey:
type: apiKey
in: user
description: Provide your API key as the user and leave the password empty.

4 changes: 4 additions & 0 deletions test/yaml-sort-skip-components/options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
verbose: true
sortComponentsFile: customSortComponents.yaml
output: output.yaml

Loading

0 comments on commit bf0d7e4

Please sign in to comment.