Skip to content

Provide XML examples as well as JSON #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jugglingcats opened this issue Sep 19, 2014 · 5 comments
Closed

Provide XML examples as well as JSON #583

jugglingcats opened this issue Sep 19, 2014 · 5 comments
Milestone

Comments

@jugglingcats
Copy link

Apologies if this is a duplicate, I couldn't find it in open issues and very little in other forums.

It would be very nice if Swagger UI could generate XML examples (input and response) for services that produce or consume XML.

It might be possible to implement (relatively) easily by adding conversion methods to ApiListingResource. It could use Jackson to convert from the JSON example to POJO then use JAXB to produce the XML representation, to return to Swagger UI. I guess this would mean changing swagger-jersey-jaxrs, but cannot see how it could be done purely client side. Unfortunately I don't do Scala well, so can't have a go at it...!

Thanks.

@webron
Copy link
Contributor

webron commented Sep 19, 2014

I believe that when using Swagger 1.2 and prior to it, implementing it would be a bit of an issue since the json-to-xml translation isn't always clear. Just to give you an idea, assume an array of strings.

In JSON, it would look like this:

{
  [ "hello", "world" ]
}

In XML it could look like this:

<object>
  <items>
    <item>"hello"</item>
    <item>"world"</item>
  <items>
</object>

Or this:

<object>
  <item>"hello"</item>
  <item>"world"</item>
</object>

Or even this:

<object>
  <items>
    <item value="hello"/>
    <item value="world"/>
  <items>
</object>

The right way to describe it is based on how the server expects to receive it, but we cannot imply the proper structure with the specification itself, so producing such examples automatically simply won't work.

However, with the new Swagger Specification 2.0, we've introduced a better way to define and control such conversions, and for that we may be able to implement the support you request in the future.

@jugglingcats
Copy link
Author

Thanks for the reply. I realise now that you need Swagger UI to work purely off the spec info. I am using it in conjunction with the Jersey integation server-side to dynamically generate the spec. Of course the JAXB annotations indicate exactly how the XML should be formed, and so I thought it might be possible for Swagger UI to invoke this feature dynamically (purely for examples)... but I guess it is not the right approach, especially as better support is in the 2.0 spec. I guess it will take a while for the tools and Swagger UI to catch up though.

@webron
Copy link
Contributor

webron commented Sep 22, 2014

You can use both swagger-core 1.5.0-SNAPSHOT and the swagger-ui's master version for Swagger 2.0 support. Those are still under development so there may be bugs, but if you feel adventurous and want to help us test it out, you're more than welcome.

@fehguy fehguy added this to the v2.1.0 milestone Jan 28, 2015
@webron webron modified the milestones: v2.1, v2.1.1 Jun 8, 2015
@webron webron removed the P3 label Jul 20, 2015
@webron webron modified the milestones: v2.1.2, v2.1.1 Jul 21, 2015
@webron webron modified the milestones: v2.1.2, v2.1.3 Jul 31, 2015
@webron webron modified the milestones: v2.1.3, v2.1.4 Sep 2, 2015
@fehguy fehguy modified the milestones: future, v2.1.4 Dec 7, 2015
@fehguy
Copy link
Contributor

fehguy commented Dec 7, 2015

depends on #1248

@fehguy
Copy link
Contributor

fehguy commented Dec 7, 2015

Please track meta issue #1248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants