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

Missing "content-type" header during POST request and missing properties in swagger-ui screen #3353

Closed
gwcakep opened this issue Jun 29, 2020 · 5 comments
Labels
Milestone

Comments

@gwcakep
Copy link

gwcakep commented Jun 29, 2020

io.springfox springfox-boot-starter 3.0.0-SNAPSHOT

for below method

image

swagger-ui is not displaying the properties in the bean instead only displaying "body" param only and also missing "x-www-form-urlencoded" content-type when sending the request

image

would appreciate if somebody could provide some pointers. Thanks

@dilipkrish
Copy link
Member

It may be a bug.I’ll investigate

@dilipkrish
Copy link
Member

@gwcakep would've been easier if you'd based the code rather than an screenshot of the code

@dilipkrish
Copy link
Member

As far as I know @JSONVIEW and model attributes dont go together. Once is a request body and the other is usually a url encoded form. Would you mind sharing what WithdrawQueryRequestView looks like?

@gwcakep
Copy link
Author

gwcakep commented Jun 30, 2020

Hi Dilip,

Thanks for the followup. Below is the content of WithdrawQueryRequestView :

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({ "agentCode", "orderNo", "timestamp"})
public class WithdrawQueryRequestView extends BaseView {

	@JsonView({Request.class, QueryParam.class, QueryParamDes.class, KeyHint.class})
	@JsonProperty("AgentCode")
	@JsonAlias("MerCode")
	@NotBlank(groups={IRequest.class}, message="AgentCode {javax.validation.constraints.NotBlank.message}")
	private String agentCode;
	
	@JsonView({Request.class, QueryParam.class})
	@JsonProperty("Timestamp")
	@NotNull(groups={IRequest.class}, message="Timestamp {javax.validation.constraints.NotNull.message}")
	@Digits(groups={IRequest.class}, fraction=0, integer=13, message="Timestamp {javax.validation.constraints.Digits.message}")
	@Positive(groups={IRequest.class}, message="Timestamp {javax.validation.constraints.Positive.message}")
	private BigDecimal timestamp;
	
	@JsonView({Request.class, QueryParam.class, QueryParamDes.class})
	@JsonProperty("OrderNo")
	@NotBlank(groups={IRequest.class}, message="OrderNo {javax.validation.constraints.NotBlank.message}")
	@Size(min=13, max=30, groups={IRequest.class}, message="{javax.validation.constraints.Size.message}")
	private String orderNo;

}

The code for the BaseView :

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class BaseView {

	public interface IRequest{};

	public interface IResponse{};
	
	public static class Request{};
	
	public static class RequestDes{};
	
	public static class Response{};
	
	public static class QueryParam{};
	
	public static class QueryParamDes{};
	
	public static class KeyHint{};
	
	@JsonView({Request.class})
	@JsonProperty("Sign")
	@NotNull(groups={Request.class})
	private String sign;
	
	@JsonView({QueryParam.class})
	@JsonProperty("key")
	@ApiParam(hidden=true)
	private String key;
	
	public static class QueryParamsBuilder {
		private StringBuilder builder;
		
		public QueryParamsBuilder() {
			this.builder = new StringBuilder();
		}
		
	    @JsonAnySetter
	    public void addToUri(String name, Object property) {
	    	if (!StringUtils.isEmpty(property)) {
		        if (this.builder.length() > 0) {
		        	this.builder.append("&");
		        }
		        this.builder.append(name).append("=").append(property);	    		
	    	}	    	
	    }

	    @Override
	    public String toString() {
	        return this.builder.toString();
	    }
	}
	
	public static class KeyHintBuilder {
		private StringBuilder builder;
		
		public KeyHintBuilder() {
			this.builder = new StringBuilder();
		}
		
	    @JsonAnySetter
	    public void addProperty(String name, Object property) {
	    	if (!StringUtils.isEmpty(property)) {
	    		this.builder.append(property);	
	    	}	    	
	    }

	    @Override
	    public String toString() {
	        return this.builder.toString();
	    }
	}

}

I tried to strip @JSONVIEW and @validated related annotations to leave only @ModelAttribute annotation but the issue still persist


	@RequestMapping(method = POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
	@JsonView({BaseView.Response.class})
	public ResponseEntity<WithdrawQueryResponseView> performWithdrawQueryMd5(
									@ModelAttribute 									
									WithdrawQueryRequestView view)

out of curiosity, I stripped io.springfox springfox-boot-starter 3.0.0-SNAPSHOT dependency from my pom.xml and added springfox dependencies with latest stable version 2.10.5 one by one. Surprisingly the issue resolved without any modification to the above controller's method (@JSONVIEW and @validated are intact)

I really want to use the io.springfox springfox-boot-starter 3.0.0-SNAPSHOT as i'm using spring boot framework (version 2.2.6.RELEASE) now. Is that something related to my current configurations which doesn't work well with this dependency ?

		<!-- SWAGGER -->
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.10.5</version>
		</dependency>		

		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.10.5</version>
		</dependency>

		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-spring-webmvc</artifactId>
			<version>2.10.5</version>
		</dependency>

		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-bean-validators</artifactId>
			<version>2.10.5</version>
		</dependency>
		<!-- SWAGGER UI -->

image

image

@dilipkrish
Copy link
Member

Thank you for the additional details! 👀

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

2 participants