swagger-api / swagger-api/swagger-ui

Nullable int is with a default value of null is still getting POST with Zero

Open
#8,157 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

In my model I have the following definied:

[DefaultValue(null)]
public int? MyAttrId { get; set; }

When swagger is opened the generated json shows as "MyAttrid" : 0

I had expected "MyAttrid" : null

The Post to my endpoint controller has default Zero when Null was expected.

Is there a setting or another attribute available to fix this?

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

No repository file, test, or entry point is named. First determine whether the payload is generated by Swagger UI or by the C# server serializer, then establish a repository-level reproduction and expected null behavior; done requires a maintainer-confirmed fix or confirmation that the behavior is outside Swagger UI.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, javascript
Domain
api
Issue type
Bug
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.