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

SpringFox Generation #69

Closed
pluttrell opened this issue Sep 21, 2017 · 3 comments
Closed

SpringFox Generation #69

pluttrell opened this issue Sep 21, 2017 · 3 comments

Comments

@pluttrell
Copy link

pluttrell commented Sep 21, 2017

We've found this library to work great parsing and rendering MonetaryAmount instances as:

{
    "amount": 900,
    "currency": "USD"
}

However when SpringFox generates the Swagger docs on the same code, it describes the rendering as:

{
    "context": {
        "empty": true,
        "fixedScale": true,
        "maxScale": 0,
        "precision": 0,
        "providerName": "string"
    },
    "currency": {
        "context": {
            "empty": true,
            "providerName": "string"
        },
        "currencyCode": "string",
        "defaultFractionDigits": 0,
        "numericCode": 0
    }
}

Is there a way to solve this?

@whiskeysierra
Copy link
Collaborator

Does this still apply? https://stackoverflow.com/questions/41675459/springfox-swagger-generation-creates-odd-schema

I've never used springfox myself.

@whiskeysierra
Copy link
Collaborator

@pluttrell Have you managed to resolve this? I'll close this for now. I believe the stackoverflow answer gives some hints how to do this. Feel free to re-open, if needed.

@pluttrell
Copy link
Author

@whiskeysierra Many thanks for getting back to me.

That SO answer suggests a mechanism where the rendering of one time is replaced with another, which is helpful in controlling how it renders. In the example, it uses a Double.class or String.class, which if one used Double.class would render it in SpringFox simply as:

0

So to use that method, we'd need a type to use. In looking through the zalando/jackson-datatype-money codebase and it doesn't look like there's a specific class to use as it uses com.fasterxml.jackson.databind.JsonSerializer to render the instances.

If one create a class just for this purpose, such as the following:

class ZalandoJacksonDataTypeMoneyRenderedMonetaryAmount{
  private double amount;
  private String currency;
  private ZalandoJacksonDataTypeMoneyRenderedMonetaryAmount() {}
  public double getAmount() { return amount; }
  public void setAmount(double amount) { this.amount = amount; }
  public String getCurrency() { return currency;}
  public void setCurrency(String currency) { this.currency = currency; }
}

SpringFox then renders MonetaryAmounts as:

{
    "amount": 0,
    "currency": "string"
}

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

2 participants