Open andrewmorris-me opened 5 years ago
I think they are generated as XML docs, no?
the [Description] attribute will generate as a comment in the code, but [Display] does not render anything.
The problem is that json schema/swagger/openapi do not have properties to store both texts, or does it?
There is a screenshot in this corresponding thread of where both attribute details are being stored through openapi. These items I would have thought could be used to generate both the [Display] and [Description] attributes.
https://github.com/RicoSuter/NJsonSchema/issues/1011#issuecomment-508867987
@RicoSuter
Is there any guidance on how to implement this? I believe it can be done, just not sure how or where to start? Thanks
Probably in the JsonSchemaGenerator in the NJsonSchema project?
Thanks for pointing me in the right direction @RicoSuter
I see in the Class.liquid (Line 34) template in the NJsonSchema project, you have the following code:
{% for property in Properties -%}
{% if property.HasDescription -%}
/// {{ property.Description | csharpdocs }}
{% endif -%}
I can modify the template code to create a DescriptionAttribute like so, which is great:
{% for property in Properties -%}
{% if property.HasDescription -%}
/// {{ property.Description | csharpdocs }}
[System.ComponentModel.DataAnnotations.Display(Description = "{{ property.Description }}")]
{% endif -%}
However, I can't seem to obtain the Title from the list of Properties to create a DisplayNameAttribute:
{% for property in Properties -%}
{% if property.HasTitle -%}
/// {{ property.Title | csharpdocs }}
[System.ComponentModel.DataAnnotations.Display(Name = "{{ property.Title }}")]
{% endif -%}
I saw from the following issue below that you added the Title property, based off of the DisplayNameAttribute, but I can't seem to access this title property from within the Class.liquid file?
https://github.com/RicoSuter/NJsonSchema/issues/9#issuecomment-165331280
Does this list of Properties have a Title attribute, or perhaps it's called something else? Where are all these properties defined so I can review them and perhaps add the title/display attribute if possible?
I believe that the PropertyModel class is missing the Title attribute:
Where you have the following inside the class for Description:
/// <summary>Gets a value indicating whether the property has a description.</summary>
public bool HasDescription => !string.IsNullOrEmpty(_property.Description);
/// <summary>Gets the description.</summary>
public string Description => _property.Description;
You would need to add the following for Title:
/// <summary>Gets a value indicating whether the property has a title.</summary>
public bool HasTitle => !string.IsNullOrEmpty(_property.Title);
/// <summary>Gets the title.</summary>
public string Title => _property.Title;
Is there any update on this? Or any work around / instructions on how to get Display into the client generated code?
I'm late to the party but this is also something I would like to see implemented.
I'm currently using NSwag Studio to generate my C# Client. I have the setting "generate data annotation attributes" turned on and seems to work well for data annotations such as [Required], [MaxLength], [Range] etc...
I've noticed, however, that not all annotations are generated though. Annotations such as [Display(Name)] and [Description] are missing from the generated client, even though they've been added to the model class. For example:
Generates the following: