Skip to content

Commit

Permalink
GH-41 convert the field type to a value of JsonFieldType (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
mduesterhoeft authored Sep 4, 2018
1 parent 95f7c42 commit cf21dd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,7 +138,12 @@ class ResourceSnippetTest(private val temporaryFolder: TemporaryFolder) {
then(resourceSnippetJson.read<String>("request.example")).isEqualTo(operation.request.contentAsString)
then(resourceSnippetJson.read<List<*>>("request.requestFields")).hasSize(1)
then(resourceSnippetJson.read<String>("request.requestFields[0].description")).isNotEmpty()
with(resourceSnippetJson.read<String>("request.requestFields[0].type")) {
then(this).isNotEmpty()
then(JsonFieldType.valueOf(this)).isEqualTo(JsonFieldType.STRING)
}
then(resourceSnippetJson.read<String>("request.requestFields[0].type")).isNotEmpty()
then(JsonFieldType.valueOf(resourceSnippetJson.read("request.requestFields[0].type"))).isNotNull()
then(resourceSnippetJson.read<Boolean>("request.requestFields[0].optional")).isFalse()
then(resourceSnippetJson.read<Boolean>("request.requestFields[0].ignored")).isFalse()
}
Expand Down

0 comments on commit cf21dd6

Please sign in to comment.