-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com> Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
- Loading branch information
1 parent
d15f1e1
commit 63b9047
Showing
21 changed files
with
4,448 additions
and
2,461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules | |
.idea | ||
coverage | ||
lib | ||
*.DS_Store | ||
*.DS_Store | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { Optimizer } = require('../lib/Optimizer'); | ||
|
||
const yaml = ` | ||
asyncapi: 2.0.0 | ||
info: | ||
title: Streetlights API | ||
version: '1.0.0' | ||
channels: | ||
smartylighting/event/{streetlightId}/lighting/measured: | ||
parameters: | ||
#this parameter is duplicated. it can be moved to components and ref-ed from here. | ||
streetlightId: | ||
schema: | ||
type: string | ||
subscribe: | ||
operationId: receiveLightMeasurement | ||
traits: | ||
- bindings: | ||
kafka: | ||
clientId: my-app-id | ||
message: | ||
name: lightMeasured | ||
title: Light measured | ||
contentType: application/json | ||
traits: | ||
- headers: | ||
type: object | ||
properties: | ||
my-app-header: | ||
type: integer | ||
minimum: 0 | ||
maximum: 100 | ||
payload: | ||
type: object | ||
properties: | ||
lumens: | ||
type: integer | ||
minimum: 0 | ||
#full form is used, we can ref it to: #/components/schemas/sentAt | ||
sentAt: | ||
type: string | ||
format: date-time | ||
smartylighting/action/{streetlightId}/turn/on: | ||
parameters: | ||
streetlightId: | ||
schema: | ||
type: string | ||
publish: | ||
operationId: turnOn | ||
traits: | ||
- bindings: | ||
kafka: | ||
clientId: my-app-id | ||
message: | ||
name: turnOnOff | ||
title: Turn on/off | ||
traits: | ||
- headers: | ||
type: object | ||
properties: | ||
my-app-header: | ||
type: integer | ||
minimum: 0 | ||
maximum: 100 | ||
payload: | ||
type: object | ||
properties: | ||
sentAt: | ||
$ref: "#/components/schemas/sentAt" | ||
components: | ||
messages: | ||
#libarary should be able to find and delete this message, because it is not used anywhere. | ||
unusedMessage: | ||
name: unusedMessage | ||
title: This message is not used in any channel. | ||
schemas: | ||
#this schema is ref-ed in one channel and used full form in another. library should be able to identify and ref the second channel as well. | ||
sentAt: | ||
type: string | ||
format: date-time`; | ||
const optimizer = new Optimizer(yaml); | ||
optimizer.getReport().then(report => { | ||
console.log(report); | ||
const optimizedDocument = optimizer.getOptimizedDocument({ rules: { | ||
reuseComponents: true, | ||
removeComponents: true, | ||
moveToComponents: true | ||
} }); | ||
console.log(optimizedDocument); | ||
}); |
Oops, something went wrong.