OpenAPITools / OpenAPITools/openapi-generator
[Question] [CSHARP] Disable validation of required fields in model constructor and json
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I am attempting to disable client model validation entirely in C# in order to run negative tests on my service. More specifically, I need my client model classes to not perform null checks in the constructors, and the Json serializer to ignore empty fields. Some of the fields are required in my yaml, but I specifically want to send null values to the service to test its behavior. Is there an easy way to achieve this?
I have set "validatable": false in the config json, but I don't know what this setting is affecting (but it's not what I need).
openapi-generator version
I'm running version 4.1.2 with Swagger 3.0.
Command line used for generation
java -jar openapi-generator-cli.jar generate -i D:...\Blah.yaml -g csharp --config D:...\GeneratorConfig.json
Steps to reproduce
- Have a yaml model with a required field
- Run the above command line operation with a json config containing:
{
"validatable": false,
} - Check the model constructor, and observe that there are null checks on the required params.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the provided Swagger 3.0 YAML, C# generator command, and config containing validatable=false. Inspect the generated model constructors and JSON serialization behavior to determine what that setting changes; done means there is a clear supported way to omit required-field null checks and serialize empty fields for negative tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java, openapi
- Domain
- devtools, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100