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

If description has /n the Generator dont add /// to comment the line for QueryParameter classes #613

Open
Fargekritt opened this issue Feb 18, 2025 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@Fargekritt
Copy link
Contributor

Fargekritt commented Feb 18, 2025

Describe the bug
If the swagger file has a description with newline the generator dont add /// to comment out the line but it keeps the /n. this creates compile errors.

OpenAPI Specifications
The OpenAPI spec is huge, this is the only relevant section

         {
            "description": "If set to \u0027include\u0027, the result will include both deleted and non-deleted dialogs\nIf set to \u0027exclude\u0027, the result will only include non-deleted dialogs\nIf set to \u0027only\u0027, the result will only include deleted dialogs",
            "in": "query",
            "name": "deleted",
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/V1Common_dFilter"
                }
              ],
              "nullable": true
            }
          },

The generated interface is also huge this is only the relevant section

        /// <summary>
        /// If set to 'include', the result will include both deleted and non-deleted dialogs
If set to 'exclude', the result will only include non-deleted dialogs
If set to 'only', the result will only include deleted dialogs
        /// </summary>
        [Query] 
        public V1Common_dFilter? Deleted { get; set; }

Additional context
.refitter used to generate the interface

{
    "openApiPath": "../Digdir.Domain.Dialogporten.WebApi/bin/Release/net9.0/swagger.json",
    "namespace": "Altinn.ApiClients.Dialogporten.Features.V1",
    "outputFolder": "Features/V1",
    "operationNameGenerator": "SingleClientFromOperationId",
    "trimUnusedSchema": true,
    "multipleInterfaces": "ByTag",
    "includeTags": [
        "Serviceowner"
    ],
    "useCancellationTokens": true,
    "returnIApiResponse": true,
    "useDynamicQuerystringParameters": true,
    "outputFilename": "RefitterInterface.cs",
    "codeGeneratorSettings": {
        "dateFormat": "yyyy-MM-ddTHH:mm:ssZ"
    }
}

The C# that was used when generating the swagger.json

    private DeletedFilter? _deleted = DeletedFilter.Exclude;
    /// <summary>
    /// If set to 'include', the result will include both deleted and non-deleted dialogs
    /// If set to 'exclude', the result will only include non-deleted dialogs
    /// If set to 'only', the result will only include deleted dialogs
    /// </summary>
    public DeletedFilter? Deleted
    {
        get => _deleted;
        set => _deleted = value ?? DeletedFilter.Exclude;
    }

Using Version 1.5.2

        <PackageReference Include="Refitter.SourceGenerator" Version="1.5.2" Condition="$(Configuration)=='Release'">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>

Full Class with the issue

    public class V1ServiceOwnerDialogsSearchSearchDialogQueryParams
    {
        
        /// <summary>
        /// Filter by one or more service resources
        /// </summary>
        [Query(CollectionFormat.Multi)] 
        public IEnumerable<string> ServiceResource { get; set; }

        /// <summary>
        /// Filter by one or more owning parties
        /// </summary>
        [Query(CollectionFormat.Multi)] 
        public IEnumerable<string> Party { get; set; }

        /// <summary>
        /// Filter by end user id
        /// </summary>
        [Query] 
        public string EndUserId { get; set; }

        /// <summary>
        /// Filter by one or more extended statuses
        /// </summary>
        [Query(CollectionFormat.Multi)] 
        public IEnumerable<string> ExtendedStatus { get; set; }

        /// <summary>
        /// Filter by external reference
        /// </summary>
        [Query] 
        public string ExternalReference { get; set; }

        /// <summary>
        /// Filter by status
        /// </summary>
        [Query(CollectionFormat.Multi)] 
        public IEnumerable<DialogsEntities_DialogStatus> Status { get; set; }

        /// <summary>
        /// If set to 'include', the result will include both deleted and non-deleted dialogs
If set to 'exclude', the result will only include non-deleted dialogs
If set to 'only', the result will only include deleted dialogs
        /// </summary>
        [Query] 
        public V1Common_dFilter? Deleted { get; set; }

        /// <summary>
        /// Only return dialogs created after this date
        /// </summary>
        [Query] 
        public System.DateTimeOffset? CreatedAfter { get; set; }

        /// <summary>
        /// Only return dialogs created before this date
        /// </summary>
        [Query] 
        public System.DateTimeOffset? CreatedBefore { get; set; }

        /// <summary>
        /// Only return dialogs updated after this date
        /// </summary>
        [Query] 
        public System.DateTimeOffset? UpdatedAfter { get; set; }

        /// <summary>
        /// Only return dialogs updated before this date
        /// </summary>
        [Query] 
        public System.DateTimeOffset? UpdatedBefore { get; set; }

        /// <summary>
        /// Only return dialogs with due date after this date
        /// </summary>
        [Query] 
        public System.DateTimeOffset? DueAfter { get; set; }

        /// <summary>
        /// Only return dialogs with due date before this date
        /// </summary>
        [Query] 
        public System.DateTimeOffset? DueBefore { get; set; }

        /// <summary>
        /// Only return dialogs with visible-from date after this date
        /// </summary>
        [Query] 
        public System.DateTimeOffset? VisibleAfter { get; set; }

        /// <summary>
        /// Only return dialogs with visible-from date before this date
        /// </summary>
        [Query] 
        public System.DateTimeOffset? VisibleBefore { get; set; }

        /// <summary>
        /// Filter by process
        /// </summary>
        [Query] 
        public string Process { get; set; }

        /// <summary>
        /// Filter by Display state
        /// </summary>
        [Query(CollectionFormat.Multi)] 
        public IEnumerable<DialogEndUserContextsEntities_SystemLabel> SystemLabel { get; set; }

        /// <summary>
        /// Search string for free text search. Will attempt to fuzzily match in all free text fields in the aggregate
        /// </summary>
        [Query] 
        public string Search { get; set; }

        /// <summary>
        /// Limit free text search to texts with this language code, e.g. 'nb', 'en'. Culture codes will be normalized to neutral language codes (ISO 639). Default: search all culture codes
        /// </summary>
        [Query] 
        public string SearchLanguageCode { get; set; }

        [Query] 
        public OrderSetOfTOrderDefinitionAndTTarget OrderBy { get; set; }

        /// <summary>
        /// Supply "continuationToken" for the response to get the next page of results, if hasNextPage is true
        /// </summary>
        [Query] 
        public ContinuationTokenSetOfTOrderDefinitionAndTTarget ContinuationToken { get; set; }

        /// <summary>
        /// Limit the number of results per page (1-1000, default: 100)
        /// </summary>
        [Query] 
        public int? Limit { get; set; }

    }
@Fargekritt Fargekritt added the bug Something isn't working label Feb 18, 2025
@Fargekritt
Copy link
Contributor Author

Also tried running it using 1.5.3-preview.67 same issue.

@Fargekritt
Copy link
Contributor Author

I think ive found where the issue is:
https://github.com/christianhelle/refitter/blob/main/src/Refitter.Core/ParameterExtractor.cs#L214
Here the description is just added without any validation unlike other places for XML gen.

if (settings.GenerateXmlDocCodeComments && !string.IsNullOrWhiteSpace(operationParameter.Description))
{
  propertiesCodeBuilder.Append(
    $$"""
      /// <summary>
      /// {{operationParameter.Description}}
      /// </summary>
    """);
  propertiesCodeBuilder.AppendLine();
}

@Fargekritt Fargekritt changed the title If description has /n the Generator dont add /// to comment the line If description has /n the Generator dont add /// to comment the line for QueryParameter classes Feb 20, 2025
@christianhelle
Copy link
Owner

@Fargekritt Thanks for taking the time to report and look into this.

Sorry for the long response, I'm on vacation and didn't have access to a computer when you reported this

I'll look into this in the coming days, once I get my daily rhythm back 😄

@christianhelle
Copy link
Owner

@Fargekritt If you're up for the task of fixing this yourself, then I'll make sure that your pull request gets merged in

@Fargekritt
Copy link
Contributor Author

@christianhelle I will take a crack at it later this week

@christianhelle
Copy link
Owner

@all-contributors please add @Fargekritt for bugs

Copy link
Contributor

@christianhelle

I've put up a pull request to add @Fargekritt! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants