Skip to content
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

Overriding Models data types not working #359

Closed
rartavia opened this issue Oct 23, 2013 · 12 comments
Closed

Overriding Models data types not working #359

rartavia opened this issue Oct 23, 2013 · 12 comments

Comments

@rartavia
Copy link

I have a very simple model with a java.util.Calendar property, I want to present this as a simple string with date as a format (Similar to what we get with java.util.Date).

I tried what we have in the documentation https://github.com/wordnik/swagger-core/wiki/overriding-models#in-java-with-swagger-core-version-13x

... But it didn't work

My converter looks like this

public class Converter
{
  public void registerConverter()
  {
    String jsonString = "{" +
            "  \"id\": \"Calendar\"," +
            "  \"properties\": {" +
            "    \"value\": {" +
            "      \"required\": true," +
            "      \"description\": \"Date in ISO-8601 format\"," +
            "      \"notes\": \"Add any notes you like here\"," +
            "      \"type\": \"string\"," +
            "      \"format\": \"date-time\"" +
            "    }" +
            "  }" +
            "}";
    OverrideConverter converter = new OverrideConverter();
    converter.add("java.util.Calendar", jsonString);
  }
}

I'm initializing the converter using Spring, I wonder if that's sufficient and if it is, why is not working.

@fehguy
Copy link
Contributor

fehguy commented Oct 25, 2013

You're missing one line:

converter.add("java.util.Calendar", jsonString);

ModelConverters.addConverter(converter, true);

This will stick the override converter in the front of the chain (the true param does that). You'll get the right results.

@fehguy
Copy link
Contributor

fehguy commented Nov 9, 2013

please reopen if you're still having an issue with this.

@sameerarora
Copy link

@fehguy I am using Swagger on Spring MVC , where do I need to add a custom converter to the Model Converters , I mean where in SwaggerConfig class??

@webron
Copy link
Contributor

webron commented Oct 14, 2014

@sameer11sep - I assume you're using swagger-springmvc. In that case, you should open an issue on their repository and ask there directly.

@sameerarora
Copy link

thanks @webron, I have opened an issue at swagger-springmvc , one small question though
which Swagger component sets and makes use of the Model Converters?

@webron
Copy link
Contributor

webron commented Oct 14, 2014

There are several places it can be used, and I'm not sure if swagger-springmvc uses it as well or has another way of registering converters.

@pradeepg-telsiz
Copy link

I am passing javax.json.JsonObject as a parameter. But each one has different schema. How can I handle this? In UI, I can just see DataType as javax.json.JsonObject but I want to show proper schema. Can any one please guide me?

@webron
Copy link
Contributor

webron commented Mar 6, 2015

@pradeepg-telsiz - I'd suggest opening a new issue or rather send an email to the mailing list describing your use case.

@pradeepg-telsiz
Copy link

@webron Created issue. Issue number is 896.

@mfarhans
Copy link

The post was helpful and pointed me to the right direction...

Although, a quick question relating to Convertors, if someone can comment. When I define my convertor for "ZonedDateTime" for the properties "lastLogin" and "createdOn" properties (to String) using exactly the same pattern (as shown above for java.util.Calendar), the Swagger-UI response-model json schema-representation shows up like below:
{
"id": "",
"firstName": "",
"lastName": "",
"lastLogin": {
"value": "date-time"
},
"createdOn": {
"value": "date-time"
}
}

The question I have is -- How can I avoid having the "value" sub-property in this json representation for the two ZonedDateTime fields. I am expecting the representation to be like below, is there something I am missing ?

{
"id": "",
"firstName": "",
"lastName": "",
"lastLogin": "",
"createdOn": ""
}

@nikhilingole
Copy link

@mfarhans How did you solve this. Could you post a sample.
I am facing a similar issue - https://groups.google.com/forum/#!topic/swagger-swaggersocket/Csa5lxcSg6w

@fehguy
Copy link
Contributor

fehguy commented Aug 11, 2015

Hi @nikhilingole please reopen if the response in the google group doesn't help you solve your issue.

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

No branches or pull requests

7 participants