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

Fix missing support for Query Parameters #6

Merged
merged 10 commits into from
Mar 14, 2023
Merged

Conversation

christianhelle
Copy link
Owner

@christianhelle christianhelle commented Mar 14, 2023

The changes here add's the missing Query parameters support in the generated Refit interface

Endpoints that use query parameters will be generated like this:

[Get("/pet/findByStatus")]
Task<ICollection<Pet>> FindPetsByStatus([Query]Status? status);

[Get("/pet/findByTags")]
Task<ICollection<Pet>> FindPetsByTags([Query(CollectionFormat.Multi)]ICollection<string> tags);

This was verified using the Swagger Petstore v3 OpenAPI specifications and tested using the following code:

var client = RestService.For<ISwaggerPetstore>("https://petstore3.swagger.io/api/v3");
var pet = await client.GetPetById(2);

Console.WriteLine($"Name: {pet.Name}");
Console.WriteLine($"Category: {pet.Category.Name}");
Console.WriteLine($"Status: {pet.Status}");

var pets = await client.FindPetsByStatus(Status.Available);
Console.WriteLine("Found " + pets.Count + " available pet(s)");        

var taggedPets = await client.FindPetsByTags(new[] {"tag1Updated", "new"});
Console.WriteLine("Found " + taggedPets.Count + " tagged pet(s)");

Which when executed returns the following text:

Name: Gatitotototo
Category: Chaucito
Status: Sold
Found 44 available pet(s)
Found 9 tagged pet(s)

This resolves #5

@christianhelle christianhelle added the bug Something isn't working label Mar 14, 2023
@christianhelle christianhelle self-assigned this Mar 14, 2023
@christianhelle christianhelle merged commit 82e10b4 into main Mar 14, 2023
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

Successfully merging this pull request may close these issues.

Parameters from the query do not add into the resulting interface
1 participant