spring-projects/spring-framework

Convenient API Version Configuration in MockMvc

Closed this issue · 3 comments

hantsy commented

When I wrote the example codes, I found there is no convenient methods for configuring API versioning.

BTW, it seems MockRestServiceServer is also not updated for apiversion mock/assertion.

There is such support, so it's unclear what you mean or what you've tried. The referenced project has a test with an autowired MockMvc. That's configurable through a MockMvcBuilderCustomizer. On ConfigurableMockMvc builder you can set the version inserter for the request side. For the handling side, the standalone builder accepts an ApiVersioningStrategy, or if using an ApplicationContext based setup, then it's picked up from your application config.

The MockMvcBuilderCustomizer lack a defaultApiVersion existed in other Customizers.

Good point, but there is defaultRequest that at least allows it:

standaloneSetup(new MusicController())
		.defaultRequest(get("/").apiVersion("1.2")
		.build()