swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Show schema objects as XML if content type is XML

Open chrisdudley opened this issue 12 years ago • 24 comments

Using latest master swaggerui code with swagger 2. If the content type is only XML then it looks odd for schema objects to be shown as JSON in swaggerUI. I haven't yet experimented with the Example object, will that help show the examples as XML instead of JSON? Its hard to tell when there aren't any examples in the swagger 2 spec yet. It would be good if the model schema representation changed as the content type changed, that way users could more easily cut and paste into the body field to test the api.

chrisdudley avatar Nov 24 '14 20:11 chrisdudley

The UI displays two separate things - The Model and the Model Schema.

Disregarding the naming, the Model should remain the same and the Model Schema could change based on the mime type.

The tricky part would be to change it dynamically when more than one content-type is allowed.

Since the example is a free-form object, it can be anything, and we'll probably just paste it as is. It would still need to be a valid JSON object as the whole spec is in JSON. You could, however, add additional processing and extract the any form of example and manipulate it as needed in the UI.

webron avatar Nov 24 '14 20:11 webron

Some JS hanging off the content type drop down that changed the model schema format as the content type changed? With swagger 2 it should be able to know what the XML is supposed to look like, I know that was an issue with 1.2. The model schema there is very handy if using JSON as you can cut and paste from it into the body field, edit as necessary and then test the api. The same capability isn't there for XML. I know JSON is by far the more common but it would be nice to have the same capabilities regardless of format.

chrisdudley avatar Nov 25 '14 08:11 chrisdudley

+1 for XML support

jugglingcats avatar Nov 30 '14 07:11 jugglingcats

Fwiw I hacked together a non-elegant solution for an API I'm trying to understand at the moment (I'm documenting using Swagger as I go because the official aren't entirely accurate): http://trademonster.glenngillen.com

Like I said it's not terribly elegant, but solves my current issue (the API is always in XML). Code to make it happen is entirely in JS on the in question in case someone wanted to use it as a stating point.

glenngillen avatar Dec 07 '14 04:12 glenngillen

Are you able to share your changes or outline the approach?

jugglingcats avatar Dec 07 '14 11:12 jugglingcats

I'm hoping I can add this back upstream, but I'm a bit time constrained atm so it'll likely be a few weeks away. In the interim here's what I did:

  • Grabbed the JXON library from Mozilla which handles converting between JSON and XML objects.
  • Updated onComplete callback to iterate over all JSON definitions and change them to XML

As I mentioned this isn't an ideal implementation by any stretch. It needs to be updated to switch based on the Response and Parameter types rather than hard-coded assuming it's always XML instead of always JSON.

glenngillen avatar Dec 08 '14 02:12 glenngillen

Would like to add XML support for default models in 2.1.0-M2

fehguy avatar Dec 29 '14 18:12 fehguy

That would be great, any idea when 2.1.0-M2 will be? I'm happy to give it a test if that would help?

chrisdudley avatar Feb 10 '15 09:02 chrisdudley

Once the API from client is ready to get the raw schema we can render the schema in both JSON and XML formats.

https://github.com/swagger-api/swagger-js/issues/311 is opened to provide that API

mohsen1 avatar Mar 23 '15 20:03 mohsen1

Can you tell in which period the xml support will be available?

magictucura avatar Mar 27 '15 08:03 magictucura

Hi, it was targeted to the latest release (2.1.0-M2) but this feature didn't make it. Will be by 2.1 proper.

fehguy avatar Mar 27 '15 19:03 fehguy

When do you think that 2.1 proper will be ready, the XML feature would be very useful.

foufee avatar Apr 15 '15 04:04 foufee

@foufee - we aim for 2-3 weeks but can't guarantee.

webron avatar Apr 15 '15 07:04 webron

+1 for XML support

acazsouza avatar Jun 27 '15 20:06 acazsouza

Hi. When this feature will be done? I have a Rest API that works only with XML, it would be very useful for me. thanks.

andrecastro avatar Oct 07 '15 11:10 andrecastro

:+1:

firefoxNX avatar Oct 08 '15 18:10 firefoxNX

:+1:

litti avatar Oct 17 '15 13:10 litti

:+1:

m-jedynak avatar Nov 04 '15 08:11 m-jedynak

:+1:

chreble avatar Nov 09 '15 16:11 chreble

:+1:

jnupponen avatar Nov 23 '15 14:11 jnupponen