Skip to content

SwaggerEditor@next: When I change the url nothing changes #3838

@vitjaz

Description

@vitjaz

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

image

Page B

image

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions