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

Unable to change arrayType to List or IList #255

Closed
LunaWanderer1 opened this issue Dec 20, 2023 · 9 comments · Fixed by #257
Closed

Unable to change arrayType to List or IList #255

LunaWanderer1 opened this issue Dec 20, 2023 · 9 comments · Fixed by #257
Assignees
Labels
bug Something isn't working

Comments

@LunaWanderer1
Copy link

LunaWanderer1 commented Dec 20, 2023

Describe the bug
When putting arrayType to 'System.Collections.Generic.List' or 'System.Collections.Generic.IList', it stays as ICollection.

OpenAPI Specifications
Here is an example of the one that is failing:

 "/Auth/domains": {
   "get": {
     "tags": [
       "Auth"
     ],
     "responses": {
       "200": {
         "description": "Success",
         "content": {
           "text/plain": {
             "schema": {
               "type": "array",
               "items": {
                 "type": "string"
               }
             }
           },
           "application/json": {
             "schema": {
               "type": "array",
               "items": {
                 "type": "string"
               }
             }
           },
           "text/json": {
             "schema": {
               "type": "array",
               "items": {
                 "type": "string"
               }
             }
           }
         }
       }
     }
   }
 },

Additional context

Ran using: dotnet refitter --skip-validation --settings-file openapi.json

refitterconfig looks like this:


{
	"openApiPath": "swagger.json",
	"namespace": "DotNetApp",
	"naming": {
		"useOpenApiTitle": false,
		"interfaceName": "ApiClient"
	},
	"contractsGeneratorSettings": {
		"arrayType": "System.Collections.Generic.List"
	},
	"returnIApiResponse": true
}

@LunaWanderer1 LunaWanderer1 added the bug Something isn't working label Dec 20, 2023
@christianhelle
Copy link
Owner

@eliyammine thanks for taking the time to report this

Let me see what I can do

By the way, do you have a support key?

@christianhelle
Copy link
Owner

@eliyammine one quick thing I noticed in your .refitter config file is that you are using contractsGeneratorSettings instead of codeGeneratorSettings. Can you try out using codeGeneratorSettings ?

@LunaWanderer1
Copy link
Author

Hi,

My support key is aurkbqh. I tried with codeGeneratorSettings both with IList and List and no luck

@christianhelle
Copy link
Owner

You're right @eliyammine. It seems that in the Refit interface, arrays are generated as ICollection<T>. The generated contracts seem to be correct and use IList

I'll see what I can do...

@christianhelle
Copy link
Owner

@all-contributors please add @eliyammine for bugs

Copy link
Contributor

@christianhelle

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

@christianhelle
Copy link
Owner

@eliyammine I have a fix for arrayType in the Refit interface that I will merge in.

I will try resolve all the other codeGeneratorSettings return type settings over the Christmas holidays

@christianhelle
Copy link
Owner

@eliyammine I published a pre-release version to NuGet

dotnet tool install --global Refitter --version 0.8.7.40-preview

that contains a fix for this specific problem.

I bumped the target framework to .NET 8.0 since it is now the new recommended LTS version and because .NET 6.0 is going out of support soon

@LunaWanderer1
Copy link
Author

Thank you for the quick fix! Worked perfectly

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
2 participants