From cf21dd61633f5e6e2d83cc5f1256ce9d742c75d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20D=C3=BCsterh=C3=B6ft?= Date: Tue, 4 Sep 2018 16:16:38 +0200 Subject: [PATCH] GH-41 convert the field type to a value of JsonFieldType (#43) --- .../com/epages/restdocs/openapi/DescriptorValidator.kt | 3 +++ .../com/epages/restdocs/openapi/ResourceSnippetTest.kt | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/restdocs-openapi/src/main/kotlin/com/epages/restdocs/openapi/DescriptorValidator.kt b/restdocs-openapi/src/main/kotlin/com/epages/restdocs/openapi/DescriptorValidator.kt index d65434bc..e23b3185 100644 --- a/restdocs-openapi/src/main/kotlin/com/epages/restdocs/openapi/DescriptorValidator.kt +++ b/restdocs-openapi/src/main/kotlin/com/epages/restdocs/openapi/DescriptorValidator.kt @@ -9,6 +9,7 @@ import org.springframework.restdocs.hypermedia.LinkDescriptor import org.springframework.restdocs.hypermedia.LinksSnippet import org.springframework.restdocs.operation.Operation import org.springframework.restdocs.payload.FieldDescriptor +import org.springframework.restdocs.payload.JsonFieldType import org.springframework.restdocs.payload.RequestFieldsSnippet import org.springframework.restdocs.payload.ResponseFieldsSnippet import org.springframework.restdocs.request.ParameterDescriptor @@ -131,6 +132,8 @@ internal object DescriptorValidator { fieldsModel .firstOrNull { d.path == it["path"] } ?.get("type") + ?.let { it as String } + ?.let { JsonFieldType.valueOf(it.toUpperCase()) } ?.let { d.type(it) } } } diff --git a/restdocs-openapi/src/test/kotlin/com/epages/restdocs/openapi/ResourceSnippetTest.kt b/restdocs-openapi/src/test/kotlin/com/epages/restdocs/openapi/ResourceSnippetTest.kt index 99139bfc..9da2bb37 100644 --- a/restdocs-openapi/src/test/kotlin/com/epages/restdocs/openapi/ResourceSnippetTest.kt +++ b/restdocs-openapi/src/test/kotlin/com/epages/restdocs/openapi/ResourceSnippetTest.kt @@ -18,6 +18,7 @@ import org.springframework.http.MediaType.APPLICATION_JSON_VALUE import org.springframework.restdocs.generate.RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE import org.springframework.restdocs.headers.HeaderDocumentation import org.springframework.restdocs.operation.Operation +import org.springframework.restdocs.payload.JsonFieldType import org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath import java.io.File import java.io.IOException @@ -137,7 +138,12 @@ class ResourceSnippetTest(private val temporaryFolder: TemporaryFolder) { then(resourceSnippetJson.read("request.example")).isEqualTo(operation.request.contentAsString) then(resourceSnippetJson.read>("request.requestFields")).hasSize(1) then(resourceSnippetJson.read("request.requestFields[0].description")).isNotEmpty() + with(resourceSnippetJson.read("request.requestFields[0].type")) { + then(this).isNotEmpty() + then(JsonFieldType.valueOf(this)).isEqualTo(JsonFieldType.STRING) + } then(resourceSnippetJson.read("request.requestFields[0].type")).isNotEmpty() + then(JsonFieldType.valueOf(resourceSnippetJson.read("request.requestFields[0].type"))).isNotNull() then(resourceSnippetJson.read("request.requestFields[0].optional")).isFalse() then(resourceSnippetJson.read("request.requestFields[0].ignored")).isFalse() }