-
-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Custom request data in CLI #1676
Comments
Being able to provide certain values to always be used in your tests seems like an excellent idea to me. |
@hoog1511 thank you for sharing your use case and context! I have a few questions:
|
Hey @Stranger6667 here are my answers to your questions. Which specific types of values do you need to be able to hardcode? E.g. headers / query parameters / etc How do you currently handle such use cases, if at all? Do you anticipate any potential downsides, such as increased maintenance or difficulty in updating hardcoded values? Do you think you'd need to dynamically change these hardcoded values during a test run? or e.g. provide N possible options to choose randomly Yes, I think there could eventually be some use cases where I have to provide multiple hardcoded values to test various example situations (where I do not want to provide them in the OAS for security reasons). Perhaps the option for providing a file containing multiple values for a header, query or path parameter in the CLI might be a viable solution for this. |
Problem
Currently, Schemathesis CLI doesn't allow the user to directly set specific values for different elements in generated API requests such as query parameters, cookies, and body. Only headers are possible directly (via the
-H
CLI option) and the rest are only possible with Python hooks.Solution
Add a set of new CLI options,
--set-<location>
to allow users to set fixed values in API requests. The location could beheader
,query
,cookie
, orbody
.Examples for
header
,cookie
, andquery
:The syntax above is what
-H
uses now for headers, so I believe it could be a simpler transition that provided a unified way to set values there.{name}:{value}
Multiple options could be specified too!
NOTE: Implementing this feature effectively deprecates the
-H
option which is inherited fromcURL
and users are familiar with it. But I think it is more important to have a separate namespace for customizing the generated data via CLI which will unify all possible request elements.For
body
it is a bit different - no need to specify thename
part:Future extensions
I think it could be a minimal version for now, just set the whole body. In the future we might have something like this to set specific values within e.g. a JSON value:
and it will take the
foo
field, then its 4th element, and set thebar
field of this element to42
. However, such a feature requires filling some gaps within the value when e.g. there are not enough elements or they don't have such fields, or maybe they even have different types! These cases are important to resolve upfront before implementing this extension. Another aspect of it is that the "light" version of this feature could work by modifying the schema with some "const" keywords, but this extended version can not in the general case (as the generation of complex structures could be affected by many different keywords).To discuss
:
? What if the user wants to pass a space as a part of the value?--set-form-data
for Open API 2 with the same syntax as forquery
/header
/cookie
?pytest
integration? It feels less relevant as usually users just set desired values directly on the generatedCase
instance. This is basically what Ability to pass parameters directly #8 suggests.Implementation details
Case
generation via theget_case_strategy
modify the schemas, relevant to these components.const
schema insideproperties
and extending therequired
list. For negative cases, it should come after mutation.body
is provided)-H
Related issues
The text was updated successfully, but these errors were encountered: