Closed peyerroger closed 5 years ago
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.
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
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 :)
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
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;
/**
*/ public interface LuckyNumberClient {
/**
*/ public ResponseEntity 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;
/**
*/ @Component public class LuckyNumberClientImpl implements LuckyNumberClient {
@Value("${client.url}") private String baseUrl; @Autowired private RestTemplate restTemplate;
/**
*/ public ResponseEntity getDouble() {
HttpHeaders httpHeaders = new HttpHeaders();
// Add Accepts Headers and Body Content-Type
ArrayList acceptsList = new ArrayList();
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;
/**
*/ public interface LuckyNumberClient {
/**
*/ public ResponseEntity 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;
/**
*/ @Component public class LuckyNumberClientImpl implements LuckyNumberClient {
@Value("${client.url}") private String baseUrl; @Autowired private RestTemplate restTemplate;
/**
*/ public ResponseEntity getBigDecimal() {
HttpHeaders httpHeaders = new HttpHeaders();
// Add Accepts Headers and Body Content-Type
ArrayList acceptsList = new ArrayList();
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);
}
}