-
Notifications
You must be signed in to change notification settings - Fork 4
Usage guide
Adrian edited this page Jul 23, 2018
·
1 revision
As a provider you have to be using Swagger. Your REST API has to be documented and you need to generate swagger.json file. There's a lot of tutorials in the web describing how to get started using swagger. If you already have you swagger.json generated then you can perform a REST call to Judge D endpoint and wait for response containing validation results.
For spring-boot users the easiest way to generate swagger.json file is by creating integration test (which in fact doesn't test anything but is able to set up context without running application). Below example written in Spock:
@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class SwaggerJsonGenerator extends Specification {
@Autowired
private WebApplicationContext webApplicationContext
@Value('${springfox.documentation.swagger.v2.path}')
private String documentationPath
private MockMvc mockMvc
def setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build()
}
def "should generate swagger json"() {
given:
ResultHandler resultHandler = { r ->
def swaggerJsonAsString = r.getResponse().getContentAsString()
def swaggerDir = new File('build/swagger')
swaggerDir.mkdirs()
def swaggerJsonFile = new File(swaggerDir, 'swagger.json')
swaggerJsonFile.createNewFile()
Files.write(Paths.get(swaggerJsonFile.getAbsolutePath()), swaggerJsonAsString.getBytes('UTF-8'))
}
expect:
mockMvc.perform(get(documentationPath).accept(MediaType.APPLICATION_JSON))
.andDo(resultHandler)
}
}
As a result we will have file called swagger.json generated in build/swagger/ directory (yep, we're using gradle sometimes).
TODO
TODO
TODO