Skip to content

Commit a2dd36a

Browse files
committed
fix: just set raw JSON content in schema object
1 parent cba5b7b commit a2dd36a

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

src/main/kotlin/com/ctrlhub/core/datacapture/FormSchemasRouter.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FormSchemasRouter(httpClient: HttpClient) : Router(httpClient) {
1717
formId: String,
1818
requestParameters: RequestParameters = RequestParameters()
1919
): PaginatedList<FormSchema> {
20-
val endpoint = "/v3/orgs/$organisationId/data-capture/forms/{$formId}/schemas"
20+
val endpoint = "/v3/orgs/$organisationId/data-capture/forms/$formId/schemas"
2121

2222
val response = performGet(endpoint, requestParameters.toMap())
2323
val jsonContent = Json.parseToJsonElement(response.body<String>()).jsonObject
@@ -42,28 +42,21 @@ class FormSchemasRouter(httpClient: HttpClient) : Router(httpClient) {
4242
val endpoint = "/v3/orgs/$organisationId/data-capture/forms/$formId/schemas/$schemaId"
4343

4444
val response = performGet(endpoint, requestParameters.toMap())
45-
val jsonContent = Json.parseToJsonElement(response.body<String>()).jsonObject
46-
47-
val dataObject = jsonContent["data"]?.jsonObject
48-
?: throw IllegalStateException("Missing data object")
45+
val jsonContent = Json.parseToJsonElement(response.body<String>()).jsonObjectOrNull()
46+
?: throw IllegalStateException("Missing JSON content")
4947

50-
return instantiateFormSchemaFromJson(dataObject)
48+
return instantiateFormSchemaFromJson(jsonContent)
5149
}
5250

5351
private fun instantiateFormSchemaFromJson(json: JsonObject): FormSchema {
5452
val id = json["id"]?.jsonPrimitive?.content
5553
?: throw IllegalStateException("Missing id")
5654

57-
val attributes = json["attributes"]?.jsonObject ?: JsonObject(emptyMap())
58-
val model = attributes["model"]?.jsonObjectOrNull()
59-
val views = attributes["views"]?.jsonObjectOrNull()
55+
val rawContent = json.toString()
6056

6157
return FormSchema(
6258
id = id,
63-
modelConfig = model,
64-
viewsConfig = views,
65-
modelConfigStr = model?.toString() ?: "",
66-
viewsConfigStr = views?.toString() ?: ""
59+
rawSchema = rawContent
6760
)
6861
}
6962

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package com.ctrlhub.core.datacapture.response
22

33
import com.github.jasminb.jsonapi.annotations.Type
4-
import kotlinx.serialization.json.JsonObject
54

65
@Type("form-schemas")
76
data class FormSchema (
87
val id: String,
9-
val modelConfigStr: String,
10-
val viewsConfigStr: String,
11-
12-
val modelConfig: JsonObject?,
13-
val viewsConfig: JsonObject?,
8+
val rawSchema: String,
149
)

src/test/kotlin/com/ctrlhub/core/datacapture/FormSchemasRouterTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class FormSchemasRouterTest {
4343
assertEquals(1, response.data.size)
4444
val formSchema = response.data[0]
4545
assertEquals("1.0.0", formSchema.id)
46-
assertTrue(formSchema.modelConfigStr.isNotEmpty())
47-
assertTrue(formSchema.viewsConfigStr.isNotEmpty())
46+
assertTrue(formSchema.rawSchema.isNotEmpty())
4847
}
4948
}
5049
}

0 commit comments

Comments
 (0)