Skip to content

Nullable primitives on a model #172

@phil-scott-78

Description

@phil-scott-78

This is more related to an issue with the Swagger spec itself (OAI/OpenAPI-Specification#229) but I thought it would be important to track here too. Right now there's no difference between a required field and a nullable field. Let's say I have a model that looks like this

class Product
{
    [Required]
    public int ProductId {get;set;}

    [Required]
    public string ProductName {get;set;}

    public string Description {get;set;}

    [Required]
    public int? SomeSuperValidReasonThisFieldShouldBeNullableAndRequiredBesidesBadDesignThatImMarriedTo {get;set;}
}

The best way to do this would be have the nullable field be "type" : ["number","null"]but alas swagger doesn't support that.

Right now I'm adding in custom mapping in the swaggerconfig for each of the main nullables and praying no one else does anything weird in the project to require other value types to be exposed as a nullable and putting a vendor extension of "x-nullable"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions