Generate full JSON body for assertion testing?


(Nir) #1

Hi!

I’ve finally reached the testing phase! A few questions:

first question: For the validate.contract test I can see the following:
output.body [validate.contract] [schema object not shown for now]

(root): Invalid type. Expected: object, given: array (root): Invalid type. Expected: object, given: array (root): Must validate all the schemas (allOf)

The document is not valid. see errors

Ok, cool - but I wanted to see WHERE it’s not valid - could you point me to the right place to check which items are failing the assertion? The use case is simply telling the engineer what to change.

Second question: Is there a way to programmatically create a JSON body (or random object) based on spec in the JavaScript?

The use case here is to post random objects, and then GET and assert the datapoints all propogated correctly and that the proper things get set.

For instance, if my schema specifies a JSON like that:

{ “bar”:string, “klux”:number } - there is already code that generates examples based on the validation. Can I access it from the JAvascript to create the applicable JS object and then manipulate it, save it to context, so I can test it from a later stage?

Example use case - i know that if “bar”: is a specific value then the system should do things, and on a subsequent get of a different object I would see a certain value. I would like to assert that - all the while generating random items for the objects I place into the system based on the schema.


(Taylor Barnett) #2

To answer this, this is something we want to work on with the newer version of Prism. The older version did a better job of this. And we agree, it needs to be more helpful.


(Nir) #3

I just realized it was trying to tell me all along but I was very much thrown off by the “schema object not shown” and “see errors” prompts. It would be nicer if we could see the object expected (a mock obviously) compared to what was received and the differences highlighted…

As for exposing the same functions that generate the mock in prism (there has to be a function that generates a json object based on schema somewhere since it’s in the mock) to the runtime?

Something in the vein of x = SL.generate(‘modelname’) or something like that?

thanks for your reply!


(Taylor Barnett) #4

No problem! I’m going to move this to #feedback so that I can track it better.

Those messages could definitely be more helpful.