Skip to content

Commit

Permalink
improve editing experience w/ content assistance asyncapi#132 asyncap…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Oct 14, 2022
1 parent bbfdd84 commit 3699b0f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 19 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ You can open AsyncAPI Preview from the editor title/context menu.

Automatic hot-reloading on editor save, but currently, it doesn't reload when saving referenced external files.

## Content Assistance

### Available snippets:

Open an empty or otherwise yaml file and start typing one of the following prefixes:

- `add asyncapi skeleton`: Adds an asyncapi skeleton for jump starting your API editing.
- `add asyncapi subscribe to async request`: Inserts a new subscribe operation, for listening to incoming async requests/commands.
- `add asyncapi publish event operation`: Inserts a new publish operation, for producing domain events.
- `add asyncapi message`: Inserts a new message, you can choose it to be either a **Request** or an **Event**.

Once snippets are inserted use the `<TAB>` key to travel between snippet placeholders.

## Paste as Schema

You can also autogenerate an Schema object from a JSON example.

Right-click inside `#/components/schemas` section and choose `AsyncAPI: Paste as Schema` from the context menu.

![VSCode AsyncapiPreview - Content Assistance](docs/VSCode%20AsyncAPI%20Content%20Assistance-X4.gif)

### Credits

AsyncAPI Viewer utilizes the following open source projects:
Expand Down
Binary file added docs/VSCode AsyncAPI Content Assistance-X4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"@semantic-release/github": "7.2.3",
"@semantic-release/release-notes-generator": "^9.0.1",
"@types/glob": "^7.2.0",
"@types/js-yaml": "^4.0.5",
"@types/mocha": "^9.1.1",
"@types/node": "14.x",
"@types/vscode": "^1.66.0",
Expand Down
22 changes: 8 additions & 14 deletions snippets/snippets.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Add AsyncAPI Skeleton": {
"prefix": "asyncapi",
"prefix": "add asyncapi skeleton",
"body": [
"asyncapi: '2.4.0'",
"info:",
Expand All @@ -22,7 +22,7 @@
"",
"channels:",
" this.is.one.channel.please.rename:",
" description: The topic on which messages may be produced and consumed.",
" description: A sample topic on which messages may be produced and consumed.",
"${4:# type 'add publish' or 'add subscribe' to get snippets autocomplete}",
"",
"",
Expand All @@ -32,22 +32,16 @@
" description: add one message and remove this line",
" # type here 'add message' to get snippets autocomplete",
"",
"",
" schemas:",
" OneEntity:",
" type: object",
"",
" messageTraits:",
" CommonHeaders:",
" headers:",
" type: object",
" properties:",
" metadata-session:",
" type: string",
""
]
},
"Add Subscribe to Async Request": {
"prefix": "add subscribe to async request",
"prefix": "add asyncapi subscribe to async request",
"body": [
" subscribe:",
" summary: ${1:Entity} Async Requests",
Expand All @@ -60,7 +54,7 @@
]
},
"Add Publish Event Operation": {
"prefix": "add publish event operation",
"prefix": "add asyncapi publish event operation",
"body": [
" publish:",
" summary: ${1:Entity} Domain Events",
Expand All @@ -73,15 +67,15 @@
]
},
"Add Message": {
"prefix": "add message",
"prefix": "add asyncapi message",
"body": [
" ${1:Entity}${2:Type|Request,Event|}Message:",
" ${1:Entity}${2|Request,Event|}Message:",
" name: ${1}${2}Message",
" title: Async ${2} for a ${1}",
" summary: Async ${2} for a ${1}",
" schemaFormat: application/vnd.aai.asyncapi;version=2.4.0",
" payload:",
" \\$ref: '#/components/schemas/${1}${2}'",
" \\$ref: '#/components/schemas/${1}'",
""
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/PreviewWebPanel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import * as path from 'path';

export function previewAsyncAPI(context) {
export function previewAsyncAPI(context: vscode.ExtensionContext) {
return async (uri: vscode.Uri) => {
uri = uri || (await promptForAsyncapiFile()) as vscode.Uri;
if (uri) {
Expand Down
5 changes: 2 additions & 3 deletions src/SmartPasteCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import * as yml from 'js-yaml';
import { createSchema } from './lib/genson-js/schema-builder';
import { createSchema } from 'genson-js';

export async function asyncapiSmartPaste() {
let editor = vscode.window.activeTextEditor;
Expand All @@ -13,7 +13,6 @@ export async function asyncapiSmartPaste() {
let currentLineText = editor.document.lineAt(start.line).text;
let clipboad = await vscode.env.clipboard.readText();

console.log("Smart Pasting", clipboad);
const json = parse(clipboad);
if(typeof json === 'object') {
const schema = { PastedSchema: createSchema(json) };
Expand Down Expand Up @@ -50,7 +49,7 @@ function parse(text: string) {
}
}

function stringify(schema, languageId: string, indentYml: number) {
function stringify(schema: object, languageId: string, indentYml: number) {
if(languageId === 'json') {
return JSON.stringify(schema, null, 2);
} else {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"sourceMap": true,
"rootDir": "src",
"strict": false /* enable all strict type-checking options */
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
Expand Down

0 comments on commit 3699b0f

Please sign in to comment.