schemathesis icon indicating copy to clipboard operation
schemathesis copied to clipboard

[FEATURE] Recursion limit to examples

Open ravy opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe

to have control on the recursion in explicit examples

Describe the solution you'd like

from the documentation is see a similar stateful-recursion-limit=<N> when following links maybe we can have a examples-recursion-limit=<N>

Lets say we have a tree with branches, each branch can have more branches. Currently i notice the value of N=7 (counted the nested 'branches' occurrences in below example)

{
	"id":"415feabd",
	"name":"Birch",
	"description":"white birch tree",
	"branches":[
		{
			"name":"b1","leaves":[{"name":"l1"}],
			"branches":[
				{
					"name":"b1","leaves":[{"name":"l1"}],
					"branches":[
						{
							"name":"b1","leaves":[{"name":"l1"}],
							"branches":[
								{
									"name":"b1","leaves":[{"name":"l1"}],
									"branches":[
										{
											"name":"b1","leaves":[{"name":"l1"}],
											"branches":[
												{
													"name":"b1","leaves":[{"name":"l1"}], 
													"branches":[
														{
															"name":"b1","leaves":[{"name":"l1"}],
															"branches":[
																{
																	"name":"b1"
																}
															]
														}
													]
												}
											]
										}
									]
								}
							]
						}
					]
				}
			]
		}
	]
}

There are two issues with current behavior:

  1. unable to control the recursion
  2. the final branch has no leaves (nested objects do not work for the final recursive call issue #2358 )

Expectation:

considering examples-recursion-limit=2

{
	"id":"415feabd",
	"name":"Birch",
	"description":"white birch tree",
	"branches":[
		{
			"name":"b1","leaves":[{"name":"l1"}],
			"branches":[
				{
					"name":"b1","leaves":[{"name":"l1"}],
					"branches":[
						{
							"name":"b1","leaves":[{"name":"l1"}]
						}
					]
				}
			]
		}
	]
}

ravy avatar Jul 24 '24 17:07 ravy

Thanks for pointing out this!

Recursion is a bit complicated right now as it is done by inlining the referenced schema up to N times (7 in most cases). I want to rework how such schemas are processed and expose a way to control the depth - currently, it is in #2207 which is WIP.

I hope to get back to that PR and finish it, but it still requires a lot of work.

Stranger6667 avatar Aug 09 '24 21:08 Stranger6667