Test openapi schema parameters in path
This commit is contained in:
@@ -38,6 +38,7 @@ paths:
|
|||||||
properties:
|
properties:
|
||||||
result:
|
result:
|
||||||
type: array
|
type: array
|
||||||
|
maxItems: 50
|
||||||
items:
|
items:
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
@@ -47,6 +48,7 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
created_by:
|
created_by:
|
||||||
type: object
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
type: string
|
type: string
|
||||||
@@ -63,6 +65,7 @@ paths:
|
|||||||
workgroup:
|
workgroup:
|
||||||
type: object
|
type: object
|
||||||
nullable: true
|
nullable: true
|
||||||
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
type: string
|
type: string
|
||||||
@@ -71,6 +74,69 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
draft:
|
draft:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
/articles/{article}:
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/article'
|
||||||
|
get:
|
||||||
|
security:
|
||||||
|
- JWTAuth: []
|
||||||
|
summary: Get one article
|
||||||
|
tags:
|
||||||
|
- article
|
||||||
|
operationId: getArticle
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: The Article objects
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
title:
|
||||||
|
type: string
|
||||||
|
anonymous:
|
||||||
|
type: boolean
|
||||||
|
content:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
tags:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
draft:
|
||||||
|
type: boolean
|
||||||
|
last_version:
|
||||||
|
type: boolean
|
||||||
|
created_by:
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
name:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
first_name:
|
||||||
|
type: string
|
||||||
|
last_name:
|
||||||
|
type: string
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
workgroup:
|
||||||
|
type: object
|
||||||
|
nullable: true
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
|
||||||
components:
|
components:
|
||||||
parameters:
|
parameters:
|
||||||
@@ -143,6 +209,17 @@ components:
|
|||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
|
||||||
|
article:
|
||||||
|
name: article
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: the ID of article
|
||||||
|
example: d91aa0cd-61d6-83cc-41bb-8d5656e130f7
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
|
||||||
schemas:
|
schemas:
|
||||||
UUID:
|
UUID:
|
||||||
type: string
|
type: string
|
||||||
@@ -159,6 +236,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
result:
|
result:
|
||||||
type: array
|
type: array
|
||||||
|
maxItems: 50
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/UuidEntity'
|
$ref: '#/components/schemas/UuidEntity'
|
||||||
count:
|
count:
|
||||||
@@ -172,6 +250,7 @@ components:
|
|||||||
limit:
|
limit:
|
||||||
type: integer
|
type: integer
|
||||||
minimum: 0
|
minimum: 0
|
||||||
|
maximum: 50
|
||||||
example: 50
|
example: 50
|
||||||
offset:
|
offset:
|
||||||
type: integer
|
type: integer
|
||||||
@@ -181,6 +260,14 @@ components:
|
|||||||
type: integer
|
type: integer
|
||||||
minimum: 0
|
minimum: 0
|
||||||
example: 1
|
example: 1
|
||||||
|
|
||||||
|
securitySchemes:
|
||||||
|
JWTAuth:
|
||||||
|
type: http
|
||||||
|
scheme: bearer
|
||||||
|
description: call /login to get token
|
||||||
|
bearerFormat: JWT
|
||||||
|
|
||||||
servers:
|
servers:
|
||||||
- description: localhost
|
- description: localhost
|
||||||
url: http://localhost:8080
|
url: http://localhost:8080
|
||||||
|
|||||||
@@ -57,6 +57,18 @@ class `Article routes` : BaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `I can get article by id`() {
|
||||||
|
withIntegrationApplication {
|
||||||
|
`Given I have article`(id = "65cda9f3-8991-4420-8d41-1da9da72c9bb")
|
||||||
|
`When I send a GET request`("/articles/65cda9f3-8991-4420-8d41-1da9da72c9bb") `Then the response should be` OK and {
|
||||||
|
`And the response should not be null`()
|
||||||
|
`And have property`("$.id") `whish contains` "65cda9f3-8991-4420-8d41-1da9da72c9bb"
|
||||||
|
`And schema must be valid`()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `I can get versions of article by the id`() {
|
fun `I can get versions of article by the id`() {
|
||||||
withIntegrationApplication {
|
withIntegrationApplication {
|
||||||
@@ -69,17 +81,6 @@ class `Article routes` : BaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `I can get article by id`() {
|
|
||||||
withIntegrationApplication {
|
|
||||||
`Given I have article`(id = "65cda9f3-8991-4420-8d41-1da9da72c9bb")
|
|
||||||
`When I send a GET request`("/articles/65cda9f3-8991-4420-8d41-1da9da72c9bb") `Then the response should be` OK and {
|
|
||||||
`And the response should not be null`()
|
|
||||||
`And have property`("$.id") `whish contains` "65cda9f3-8991-4420-8d41-1da9da72c9bb"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `I can create an article`() {
|
fun `I can create an article`() {
|
||||||
withIntegrationApplication {
|
withIntegrationApplication {
|
||||||
|
|||||||
@@ -17,13 +17,17 @@ import org.openapi4j.schema.validator.v3.SchemaValidator
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
fun TestApplicationResponse.`And schema must be valid`() {
|
fun TestApplicationResponse.`And schema must be valid`(route: String? = null) {
|
||||||
val uri = "/" + Url(call.request.uri).encodedPath
|
|
||||||
val operation = call.request.httpMethod
|
|
||||||
|
|
||||||
OpenApi3Parser().parse(File("/openapi2.yaml".getResource().toURI()), true).let { api ->
|
OpenApi3Parser().parse(File("/openapi2.yaml".getResource().toURI()), true).let { api ->
|
||||||
api.getPath(uri)
|
val operation = call.request.httpMethod
|
||||||
?.getOperation(operation.value.toLowerCase())?.apply {
|
val uri = route ?: "/" + Url(call.request.uri).encodedPath
|
||||||
|
val path = api.paths
|
||||||
|
.keys
|
||||||
|
.firstOrNull { uri.matches(it.replace("""\{[^{}]+}""".toRegex(), "[^/]+").toRegex()) }
|
||||||
|
|
||||||
|
api.getPath(path)
|
||||||
|
?.getOperation(operation.value.toLowerCase())
|
||||||
|
?.apply {
|
||||||
val mediaType = call.request.contentType()
|
val mediaType = call.request.contentType()
|
||||||
val status = call.response.status()
|
val status = call.response.status()
|
||||||
getResponse(status?.value?.toString() ?: error("HttpStatus not found"))
|
getResponse(status?.value?.toString() ?: error("HttpStatus not found"))
|
||||||
@@ -38,11 +42,13 @@ fun TestApplicationResponse.`And schema must be valid`() {
|
|||||||
schemaValidator.validate(mapper.readTree(content), results)
|
schemaValidator.validate(mapper.readTree(content), results)
|
||||||
|
|
||||||
assertTrue(results.isValid, results.results().toString())
|
assertTrue(results.isValid, results.results().toString())
|
||||||
} ?: error("""No path found for "$operation $uri" for status ${status.value} with media type "$mediaType".""")
|
}
|
||||||
}?.apply {
|
?: error("""No path found for "$operation $uri" for status ${status.value} with media type "$mediaType".""")
|
||||||
|
}
|
||||||
|
?.apply {
|
||||||
Url(call.request.uri).parameters.forEach { parameter: String, values: List<String> ->
|
Url(call.request.uri).parameters.forEach { parameter: String, values: List<String> ->
|
||||||
getParametersIn(api.context, "query")
|
getParametersIn(api.context, "query")
|
||||||
?.firstOrNull { it.name == "workgroup" }?.schema?.let { schema ->
|
?.firstOrNull { it.name == parameter }?.schema?.let { schema ->
|
||||||
val validationContext: ValidationContext<OAI3> = ValidationContext(api.context)
|
val validationContext: ValidationContext<OAI3> = ValidationContext(api.context)
|
||||||
val jsonNode: JsonNode = schema.toNode()
|
val jsonNode: JsonNode = schema.toNode()
|
||||||
val schemaValidator = SchemaValidator(validationContext, "", jsonNode)
|
val schemaValidator = SchemaValidator(validationContext, "", jsonNode)
|
||||||
@@ -50,8 +56,10 @@ fun TestApplicationResponse.`And schema must be valid`() {
|
|||||||
schemaValidator.validate(TextNode(values.first()), params)
|
schemaValidator.validate(TextNode(values.first()), params)
|
||||||
|
|
||||||
assertTrue(params.isValid, params.results().toString())
|
assertTrue(params.isValid, params.results().toString())
|
||||||
} ?: error("""No path found for "$operation $uri" for status "$parameter".""")
|
}
|
||||||
|
?: error("""No path found for "$operation $uri" for status "$parameter".""")
|
||||||
}
|
}
|
||||||
} ?: error("""No path found for "$operation $uri".""")
|
}
|
||||||
|
?: error("""No path found for "$operation $uri".""")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user