-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Open
Description
System
- OS: Windows 10 Pro 21H1 (build 19043.1466)
- Browser: Chrome (108.0.5359.125)
- Swagger-Editor version:
^5.0.0-alpha.44
My situation
I'm trying to build an MVP project based on Vue 3. I have SwaggerEditor@next 5.0.0alpha44
sources and I'm running them locally with npm run start
on localhost:3000
.
I then use the iframe to get the SwaggerEditor@next instance. In an iframe, I send the url I need using postMessage(). I know that SwaggerEditor@next gets my url and it changes depending on the context. But the value of monaco-editor does not change, and therefore the api I need is not generated.
Code
Page A Vue 3
<template>
<iframe
src="http://localhost:3000/"
width="100%"
frameborder="0"
ref="targetIframe"
@load="postMessage"
/>
</template>
<script setup lang="ts">
const postMessage = () => {
const iframe = window.document.querySelector("iframe");
if (iframe) {
iframe.contentWindow!.postMessage(
{
url: "https://petstore.swagger.io/v2/swagger.json",
},
"*"
);
}
};
</script>
<style scoped></style>
Page B Vue 3
<template>
<iframe
src="http://localhost:3000/"
width="100%"
frameborder="0"
ref="targetIframe"
@load="postMessage"
/>
</template>
<script setup lang="ts">
const postMessage = () => {
const iframe = window.document.querySelector("iframe");
if (iframe) {
iframe.contentWindow!.postMessage(
{
url: "https://raw.githubusercontent.com/asyncapi/spec/v2.5.0/examples/streetlights-kafka.yml",
},
"*"
);
}
};
</script>
<style scoped></style>
index.js SwaggerEditor@next
import React from 'react';
import ReactDOM from 'react-dom';
import 'swagger-ui-react/swagger-ui.css';
import SwaggerEditor from './App.jsx';
let url = '';
window.addEventListener('message', (e) => {
if (e.origin === 'http://127.0.0.1:5173') {
console.log(e.data.url);
url = e.data.url;
ReactDOM.render(<SwaggerEditor url={url} />, document.getElementById('swagger-editor'));
}
});
Screenshots
Page A
Page B
How can we help?
So, I send different urls, but the code in the editor does not change, and therefore the new api is not generated. What am I doing wrong?