Skip to content

Commit

Permalink
feat: add test for new generator flag
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Sep 23, 2024
1 parent a6e23cf commit 01f3179
Show file tree
Hide file tree
Showing 11 changed files with 4,298 additions and 2 deletions.
3 changes: 3 additions & 0 deletions check/asyncapi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a markdown file for my application.
App name is: **Streetlights API V2**
Version running on mode
54 changes: 54 additions & 0 deletions check/asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
asyncapi: "2.1.0"
info:
title: Streetlights API V2
version: "1.0.0"
description: |
The Smartylighting Streetlights API allows you
to remotely manage the city lights.
license:
name: Apache 2.0
url: "https://www.apache.org/licenses/LICENSE-2.0"
servers:
mosquitto:
url: http://test.mosquitto.org
protocol: http
channels:
user/signedup:
subscribe:
message:
$ref: "#/components/messages/UserSignedUp"
light/measured:
publish:
summary: Inform about environmental lighting conditions for a particular streetlight.
operationId: onLightMeasured
message:
name: LightMeasured
payload:
type: object
properties:
id:
type: integer
minimum: 1
description: Id of the streetlight.
lumens:
type: integer
minimum: 0
description: Light intensity measured in lumens.
sentAt:
type: string
format: date-time
description: Date and time when the message was sent.

components:
messages:
UserSignedUp:
payload:
type: object
properties:
displayName:
type: string
description: Name of the user
email:
type: string
format: email
description: Email of the user
19 changes: 18 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@asyncapi/converter": "^1.5.1",
"@asyncapi/diff": "^0.4.1",
"@asyncapi/generator": "^1.17.25",
"generator-v2": "npm:@asyncapi/generator@^2.0.3",
"generator-v2": "npm:@asyncapi/generator@^2.4.1",
"@asyncapi/modelina": "^3.7.0",
"@asyncapi/modelina-cli": "^4.0.0-next.48",
"@asyncapi/openapi-schema-parser": "^3.0.24",
Expand Down Expand Up @@ -53,6 +53,7 @@
},
"devDependencies": {
"@asyncapi/minimaltemplate": "./test/fixtures/minimaltemplate",
"@asyncapi/newtemplate": "./test/fixtures/newtemplate",
"@babel/core": "^7.19.3",
"@oclif/test": "^2",
"@swc/core": "^1.3.2",
Expand Down
24 changes: 24 additions & 0 deletions test/fixtures/newtemplate/__transpiled/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/newtemplate/__transpiled/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions test/fixtures/newtemplate/hooks/generateAsyncapiFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fs = require('fs');
const path = require('path');

module.exports = {
'generate:before': generator => {
const asyncapi = generator.originalAsyncAPI;
let extension;
try {
JSON.parse(asyncapi);
extension = 'json'
} catch (error) {
extension = 'yaml'
}

fs.writeFileSync(
path.resolve(
generator.targetDir, `asyncapi.${extension}`
)
, asyncapi, { encoding: 'utf-8' }
);
}
}
Loading

0 comments on commit 01f3179

Please sign in to comment.