Skip to content

Commit

Permalink
Merge branch 'master' into feature/integrate_visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Nov 28, 2022
2 parents 85a313f + bd36cfa commit 921c8e9
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 44 deletions.
58 changes: 30 additions & 28 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@asyncapi/studio",
"version": "0.14.3",
"version": "0.14.5",
"description": "One place that allows you to develop an AsyncAPI document, validate it, convert it to the latest version, preview the documentation and visualize the events flow.",
"license": "Apache-2.0",
"bugs": {
Expand Down Expand Up @@ -31,7 +31,7 @@
"@asyncapi/openapi-schema-parser": "^2.0.1",
"@asyncapi/parser": "^2.0.0-next-major.10",
"@asyncapi/react-component": "^1.0.0-next.44",
"@asyncapi/specs": "^4.0.0",
"@asyncapi/specs": "^4.0.1",
"@headlessui/react": "^1.7.4",
"@hookstate/core": "^4.0.0-rc21",
"@monaco-editor/react": "^4.4.6",
Expand Down Expand Up @@ -78,7 +78,7 @@
]
},
"devDependencies": {
"@asyncapi/dotnet-nats-template": "^0.10.0",
"@asyncapi/dotnet-nats-template": "^0.11.0",
"@asyncapi/go-watermill-template": "^0.2.11",
"@asyncapi/html-template": "^0.28.1",
"@asyncapi/java-spring-cloud-stream-template": "^0.13.4",
Expand All @@ -88,7 +88,7 @@
"@asyncapi/nodejs-template": "^0.13.1",
"@asyncapi/nodejs-ws-template": "^0.9.25",
"@asyncapi/python-paho-template": "^0.2.13",
"@asyncapi/ts-nats-template": "^0.10.0",
"@asyncapi/ts-nats-template": "^0.10.1",
"@craco/craco": "^7.0.0",
"@semantic-release-plus/docker": "^3.1.2",
"@semantic-release/commit-analyzer": "^9.0.2",
Expand Down
6 changes: 3 additions & 3 deletions src/components/Editor/EditorSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const EditorSidebar: React.FunctionComponent<EditorSidebarProps> = () =>
let documentFromText = '';
if (documentFrom === 'localStorage') {
documentFromText = 'From localStorage';
} else if (documentFrom === 'Base64') {
} else if (documentFrom === 'base64') {
documentFromText = 'From Base64';
} else {
const splittedText = documentFrom.split(' ');
documentFromText = `From ${splittedText[1]}`;
const documentSource = editorState.documentSource.get();
documentFromText = `From URL ${documentSource}`;
}

return (
Expand Down
4 changes: 3 additions & 1 deletion src/components/Editor/MonacoWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export const MonacoWrapper: React.FunctionComponent<MonacoWrapperProps> = ({

const onChange = debounce((v: string) => {
EditorService.updateState({ content: v });
autoSaving && EditorService.saveToLocalStorage(v, false);
if (autoSaving) {
autoSaving && EditorService.saveToLocalStorage(v, false);
}
SpecificationService.parseSpec(v);
}, savingDelay);

Expand Down
14 changes: 11 additions & 3 deletions src/services/editor.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ export class EditorService {
if (url) {
return fetch(url)
.then(res => res.text())
.then(text => {
state.editor.documentFrom.set(`URL: ${url}` as any);
.then(async text => {
state.editor.merge({
documentFrom: 'url',
documentSource: url,
});
this.updateState({ content: text, updateModel: true });
await SpecificationService.parseSpec(text, { source: url });
})
.catch(err => {
console.error(err);
Expand Down Expand Up @@ -125,7 +129,10 @@ export class EditorService {
static async importBase64(content: string) {
try {
const decoded = FormatService.decodeBase64(content);
state.editor.documentFrom.set('Base64');
state.editor.merge({
documentFrom: 'base64',
documentSource: undefined,
});
this.updateState({ content: String(decoded), updateModel: true });
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -178,6 +185,7 @@ export class EditorService {
localStorage.setItem('document', editorValue);
state.editor.merge({
documentFrom: 'localStorage',
documentSource: undefined,
modified: false,
});

Expand Down
20 changes: 16 additions & 4 deletions src/services/specification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MonacoService } from './monaco.service';
import state from '../state';

import type { ConvertVersion } from '@asyncapi/converter';
import type { OldAsyncAPIDocument as AsyncAPIDocument, Diagnostic } from '@asyncapi/parser/cjs';
import type { OldAsyncAPIDocument as AsyncAPIDocument, Diagnostic, ParseOptions } from '@asyncapi/parser/cjs';
import type { SpecVersions } from '../types';

const parser = new Parser({
Expand All @@ -34,12 +34,24 @@ export class SpecificationService {
return window.ParsedExtras || null;
}

static async parseSpec(rawSpec: string): Promise<AsyncAPIDocument | void> {
static async parseSpec(rawSpec: string, options: ParseOptions = {}): Promise<AsyncAPIDocument | void> {
const source = state.editor.documentSource.get();
if (source) {
options.source = source;
}

let diagnostics: Diagnostic[] = [];

try {
const { document, diagnostics: validationDiagnostics, extras } = await parser.parse(rawSpec);
diagnostics = validationDiagnostics;
const { document, diagnostics: validationDiagnostics, extras } = await parser.parse(rawSpec, options);

// map messages of invalid ref to file
diagnostics = validationDiagnostics.map(d => {
if (d.code === 'invalid-ref' && d.message.endsWith('readFile is not a function')) {
d.message = 'File references are not yet supported in Studio';
}
return d;
});

if (document) {
const oldDocument = convertToOldAPI(document);
Expand Down
3 changes: 2 additions & 1 deletion src/state/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ components:
clientId: my-app-id
`;

export type EditorStateDocumentFrom = 'localStorage' | `URL: ${string}` | 'Base64';
export type EditorStateDocumentFrom = 'localStorage' | 'url' | 'base64';

export interface EditorState {
height: string;
Expand All @@ -176,6 +176,7 @@ export interface EditorState {
monacoLoaded: boolean;
editorLoaded: boolean;
documentFrom: EditorStateDocumentFrom;
documentSource?: string;
decorations: Array<any>;
modified: boolean,
}
Expand Down

0 comments on commit 921c8e9

Please sign in to comment.