OpenAPITools / OpenAPITools/openapi-generator

[BUG][C#] Dto properties can't be made non-nullable

Open
#2,269 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Issue: Bug Server: C-Sharp
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

If I try to generate aspnetcore dto's the nullable = false is alwasy ignored and all the properties created are created nullable.

If I have nullable field in my api.yaml file (skipping allot for brevity)

        expireDateOfOffer:
          type: string
          format: date
          nullable: false (toggling/skipping this doesn't change anything! )

and then run the following

java -DdebugModels -jar openapi-generator-cli-4.0.0-20181226.105224-120.jar generate -i api.yaml -g aspnetcore -o c:\Temp -t templates\aspnetcore\controller -Dapis

I get

        /// <summary>
        /// Gets or Sets ExpireDateOfOffer
        /// </summary>
        [DataMember(Name="expireDateOfOffer")]
        public DateTime? ExpireDateOfOffer { get; set; }

I can't seem to get rid off the ? (nullable) after the DateTime.
I don't want it to be nullable!

openapi-generator version

4.0.0-20181226.105224-120

Command line used for generation

java -DdebugModels -jar openapi-generator-cli-4.0.0-20181226.105224-120.jar generate -i api.yaml -g aspnetcore -o c:\Temp -t templates\aspnetcore\dtos -Dapis

Steps to reproduce

Run the previous command line on a yaml file with property you want to have as non-nullable and see if you can make it so.

Related issues/PRs

Couldn't find anything except maybe this one

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 issue with the provided api.yaml and openapi-generator 4.0.0 command, using the aspnetcore DTO templates under templates/aspnetcore/dtos. Inspect the generated model and debugModels output to trace how nullable=false is handled. Done means the generated DateTime property no longer has the nullable marker when the schema property is non-nullable.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.