Swagger-editor: How to set the YAML value of the editor

Created on 24 Mar 2017  路  11Comments  路  Source: swagger-api/swagger-editor

Hi,

I currently have the editor object[1] with me and also a Swagger YAML value as a string with me. How set the swagger YAML value to the editor ?

Where can I find the API documentation of the SwaggerEditorBundle object ?

[1] - https://github.com/swagger-api/swagger-editor/blob/master/index.html#L50

Regards,
Hemika

Most helpful comment

Just looked over this again- my apologies, the correct way to set the value is self._swaggerEditor.specActions.updateSpec('new string for the editor').

Other than that, you should be good to go. Thanks for using Swagger!

All 11 comments

Ping!

You want to set the default YAML loaded with the editor (something different than the pet store)?

@webron Yes. And also need a way to get the YAML content from the editor ? Need a way to set the Swagger content without using a url.

Is there a way to access the ace editor events ? Need an onChange like event when a YAML content is changed with location(line number).

Can we access the ace editor object as well ?

Can you explain your use case? I don't understand what you're trying to do.

I have embedded the swagger editor to my web application.
I have a swagger YAML content as a variable which I need to set as the content of the swagger editor. Similarly, when the editor's YAML content is changed, i'll like to get the new YAML content.

I also have a need to event which is triggered when the Swagger editor content is changed.

I have created the swagger editor as follows :
self._swaggerEditor = SwaggerEditorBundle({ dom_id: '#' + 'z-' + self._options.swaggerEditorId });

I'd like to use the self._swaggerEditor object to set and get the Swagger YAML to the editor. Is this possible ?

@hemikak, you can get the editor's value dynamically by calling self._swaggerEditor.specSelectors.specStr(), and set the value by calling self._swaggerEditor.updateSpec('new string for the editor').

Cheers!

Thanks!

Just looked over this again- my apologies, the correct way to set the value is self._swaggerEditor.specActions.updateSpec('new string for the editor').

Other than that, you should be good to go. Thanks for using Swagger!

Thanks Shockey it worked for me.

Also: setting url:

    const editor = SwaggerEditorBundle({
      url: "/swagger.yaml",                // To Remove PetStore and add my Own API
      dom_id: '#swagger-editor',
      layout: 'StandaloneLayout',
      presets: [
        SwaggerEditorStandalonePreset
      ]
    })
Was this page helpful?
0 / 5 - 0 ratings