File tree Expand file tree Collapse file tree 4 files changed +25
-9
lines changed
editor-monaco-language-apidom
editor-preview-asyncapi/util Expand file tree Collapse file tree 4 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ const makeAfterLoad =
88 ( system ) => {
99 if ( isLanguageRegistered ( ) ) return ;
1010
11- lazyMonacoContribution ( { createData } ) ;
11+ lazyMonacoContribution ( { createData, system } ) ;
1212 system . editorActions . setLanguage ( apidomDefaults . getLanguageId ( ) ) ;
1313 } ;
1414
Original file line number Diff line number Diff line change 1+ import YAML from 'js-yaml' ;
2+
13import { getWorker } from '../apidom-mode.js' ;
24
3- const dereferenceActionDescriptor = {
5+ const createDereferenceActionDescriptor = ( { getSystem } ) => ( {
46 id : 'swagger.editor.apidomDereference' ,
57 label : 'Resolve document' ,
68 async run ( editor ) {
9+ const system = getSystem ( ) ;
10+ const isContentJSON = system . editorSelectors . selectIsContentFormatJSON ( ) ;
11+ const isContentYAML = system . editorSelectors . selectIsContentFormatYAML ( ) ;
12+
13+ if ( ! isContentJSON && ! isContentYAML ) return ; // nothing to do here
14+
715 const model = editor . getModel ( ) ;
816 const worker = await getWorker ( ) ( model . uri ) ;
917 const dereferenced = await worker . doDeref ( model . uri . toString ( ) , {
1018 baseURI : globalThis . document . baseURI || globalThis . location . href ,
19+ format : isContentJSON ? 0 : isContentYAML ? 1 : 'unknown' , // eslint-disable-line no-nested-ternary
1120 } ) ;
1221
13- editor . setValue ( dereferenced ) ;
22+ if ( isContentYAML ) {
23+ const nicelyFormattedYAML = YAML . dump ( YAML . load ( dereferenced ) ) ;
24+ editor . setValue ( nicelyFormattedYAML ) ;
25+ } else if ( isContentJSON ) {
26+ editor . setValue ( dereferenced ) ;
27+ }
1428 } ,
15- } ;
29+ } ) ;
1630
17- export default dereferenceActionDescriptor ;
31+ export default createDereferenceActionDescriptor ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { ModesRegistry } from 'monaco-editor/esm/vs/editor/common/languages/mode
44
55import * as apidom from './apidom.js' ;
66import { setupMode } from './apidom-mode.js' ;
7- import dereferenceActionDescriptor from './actions/dereference.js' ;
7+ import createDereferenceActionDescriptor from './actions/dereference.js' ;
88import jsonPointerPositionActionDescriptor from './actions/json-pointer-position.js' ;
99
1010export { getWorker } from './apidom-mode.js' ;
@@ -65,7 +65,7 @@ export const isLanguageRegistered = () => {
6565 return languages . includes ( apidom . languageId ) ;
6666} ;
6767
68- const lazyMonacoContribution = ( { createData } ) => {
68+ const lazyMonacoContribution = ( { createData, system } ) => {
6969 const disposables = [ ] ;
7070
7171 // register apidom language
@@ -98,9 +98,11 @@ const lazyMonacoContribution = ({ createData }) => {
9898 monaco . editor . onDidCreateEditor ( ( editor ) => {
9999 disposables . push (
100100 monaco . editor . onDidCreateModel ( ( ) => {
101+ const dereferenceActionDescriptor = createDereferenceActionDescriptor ( system ) ;
101102 if ( ! editor . getAction ( dereferenceActionDescriptor . id ) ) {
102103 disposables . push ( editor . addAction ( dereferenceActionDescriptor ) ) ;
103104 }
105+
104106 disposables . push ( editor . addAction ( jsonPointerPositionActionDescriptor ) ) ;
105107 } )
106108 ) ;
Original file line number Diff line number Diff line change 1- import yaml from 'js-yaml' ;
1+ import YAML from 'js-yaml' ;
22
33/* eslint-disable no-param-reassign */
44
55export async function parse ( { message, defaultSchemaFormat } ) {
66 try {
77 let { payload } = message ;
88 if ( typeof payload === 'object' ) {
9- payload = yaml . dump ( payload ) ;
9+ payload = YAML . dump ( payload ) ;
1010 }
1111
1212 message [ 'x-parser-original-schema-format' ] = message . schemaFormat || defaultSchemaFormat ;
You can’t perform that action at this time.
0 commit comments