Search code examples
bddapiblueprintdredd

Reuse of schema / model apiblueprint for repeated requests with other parameters


What I'm trying to do with an API-blueprint (with dredd as testrunner) is calling a backend twice in a row with almost the same (complex) request. What I would like to do is define an input for a certain endpoint and have some placeholders in there, maybe with defaults if no parameters given.

Like : request 1, dataset x, param x = 0 => result = 'nothing to do'

Like : request 2, dataset x, param x = 100 => result = 'a whole lot to do'

Does apiblueprint supply in this functionality?

Searched for it, and schemas and models seem to come near, but I cannot find any example implementation that does exactly this.

Kind regards, Tim


Solution

  • If I understand your question correctly, what you may want to use is a combination of following features:

    Describe your two use cases as two separate transactions in your API Blueprint. Then, you should be able to test them with Dredd. To ensure your API Blueprint is DRY, use the power of Attributes Section and make use of inheritance or mixins. Then, if you still feel like lacking a firmer grip around how Dredd tests the blueprint, you can alter what is being sent using hooks. Dredd Hooks allow you to programatically enhance Dredd's behavior and they can be written in multiple programming languages.