OpenAPITools / OpenAPITools/openapi-generator

[Question] [CSHARP] Disable validation of required fields in model constructor and json

Open
#3,898 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp
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
  1. Have a yaml model with a required field
  2. Run the above command line operation with a json config containing:
    {
    "validatable": false,
    }
  3. Check the model constructor, and observe that there are null checks on the required params.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.