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

@Dunnymeister Dunnymeister commented Jun 29, 2021

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

@domaindrivendev domaindrivendev Jun 29, 2021

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

@Dunnymeister Dunnymeister Jun 29, 2021

Makes sense, will do!

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

@domaindrivendev domaindrivendev Jun 29, 2021

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

@Dunnymeister Dunnymeister Jun 29, 2021

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

@domaindrivendev domaindrivendev commented Jun 29, 2021

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

@Dunnymeister
Copy link
Contributor Author

@Dunnymeister Dunnymeister commented Jun 29, 2021

@domaindrivendev Thanks very much for the quick feedback!

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

@rozbo 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
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants