Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable primitives on a model #172

Closed
phil-scott-78 opened this issue Jan 28, 2015 · 2 comments
Closed

Nullable primitives on a model #172

phil-scott-78 opened this issue Jan 28, 2015 · 2 comments

Comments

@phil-scott-78
Copy link
Contributor

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"

@withinboredom
Copy link

Also misses it on parameters. For example:

[Route("{secretName:alpha}/{version:int?}")]
[HttpGet]
public Secret GetSecret([FromUri] string secretName, [FromUri] int? version = null)

Shows version as required even though it has a default set and its set as optional in the route.

@domaindrivendev
Copy link
Owner

I'm going to close this as it's a Swagger limitation. It's worth noting that in a separate thread I'm proposing the introduction of a separate package that extends Swashbuckle with vendor extensions that are required for client generators such as AutoRest - #776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants