modelina icon indicating copy to clipboard operation
modelina copied to clipboard

C# generator add xml docs from the async api description

Open diogonborges opened this issue 1 year ago • 5 comments

Reason/Context

Please try answering few of those questions

  • Why we need this improvement? To not lose information (from a documention perspective) in the process of generating C# models
  • How will this change help? Improve the C# generation to be more complete
  • What is the motivation? We're using this on our project to generated C# contracts for the models

Description

Please try answering few of those questions

  • What changes have to be introduced? Unsure
  • Will this be a breaking change? No
  • How could it be implemented/designed? Unsure

diogonborges avatar May 25 '23 14:05 diogonborges

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

github-actions[bot] avatar May 25 '23 14:05 github-actions[bot]

@diogonborges can you give an example model i.e. the output you are looking for?

jonaslagoni avatar May 25 '23 15:05 jonaslagoni

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Sep 28 '23 00:09 github-actions[bot]

This issue is similar to how the other languages work in terms of adding descriptions: https://modelina.org/playground?tsIncludeDescriptions=true

This means we have to utilize the functionality of xmldoc: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/?redirectedfrom=MSDN

What we are looking to generate is a description per model and property:

namespace asyncapi.models
{
    using System.Collections.Generic;
    /// <summary>
    /// The light measured payload
    /// </summary>
    public class LightMeasured
    {
        /// <summary>
        /// Id of the streetlight.
        /// </summary>
        private int? id;

        /// <summary>
        /// Light intensity measured in lumens.
        /// </summary>
        private int? lumens;

        /// <summary>
        /// Date and time when the message was sent.
        /// </summary>
        private string? sentAt;

        private Dictionary<string, dynamic>? additionalProperties;

        public int? Id
        {
            get { return id; }
            set { id = value; }
        }

        public int? Lumens
        {
            get { return lumens; }
            set { lumens = value; }
        }

        public string? SentAt
        {
            get { return sentAt; }
            set { sentAt = value; }
        }

        public Dictionary<string, dynamic>? AdditionalProperties
        {
            get { return additionalProperties; }
            set { additionalProperties = value; }
        }
    }
}

We can do this through presets, you can follow this guide to add it: https://github.com/asyncapi/modelina/blob/master/docs/contributing.md#adding-a-new-preset

You can use the following existing description preset for TS as reference: https://github.com/asyncapi/modelina/blob/master/src/generators/typescript/presets/DescriptionPreset.ts

jonaslagoni avatar Jan 12 '24 00:01 jonaslagoni