OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.51k stars 6.27k forks source link

[BUG] Description #19017

Open famattsson opened 3 days ago

famattsson commented 3 days ago

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.