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

Cannot override model as a primitive type #573

Closed
e28eta opened this issue May 20, 2014 · 7 comments
Closed

Cannot override model as a primitive type #573

e28eta opened this issue May 20, 2014 · 7 comments

Comments

@e28eta
Copy link

e28eta commented May 20, 2014

I can't figure out how to override a class and specify that it should be a primitive type

For example, given:

class Foo {
  Date myDate
}

How do I make swagger think that Dates should be strings, such that swagger-ui (and other clients following the spec) thinks that this is a valid Foo object:

{ "myDate": "2014-01-01" }

I've tried this: https://github.com/wordnik/swagger-core/wiki/overriding-models
However, that results in clients expecting that Foo objects look like this:

{ "myDate": { "value": "2014-01-01" } }

I also want to attach a description (for example) to the date class that specify recognized formats.

So far I want this for things like dates (XMLGregorianCalendar), BigDecimal, and BigInteger, where our JSON serialization knows how to serialize/deserialize as strings in a particular format.

Thanks!

@webron
Copy link
Contributor

webron commented May 21, 2014

The model overriding is meant to be used to override they way models are
described, not to convert them to primitives (could be a nice idea, feel
free to open a specific issue about it).
If you want to 'replace' the type of it, you can use
https://github.com/wordnik/swagger-core/blob/master/modules/swagger-annotations/src/main/java/com/wordnik/swagger/annotations/ApiImplicitParam.java#L58to
describe that parameter instead.

On Wed, May 21, 2014 at 2:02 AM, Dan Jackson [email protected]:

I can't figure out how to override a class and specify that it should be a
primitive type

For example, given:

class Foo {
Date myDate}

How do I make swagger think that Dates should be strings, such that
swagger-ui (and other clients following the spec) thinks that this is a
valid Foo object:

{ "myDate": "2014-01-01" }

I've tried this:
https://github.com/wordnik/swagger-core/wiki/overriding-models
However, that results in clients expecting that Foo objects look like this:

{ "myDate": { "value": "2014-01-01" } }

I also want to attach a description (for example) to the date class that
specify recognized formats.

So far I want this for things like dates (XMLGregorianCalendar),
BigDecimal, and BigInteger, where our JSON serialization knows how to
serialize/deserialize as strings in a particular format.

Thanks!


Reply to this email directly or view it on GitHubhttps://github.com//issues/573
.

@e28eta
Copy link
Author

e28eta commented May 21, 2014

I don't think that'll work, I want to replace the type for all requests, parameters and responses, and I can't do it through annotations.

Dates are a great example. Our (third-party provided) schema specifies that the date fields have type XMLGregorianCalendar. We've told Jackson (the json serialization library we're using) that it should produce and consume strings with a certain format (yyyy-MM-dd...) for all XMLGregorianCalendar fields.

I need Swagger to reflect this fact.

And a very similar story for BigDecimal. Because it's a global override, there's no way I want to find and annotate each field with the target type, even if we could.

Can this be the specific issue to provide this feature? Is there some other way I can word it to be more clear?

Thanks!
Dan

@webron
Copy link
Contributor

webron commented May 21, 2014

We're actually working on a stronger integration between Jackson and
Swagger, so it may end up resulting with that. However, I'm not entirely
sure at the moment.
I think it would require additional manual work since what you're looking
to do is unwrap the complex models into primitive types and I'm not sure
that can be done (or should be done) automatically.

On Wed, May 21, 2014 at 8:03 PM, Dan Jackson [email protected]:

I don't think that'll work, I want to replace the type for all requests,
parameters and responses, and I can't do it through annotations.

Dates are a great example. Our (third-party provided) schema specifies
that the date fields have type XMLGregorianCalendar. We've told Jackson
(the json serialization library we're using) that it should produce and
consume strings with a certain format (yyyy-MM-dd...) for all
XMLGregorianCalendar fields.

I need Swagger to reflect this fact.

And a very similar story for BigDecimal. Because it's a global override,
there's no way I want to find and annotate each field with the target type,
even if we could.

Can this be the specific issue to provide this feature? Is there some
other way I can word it to be more clear?

Thanks!
Dan

On May 21, 2014, at 4:30 AM, webron [email protected] wrote:

The model overriding is meant to be used to override they way models are
described, not to convert them to primitives (could be a nice idea, feel
free to open a specific issue about it).
If you want to 'replace' the type of it, you can use

https://github.com/wordnik/swagger-core/blob/master/modules/swagger-annotations/src/main/java/com/wordnik/swagger/annotations/ApiImplicitParam.java#L58to
describe that parameter instead.

On Wed, May 21, 2014 at 2:02 AM, Dan Jackson [email protected]:

I can't figure out how to override a class and specify that it should
be a
primitive type

For example, given:

class Foo {
Date myDate}

How do I make swagger think that Dates should be strings, such that
swagger-ui (and other clients following the spec) thinks that this is
a
valid Foo object:

{ "myDate": "2014-01-01" }

I've tried this:
https://github.com/wordnik/swagger-core/wiki/overriding-models
However, that results in clients expecting that Foo objects look like
this:

{ "myDate": { "value": "2014-01-01" } }

I also want to attach a description (for example) to the date class
that
specify recognized formats.

So far I want this for things like dates (XMLGregorianCalendar),
BigDecimal, and BigInteger, where our JSON serialization knows how to
serialize/deserialize as strings in a particular format.

Thanks!


Reply to this email directly or view it on GitHub<
https://github.com/wordnik/swagger-core/issues/573>
.


Reply to this email directly or view it on GitHub.


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

@fehguy
Copy link
Contributor

fehguy commented May 21, 2014

I'm confused why this isn't working. Did you look here?

https://github.com/wordnik/swagger-core/wiki/overriding-models

@e28eta
Copy link
Author

e28eta commented May 21, 2014

@webron I can't figure out how someone would use Swagger with types like BigDecimal and not need this, unless they're solely going from Java to Java. My API client should not send me scale and precision (the internal representation of BigDecimal on Java) it should send me the value as a string (since any other JSON representation could lose precision). Date classes are another good example, I think.

@fehguy I thought my initial message explained why. Did I get something wrong, or explain my issue incorrectly?

Thanks again for the help.

@fehguy
Copy link
Contributor

fehguy commented May 21, 2014

@e28eta I'm saying, we should be able to support this easily. I believe @webron is trying, I pointed him at some undocumented logic that should do the trick

@fehguy
Copy link
Contributor

fehguy commented Jun 16, 2014

Hi, take a look at #588 for a solution to this issue.

@fehguy fehguy closed this as completed Jun 16, 2014
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

3 participants