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

@ApiModelProperty(dataType='xx') not handled within ModelPropertyParser #334

Closed
andyoll opened this issue Sep 28, 2013 · 14 comments
Closed
Labels
Milestone

Comments

@andyoll
Copy link

andyoll commented Sep 28, 2013

In version 1.2.5 it was possible to annotate a case class as:

case class User(@(ApiProperty @field)(notes="nullable", dataType="long", required=false) id: Option[Long] = None, userName: String)

The dataType attribute would be processed correctly, and Option[Long] would not be described in Swagger doco as 'Object'. This seemed like a reasonable work-around for describing Option[xx] dataTypes.

In 1.3 I've migrated to:

case class User(@(ApiModelProperty @field)(required = false, value = "Id of the user record", dataType = "Long") id: Option[Long] = None, userName: String)

But now dataType has no effect. The resulting JSON for field id:

id: {
    "$ref": "Object",
    "description": "Id of the user record"
}

Although I can see that ModelPropertyParser$.processAnnotations does extract dataType value and return it, this value is never used in ModelPropertyParser$.parsePropertyAnnotations.

@jayree05
Copy link

There seems to be similar problem with the "notes" field in the same annotation.

@fehguy
Copy link
Contributor

fehguy commented Oct 10, 2013

@andyoll the issue you are hitting is that Long is of type anyval and cannot be reflected upon. If you changed it to java.lang.Long, you would see it become an optional type long.

I will look at the datatype mapping, that should still work.

@rage-shadowman
Copy link

This also doesn't work in Java. The dataType parameter of @ApiModelProperty appears to have absolutely no effect at all in both versions 1.3.1 and 1.3.2.

I've tried annotating a property like such:

   @ApiModelProperty(required = true, position = 1, dataType = "java.lang.Long")
   public String getId ()
   {
      return m_id;
   }

...but the model still defines "id" as type "string"

@jorgenbraseth
Copy link
Contributor

This is still an issue with 1.3.2, as stated above.
Its a big concern with my project, as it breaks the documentation if you use java.util.Collection as a return value.

@fehguy
Copy link
Contributor

fehguy commented Mar 19, 2014

Hi, I think the right thing to do is map java.util.Collection to type List in an override converter so it can be treated as such. There should be examples on the wiki to do so.

@jorgenbraseth
Copy link
Contributor

thanks, I will try that, but is there a reason why TypeUtil.scala doesn't
handle Collection? It seems to be working after I modified that class.
On 19 Mar 2014 02:47, "Tony Tam" [email protected] wrote:

Hi, I think the right thing to do is map java.util.Collection to type List
in an override converter so it can be treated as such. There should be
examples on the wiki to do so.


Reply to this email directly or view it on GitHubhttps://github.com//issues/334#issuecomment-38009876
.

@fehguy
Copy link
Contributor

fehguy commented Mar 19, 2014

No, as i mentioned it's simply not implemented. Collections should be converted into a List type. Happy to merge a PR on this.

@jorgenbraseth
Copy link
Contributor

I will try to make a PR for the patch I made, just need to verify it som more...

In the mean time:
How would I go about using the OverrideConverter to do this?
I tried doing

OverrideConverter converter = new OverrideConverter();
converter.add("java.util.Collection", "java.util.List");

But that doesn't work as the second argument needs to be JSON.

@jorgenbraseth
Copy link
Contributor

Added a pull request for this: #506

@damienbiggs
Copy link

I just ran into what rage-shadowman described above in java as well.

I can't set dataType="string" for uuid field types.
This leads to invalid model schema data.
Are there any updates on this issue?
Thanks

@Lorkster
Copy link

Lorkster commented May 7, 2014

Same thing here. dataType="x" doesn't seem to have any effect at all in Java. Any updates?

@fehguy
Copy link
Contributor

fehguy commented May 7, 2014

Hi @Lorkster this enhancement is in progress but not complete. Will be in 1.3.6-SNAPSHOT shortly.

@fehguy fehguy modified the milestone: v1.5.0 Sep 19, 2014
@jorgenbraseth
Copy link
Contributor

This bug is still present in 1.3.10 it seems, event though the change request was merged. Has it been removed again?

@fehguy fehguy modified the milestones: v1.3.12, v1.5.0 Dec 20, 2014
@fehguy fehguy added the Bug label Dec 20, 2014
@fehguy fehguy closed this as completed Dec 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants