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

Import Statement for BigDecimal/BigInteger not generated for responses #275

Closed
peyerroger opened this issue Sep 9, 2018 · 4 comments
Closed
Labels
bug v2 Feature will be implemented in v2.0 only (master branch)

Comments

@peyerroger
Copy link

peyerroger commented Sep 9, 2018

Import Statement for BigDecimal not generated if return type number and useBigDecimal=true

Example:
`#%RAML 1.0
title: Number as bigdecimal
version: 1.0

/lucky-number:
get:
description: Returns the winning number.
responses:
200:
body:
application/json:
type: number`

Actual:
`-----------------------------------com.gen.test.LuckyNumberClient.java-----------------------------------

package com.gen.test;

import org.springframework.http.ResponseEntity;

/**

  • No description
  • (Generated with springmvc-raml-parser v.2.0.4)

*/
public interface LuckyNumberClient {

/**
 * Returns the winning number.
 * 
 */
public ResponseEntity<Double> getDouble();

}
-----------------------------------com.gen.test.LuckyNumberClientImpl.java-----------------------------------

package com.gen.test;

import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

/**

  • No description
  • (Generated with springmvc-raml-parser v.2.0.4)

*/
@component
public class LuckyNumberClientImpl
implements LuckyNumberClient
{

@Value("${client.url}")
private String baseUrl;
@Autowired
private RestTemplate restTemplate;

/**
 * Returns the winning number.
 * 
 */
public ResponseEntity<Double> getDouble() {
    HttpHeaders httpHeaders = new HttpHeaders();
    //  Add Accepts Headers and Body Content-Type
    ArrayList<MediaType> acceptsList = new ArrayList<MediaType>();
    acceptsList.add(MediaType.valueOf("application/json"));
    httpHeaders.setAccept(acceptsList);
    String url = baseUrl.concat("/lucky-number");
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
    UriComponents uriComponents = builder.build();
    HttpEntity httpEntity = new HttpEntity(httpHeaders);
    return this.restTemplate.exchange(uriComponents.encode().toUri(), HttpMethod.GET, httpEntity, Double.class);
}

}
`

Expected:
-----------------------------------com.gen.test.LuckyNumberClient.java-----------------------------------

package com.gen.test;

import java.math.BigDecimal;
import org.springframework.http.ResponseEntity;

/**

  • No description
  • (Generated with springmvc-raml-parser v.2.0.4)

*/
public interface LuckyNumberClient {

/**
 * Returns the winning number.
 *
 */
public ResponseEntity<BigDecimal> getBigDecimal();

}
-----------------------------------com.gen.test.LuckyNumberClientImpl.java-----------------------------------

package com.gen.test;

import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

/**

  • No description
  • (Generated with springmvc-raml-parser v.2.0.4)

*/
@component
public class LuckyNumberClientImpl
implements LuckyNumberClient
{

@Value("${client.url}")
private String baseUrl;
@Autowired
private RestTemplate restTemplate;

/**
 * Returns the winning number.
 *
 */
public ResponseEntity<java.math.BigDecimal> getBigDecimal() {
    HttpHeaders httpHeaders = new HttpHeaders();
    //  Add Accepts Headers and Body Content-Type
    ArrayList<MediaType> acceptsList = new ArrayList<MediaType>();
    acceptsList.add(MediaType.valueOf("application/json"));
    httpHeaders.setAccept(acceptsList);
    String url = baseUrl.concat("/lucky-number");
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
    UriComponents uriComponents = builder.build();
    HttpEntity httpEntity = new HttpEntity(httpHeaders);
    return this.restTemplate.exchange(uriComponents.encode().toUri(), HttpMethod.GET, httpEntity, BigDecimal.class);
}

}

@stojsavljevic stojsavljevic added bug v2 Feature will be implemented in v2.0 only (master branch) v0.X Related to v0x branch labels Sep 11, 2018
@stojsavljevic
Copy link
Contributor

Hi,

Thanks for reporting the bug.
I believe I fixed the import.

Only thing that is unclear to me is Double object instead of BigDecimal in your actual results.
I guess it's just misspelled.

In case that fix doesn't work as you expect please reopen the issue or create new one.

@peyerroger
Copy link
Author

peyerroger commented Sep 11, 2018

Hi Aleksander

Sorry, the double is a copy/paste error.

I already created a pull request for this issue. I used a different approach, which is most probably not as good as yours. BUT the tests can be reuses ;)

Would you mind to add the tests from my pull request to your commit?

Thanks,
Roger

stojsavljevic pushed a commit that referenced this issue Sep 12, 2018
This reverts commit 0d78b2f
Test files remains
stojsavljevic pushed a commit that referenced this issue Sep 12, 2018
Import Statement for BigDecimal not generated
Spring4ControllerStubRule omits ResponseEntity for POJOs (data types)
@stojsavljevic
Copy link
Contributor

Hi @peyerroger

Thank you very much for your #280 PR.
My original idea was to create generic solution.
But after looking at your solution I realized it's actually better than mine.
Your change is less intrusive - I was changing core object ApiBodyMetadata and this something I want to avoid. Also, my change there (name vs fullName) can be confusing.

Further, your change helped to discover and solve another bug - #281

I added 24 test cases to make sure we don't regress on this.
They include your test cases too.

I will reject your PR since I resolved the bug using your idea but I added something more generic (RuleHelper for example).
I hope you don't get mad at me for rejecting the PR :)

@stojsavljevic stojsavljevic removed the v0.X Related to v0x branch label Sep 12, 2018
@peyerroger
Copy link
Author

Hi Aleksander

Thanks for solving this issue so quickly.

Not at all! The important thing is solving the issue. Doesn't matter which pull request gets integrated ;)

Cheers,
Roger

@stojsavljevic stojsavljevic changed the title Import Statement for BigDecimal not generated Import Statement for BigDecimal/BigInteger not generated for responses Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug v2 Feature will be implemented in v2.0 only (master branch)
Projects
None yet
Development

No branches or pull requests

2 participants