Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ internal object OpenApi20Generator {
HTTPMethod.PUT -> path.put(resourceModels2Operation(it.value))
HTTPMethod.DELETE -> path.delete(resourceModels2Operation(it.value))
HTTPMethod.PATCH -> path.patch(resourceModels2Operation(it.value))
HTTPMethod.HEAD -> path.head(resourceModels2Operation(it.value))
HTTPMethod.OPTIONS -> path.options(resourceModels2Operation(it.value))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,7 @@ internal enum class HTTPMethod {
POST,
PUT,
DELETE,
PATCH
PATCH,
HEAD,
OPTIONS
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ class OpenApi20GeneratorTest {
thenPathParametersExist(openapi, api)
}

@Test
fun `should convert resource with head http method`() {
val api = givenHeadResourceModel()

val openapi = OpenApi20Generator.generate(api)
println(Json.pretty().writeValueAsString(openapi))

thenHeadRequestExist(openapi, api)
}

@Test
fun `should convert resource with options http method`() {
val api = givenOptionsResourceModel()

val openapi = OpenApi20Generator.generate(api)
println(Json.pretty().writeValueAsString(openapi))

thenOptionsRequestExist(openapi, api)
}

private fun thenOptionsRequestExist(openapi: Swagger, api: List<ResourceModel>) {
then(openapi.getPath(api.get(0).request.path).options).isNotNull()
}

private fun thenHeadRequestExist(openapi: Swagger, api: List<ResourceModel>) {
then(openapi.getPath(api.get(0).request.path).head).isNotNull()
}

private fun thenPathParametersExist(openapi: Swagger, api: List<ResourceModel>) {
val path = openapi.paths.getValue(api[0].request.path).get
then(path.parameters.firstOrNull()).isNotNull
Expand Down Expand Up @@ -272,6 +300,30 @@ class OpenApi20GeneratorTest {
)
}

private fun givenHeadResourceModel(): List<ResourceModel> {
return listOf(
ResourceModel(
operationId = "testHead",
privateResource = false,
deprecated = false,
request = headRequest(),
response = getProductDummyResponse()
)
)
}

private fun givenOptionsResourceModel(): List<ResourceModel> {
return listOf(
ResourceModel(
operationId = "testOptions",
privateResource = false,
deprecated = false,
request = optionsRequest(),
response = getProductDummyResponse()
)
)
}

private fun postProduct200Response(example: String): ResponseModel {
return ResponseModel(
status = 200,
Expand Down Expand Up @@ -341,6 +393,16 @@ class OpenApi20GeneratorTest {
)
}

private fun getProductDummyResponse(): ResponseModel {
return ResponseModel(
status = 200,
contentType = "application/json",
headers = listOf(),
responseFields = listOf(),
example = "{}"
)
}

private fun getProductPayloadExample(): String {
return "{\n" +
" \"_id\": \"123\",\n" +
Expand Down Expand Up @@ -473,6 +535,36 @@ class OpenApi20GeneratorTest {
)
}

private fun headRequest(): RequestModel {
return RequestModel(
path = "/products",
method = HTTPMethod.HEAD,
securityRequirements = SecurityRequirements(
type = OAUTH2,
requiredScopes = listOf()
),
headers = listOf(),
pathParameters = listOf(),
requestParameters = listOf(),
requestFields = listOf()
)
}

private fun optionsRequest(): RequestModel {
return RequestModel(
path = "/products",
method = HTTPMethod.OPTIONS,
securityRequirements = SecurityRequirements(
type = OAUTH2,
requiredScopes = listOf()
),
headers = listOf(),
pathParameters = listOf(),
requestParameters = listOf(),
requestFields = listOf()
)
}

private fun deleteProduct204Response(): ResponseModel {
return ResponseModel(
status = 204,
Expand Down