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

Generate Multiple interfaces based on first Tag #95

Merged
merged 2 commits into from
Aug 6, 2023

Conversation

kirides
Copy link
Contributor

@kirides kirides commented Aug 5, 2023

This PR adds an additional mode for --multiple-interfaces called ByTag which uses the first Tag of the operation to generate the interface name.

This PR also adds a BREAKING change as --multiple-interfaces now takes in an enumeration of Unset, ByEndpoint and ByTag.
The source generator .refitter file has the same breaking change, as it now takes its value as string like this:

{
  "multipleInterfaces": "ByTag" // or ByEndpoint
}

Generated sample:

namespace GeneratedCode
{
    // No/Empty first Tag 
    public interface IDocumentV1Api
    {
        [Get("/api/greet-unsafe")]
        Task GreetUnsafe([Query] string name);
    }

    // tag "Greeting"
    public interface IGreetingApi
    {
        [Get("/api/greet")]
        Task Greet([Query] string name);
    }

    // tag "OpenApi"
    public interface IOpenApiApi
    {
        [Get("/api/custom-docs")]
        Task<ICollection<Item>> CustomDocs([Query] string name);

        [Get("/api/some-other-thing")]
        Task<ICollection<Item>> SomeOtherThing([Query] string name);
    }


}

spec:

openapi: 3.0.1
# ...
info:
  title: Document V1
paths:
  /api/greet-unsafe:
    get:
      tags:
        - ''
      parameters:...
      responses:
        '200':...
  /api/greet:
    get:
      tags:
        - Greeting
      parameters:...
      responses:...
  /api/custom-docs:
    get:
      tags:
        - OpenApi
      parameters:...
      responses:
        '200':...
  /api/some-other-thing:
    get:
      tags:
        - OpenApi
      parameters:...
      responses:
        '200':...

@christianhelle christianhelle self-assigned this Aug 5, 2023
@christianhelle christianhelle added the enhancement New feature, bug fix, or request label Aug 5, 2023
@christianhelle
Copy link
Owner

@kirides this is some very good stuff! I don't mind the breaking change since as far as I know, I'm the only one using --multiple-interfaces but we should update the source generator README

@christianhelle
Copy link
Owner

@all-contributors please add @kirides for code

@allcontributors
Copy link
Contributor

@christianhelle

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

Copy link
Owner

@christianhelle christianhelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirides The builds are failing because --multiple-interfaces is now expecting an extra argument

Can I ask you to update line 60 in the file .github\workflows\template.yml to

${{ inputs.command }} ./openapi.${{ inputs.format }} --namespace "$namespace.MultipleInterfaces" --output "MultipleInterfaces$outputPath" --multiple-interfaces ByEndpoint --no-logging

and line 116-119 in the file test\smoke-tests.ps1 to:

Write-Host "dotnet run --project ../src/Refitter/Refitter.csproj ./openapi.$format --namespace $namespace.MultipleInterfaces --output ./GeneratedCode/MultipleInterfaces$outputPath --multiple-interfaces ByEndpoint --no-logging"
$process = Start-Process "dotnet" `
    -Args "run --project ../src/Refitter/Refitter.csproj ./openapi.$format --namespace $namespace.MultipleInterfaces --output ./GeneratedCode/MultipleInterfaces$outputPath --multiple-interfaces ByEndpoint --no-logging" `
    -NoNewWindow `
    -PassThru

Copy link
Owner

@christianhelle christianhelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirides if its not too much trouble, please update src\Refitter.SourceGenerator\README.md so the example .refitter file and explanations match the proposed changes

@kirides
Copy link
Contributor Author

kirides commented Aug 6, 2023

Sure will do those things.
Just gotta get on to a PC :)

@christianhelle
Copy link
Owner

@kirides thanks!

Remember to enjoy the weekend first 😄

@christianhelle christianhelle merged commit e0c7b27 into christianhelle:main Aug 6, 2023
@christianhelle
Copy link
Owner

This feature is now released to NuGet as v0.7.2

@kirides kirides deleted the feat/interfaces_by_tag branch August 7, 2023 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants