Fixed process responses in openapi.yaml -- they were a layer too low, w/ a wrapped "typedResponse" above them (and since they were being serialized directly by jackson, were missing the 'values' now that they were marked to be ignored by it... so going through our conversion method in here - this suggests some refactoring that should apply a change like this to all specs, in case they have overrides of handleOutput as well...

This commit is contained in:
2024-12-11 15:27:33 -06:00
parent e84fe7eb18
commit abc6331131
2 changed files with 166 additions and 167 deletions

View File

@ -28,6 +28,7 @@ import java.time.LocalDate;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.actions.values.QValueFormatter;
@ -141,12 +142,14 @@ public class ProcessSpecUtilsV1
errorResponse.setError("Illegal Argument Exception: NaN");
errorResponse.setUserFacingError("The process could not be completed due to invalid input.");
Function<ProcessInitOrStepOrStatusResponseV1, Example> responseToExample = response -> new Example().withValue(convertResponseToJSONObject(response).toMap());
return MapBuilder.of(() -> new LinkedHashMap<String, Example>())
.with("COMPLETE", new Example().withValue(completeResponse))
.with("COMPLETE with metaDataAdjustment", new Example().withValue(completeResponseWithMetaDataAdjustment))
.with("JOB_STARTED", new Example().withValue(jobStartedResponse))
.with("RUNNING", new Example().withValue(runningResponse))
.with("ERROR", new Example().withValue(errorResponse))
.with("COMPLETE", responseToExample.apply(completeResponse))
.with("COMPLETE with metaDataAdjustment", responseToExample.apply(completeResponseWithMetaDataAdjustment))
.with("JOB_STARTED", responseToExample.apply(jobStartedResponse))
.with("RUNNING", responseToExample.apply(runningResponse))
.with("ERROR", responseToExample.apply(errorResponse))
.build();
}
@ -155,7 +158,21 @@ public class ProcessSpecUtilsV1
/***************************************************************************
**
***************************************************************************/
public static void handleOutput(Context context, ProcessInitOrStepOrStatusResponseV1 output)
public static void handleOutput(Context context, ProcessInitOrStepOrStatusResponseV1 response)
{
JSONObject outputJsonObject = convertResponseToJSONObject(response);
String json = outputJsonObject.toString(3);
System.out.println(json);
context.result(json);
}
/***************************************************************************
**
***************************************************************************/
private static JSONObject convertResponseToJSONObject(ProcessInitOrStepOrStatusResponseV1 response)
{
////////////////////////////////////////////////////////////////////////////////
// normally, we like the JsonUtils behavior of excluding null/empty elements. //
@ -163,7 +180,7 @@ public class ProcessSpecUtilsV1
// so, go through a loop of object → JSON String → JSONObject → String... //
// also - work with the TypedResponse sub-object within this response class //
////////////////////////////////////////////////////////////////////////////////
ProcessInitOrStepOrStatusResponseV1.TypedResponse typedOutput = output.getTypedResponse();
ProcessInitOrStepOrStatusResponseV1.TypedResponse typedOutput = response.getTypedResponse();
String outputJson = JsonUtils.toJson(typedOutput);
JSONObject outputJsonObject = new JSONObject(outputJson);
@ -280,10 +297,7 @@ public class ProcessSpecUtilsV1
outputJsonObject.put("values", valuesAsJsonObject);
}
}
String json = outputJsonObject.toString(3);
System.out.println(json);
context.result(json);
return outputJsonObject;
}

View File

@ -1652,66 +1652,61 @@ paths:
examples:
COMPLETE:
value:
typedResponse:
nextStep: "reviewScreen"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "COMPLETE"
values:
totalAge: 32768
firstLastName: "Aabramson"
values:
firstLastName: "Aabramson"
totalAge: 32768
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
nextStep: "reviewScreen"
type: "COMPLETE"
COMPLETE with metaDataAdjustment:
value:
typedResponse:
nextStep: "inputScreen"
processMetaDataAdjustment:
updatedFields:
someField:
displayFormat: "%s"
isEditable: true
isHeavy: false
isHidden: false
isRequired: true
name: "someField"
type: "STRING"
updatedFrontendStepList:
- components:
- type: "EDIT_FORM"
formFields:
- displayFormat: "%s"
isEditable: true
isHeavy: false
isHidden: false
isRequired: false
name: "someField"
type: "STRING"
name: "inputScreen"
- components:
- type: "PROCESS_SUMMARY_RESULTS"
name: "resultScreen"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "COMPLETE"
values:
totalAge: 32768
firstLastName: "Aabramson"
values:
firstLastName: "Aabramson"
totalAge: 32768
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
nextStep: "inputScreen"
processMetaDataAdjustment:
updatedFields:
someField:
isRequired: true
isEditable: true
name: "someField"
displayFormat: "%s"
type: "STRING"
isHeavy: false
isHidden: false
updatedFrontendStepList:
- components:
- type: "EDIT_FORM"
name: "inputScreen"
formFields:
- isRequired: false
isEditable: true
name: "someField"
displayFormat: "%s"
type: "STRING"
isHeavy: false
isHidden: false
- components:
- type: "PROCESS_SUMMARY_RESULTS"
name: "resultScreen"
type: "COMPLETE"
JOB_STARTED:
value:
typedResponse:
jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "JOB_STARTED"
jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "JOB_STARTED"
RUNNING:
value:
typedResponse:
current: 47
message: "Processing person records"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
total: 1701
type: "RUNNING"
current: 47
total: 1701
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
message: "Processing person records"
ERROR:
value:
typedResponse:
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
schema:
$ref: "#/components/schemas/ProcessStepResponseV1"
description: "State of the initialization of the job, with different fields\
@ -1788,66 +1783,61 @@ paths:
examples:
COMPLETE:
value:
typedResponse:
nextStep: "reviewScreen"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "COMPLETE"
values:
totalAge: 32768
firstLastName: "Aabramson"
values:
firstLastName: "Aabramson"
totalAge: 32768
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
nextStep: "reviewScreen"
type: "COMPLETE"
COMPLETE with metaDataAdjustment:
value:
typedResponse:
nextStep: "inputScreen"
processMetaDataAdjustment:
updatedFields:
someField:
displayFormat: "%s"
isEditable: true
isHeavy: false
isHidden: false
isRequired: true
name: "someField"
type: "STRING"
updatedFrontendStepList:
- components:
- type: "EDIT_FORM"
formFields:
- displayFormat: "%s"
isEditable: true
isHeavy: false
isHidden: false
isRequired: false
name: "someField"
type: "STRING"
name: "inputScreen"
- components:
- type: "PROCESS_SUMMARY_RESULTS"
name: "resultScreen"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "COMPLETE"
values:
totalAge: 32768
firstLastName: "Aabramson"
values:
firstLastName: "Aabramson"
totalAge: 32768
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
nextStep: "inputScreen"
processMetaDataAdjustment:
updatedFields:
someField:
isRequired: true
isEditable: true
name: "someField"
displayFormat: "%s"
type: "STRING"
isHeavy: false
isHidden: false
updatedFrontendStepList:
- components:
- type: "EDIT_FORM"
name: "inputScreen"
formFields:
- isRequired: false
isEditable: true
name: "someField"
displayFormat: "%s"
type: "STRING"
isHeavy: false
isHidden: false
- components:
- type: "PROCESS_SUMMARY_RESULTS"
name: "resultScreen"
type: "COMPLETE"
JOB_STARTED:
value:
typedResponse:
jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "JOB_STARTED"
jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "JOB_STARTED"
RUNNING:
value:
typedResponse:
current: 47
message: "Processing person records"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
total: 1701
type: "RUNNING"
current: 47
total: 1701
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
message: "Processing person records"
ERROR:
value:
typedResponse:
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
schema:
$ref: "#/components/schemas/ProcessStepResponseV1"
description: "State of the backend's running of the next step(s) of the\
@ -1895,66 +1885,61 @@ paths:
examples:
COMPLETE:
value:
typedResponse:
nextStep: "reviewScreen"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "COMPLETE"
values:
totalAge: 32768
firstLastName: "Aabramson"
values:
firstLastName: "Aabramson"
totalAge: 32768
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
nextStep: "reviewScreen"
type: "COMPLETE"
COMPLETE with metaDataAdjustment:
value:
typedResponse:
nextStep: "inputScreen"
processMetaDataAdjustment:
updatedFields:
someField:
displayFormat: "%s"
isEditable: true
isHeavy: false
isHidden: false
isRequired: true
name: "someField"
type: "STRING"
updatedFrontendStepList:
- components:
- type: "EDIT_FORM"
formFields:
- displayFormat: "%s"
isEditable: true
isHeavy: false
isHidden: false
isRequired: false
name: "someField"
type: "STRING"
name: "inputScreen"
- components:
- type: "PROCESS_SUMMARY_RESULTS"
name: "resultScreen"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "COMPLETE"
values:
totalAge: 32768
firstLastName: "Aabramson"
values:
firstLastName: "Aabramson"
totalAge: 32768
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
nextStep: "inputScreen"
processMetaDataAdjustment:
updatedFields:
someField:
isRequired: true
isEditable: true
name: "someField"
displayFormat: "%s"
type: "STRING"
isHeavy: false
isHidden: false
updatedFrontendStepList:
- components:
- type: "EDIT_FORM"
name: "inputScreen"
formFields:
- isRequired: false
isEditable: true
name: "someField"
displayFormat: "%s"
type: "STRING"
isHeavy: false
isHidden: false
- components:
- type: "PROCESS_SUMMARY_RESULTS"
name: "resultScreen"
type: "COMPLETE"
JOB_STARTED:
value:
typedResponse:
jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "JOB_STARTED"
jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "JOB_STARTED"
RUNNING:
value:
typedResponse:
current: 47
message: "Processing person records"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
total: 1701
type: "RUNNING"
current: 47
total: 1701
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
message: "Processing person records"
ERROR:
value:
typedResponse:
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF"
type: "RUNNING"
schema:
$ref: "#/components/schemas/ProcessStepResponseV1"
description: "State of the backend's running of the specified job, with\