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 strings showing string null in examples #2151

Conversation

Dunnymeister
Copy link
Contributor

Addresses a reversion in closed issue:

Comments

XML Comments for String properties with tags that contain null were showing the string "null"

For the string property Subtitle:

        /// <summary>
        /// The Subtitle of the book
        /// </summary>
        /// <example>null</example>
        public string Subtitle { get; set; }

Expected:

{
  "generatedAt": "2021-06-28T02:12:19.2734596Z",
  "id": 419200,
  "title": "The Moonstone",
  "subtitle": null
}

Actual:

{
  "generatedAt": "2021-06-28T02:12:19.2734596Z",
  "id": 419200,
  "title": "The Moonstone",
  "subtitle": "null"
}

This was initially fixed in PR #1866 but broke again in 6.0.1 when swagger-ui fixed a bug where it was being passed a string "null" and turning it into a "null" value. (See swagger-api/swagger-ui#6872)

Please find tests and bug fixes included.

@@ -26,6 +26,18 @@ public void CreateFromJson_SimpleType(string json, Type expectedType, object exp
Assert.Equal(expectedValue, actualValue);
}

[Theory]
[InlineData("null", typeof(OpenApiNull), null)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there's currently only one case, and I can't really think of a need for others, I would define this test as a Fact (no need for InlineData plus parameters) rather than a Theory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, will do!

/// Summary for Nullable StringProperty
/// </summary>
/// <example>null</example>
public string NullableStringProperty { get; set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little nitpick (sorry) but the current name would make me think it's a nullable string in the context of nullable reference types. I think it would make more sense to name it StringPropertyWithNullExample.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggled with how to name this, your suggestion makes a lot more sense. Just updated the PR with this change.

@domaindrivendev
Copy link
Owner

@Dunnymeister a few minor comments but other than that looks great!

@Dunnymeister
Copy link
Contributor Author

@domaindrivendev Thanks very much for the quick feedback!

@domaindrivendev domaindrivendev merged commit a66864f into domaindrivendev:master Jun 29, 2021
@Dunnymeister Dunnymeister deleted the nullable-strings-showing-string-null-in-examples branch June 30, 2021 01:00
@rozbo
Copy link
Contributor

rozbo commented Jul 24, 2021

when release this ? 6.1.5

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

Successfully merging this pull request may close these issues.

None yet

3 participants