OpenAPITools / OpenAPITools/openapi-generator

[BUG] Description

Open
#19,017 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

It seems like there is some strange behaviour when generating input from generic types. I have this model for input

    public class RoomsFilter
    {
        public InType<List<Guid>>? RoomIds { get; set; } = null;
        public InType<List<Guid>>? BuildingIds { get; set; } = null;
        public ContainsType<string>? PopularName { get; set; } = null;
        /// <summary>list of properties to sort results </summary>
        public RoomSortKey? SortKey { get; set; } = null;
        /// <summary>Order to sort results by.</summary>
        public SortOrder? SortOrder { get; set; } = null;
    }

While the ContainsType and InType look like this

    public class FilterTypes
    {
        public class EqualsType<T>
        {
            public required T Eq { get; set; }
        }

        public class InType<T>
        {
            /// <summary>Include everything that is contained in the list.</summary>
            public required T In { get; set; }
        }
      
        public class ContainsType<T>
        {
            /// <summary>Include everything that is contained in the string.</summary>
            //Why is this even generic? This logic would probably only make sense for strings anyway
            public required T Contains { get; set; }
        }
    }

The generated code looks like this:

        /// <summary>
        /// Find rooms based on filter. Find rooms based on filtering options.
        /// </summary>
        /// <exception cref="RealEstateCoreApi.ClientSDK.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="roomIdsIn">Include everything that is contained in the list. (optional)</param>
        /// <param name="buildingIdsIn">Include everything that is contained in the list. (optional)</param>
        /// <param name="popularNameContains">Include everything that is contained in the list. (optional)</param>
        /// <param name="sortKey">list of properties to sort results (optional)</param>
        /// <param name="sortOrder">Order to sort results by. (optional)</param>
        /// <param name="page"> (optional)</param>
        /// <param name="perPage"> (optional)</param>
        /// <param name="operationIndex">Index associated with the operation.</param>
        /// <returns>RoomDtoRecApiPaginationResult</returns>
        public RoomDtoRecApiPaginationResult GetRooms(List<Guid>? roomIdsIn = default(List<Guid>?), List<Guid>? buildingIdsIn = default(List<Guid>?), string? popularNameContains = default(string?), RoomSortKey? sortKey = default(RoomSortKey?), SortOrder? sortOrder = default(SortOrder?), int? page = default(int?), int? perPage = default(int?), int operationIndex = 0)
        {
            RealEstateCoreApi.ClientSDK.Client.ApiResponse<RoomDtoRecApiPaginationResult> localVarResponse = GetRoomsWithHttpInfo(roomIdsIn, buildingIdsIn, popularNameContains, sortKey, sortOrder, page, perPage);
            return localVarResponse.Data;
        }

As you can tell, the argumets that are marked as nullable in the source code are not marked as such in the resulting generated code. This behaviour appeared after we upgraded our project to .net 8 and upgraded the generator version to 7.6.0. But reverting the generator version does not fix the issue, so it seems like it might be related to .net 8.

This is how the generated code looked before the .net 8 upgrade and the version bump:

       /// <summary>
        /// Find rooms based on filter. Find rooms based on filtering options.
        /// </summary>
        /// <exception cref="RealEstateCoreApi.ClientSDK.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="roomIdsIn">Include everything that is contained in the list. (optional)</param>
        /// <param name="buildingIdsIn">Include everything that is contained in the list. (optional)</param>
        /// <param name="popularNameContains">Include everything that is contained in the list. (optional)</param>
        /// <param name="sortKey">list of properties to sort results (optional)</param>
        /// <param name="sortOrder">Order to sort results by. (optional)</param>
        /// <param name="page"> (optional)</param>
        /// <param name="perPage"> (optional)</param>
        /// <param name="operationIndex">Index associated with the operation.</param>
        /// <returns>RoomDtoRecApiPaginationResult</returns>
        public RoomDtoRecApiPaginationResult GetRooms(List<Guid>? roomIdsIn = default(List<Guid>?), List<Guid>? buildingIdsIn = default(List<Guid>?), string? popularNameContains = default(string?), RoomSortKey? sortKey = default(RoomSortKey?), SortOrder? sortOrder = default(SortOrder?), int? page = default(int?), int? perPage = default(int?), int operationIndex = 0)
        {
            RealEstateCoreApi.ClientSDK.Client.ApiResponse<RoomDtoRecApiPaginationResult> localVarResponse = GetRoomsWithHttpInfo(roomIdsIn, buildingIdsIn, popularNameContains, sortKey, sortOrder, page, perPage);
            return localVarResponse.Data;
        }

We have not changed any settings or anything else aside from the version bump.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file, OpenAPI document, or test is named. Reproduce the supplied generic C# model with .NET 8 and compare generated signatures across generator versions, then trace nullable type handling in the C# generator. Done when nullable annotations are preserved and the regression is covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.