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

Add support for generating multiple files with OpenAPI Generator #886

Merged
merged 5 commits into from
May 6, 2024

Conversation

christianhelle
Copy link
Owner

@christianhelle christianhelle commented May 6, 2024

PR Classification

This pull request introduces a new feature that allows the generation of multiple files in the OpenApi C# generator.

PR Summary

The pull request adds a GenerateMultipleFiles option to the OpenApi C# generator, which can either copy source files to a destination directory and delete the source directory, or merge the source files, sanitize the merged file, and prefix it with an autogenerated code header.

  • OpenApiCSharpGeneratorCommand.cs and OpenApiCSharpCodeGenerator.cs have been updated to handle the new GenerateMultipleFiles option.
  • A new method CopyFilesAndDeleteSource has been added to CSharpFileMerger.cs to support the new feature.
  • The GenerateMultipleFiles property has been added to DefaultOpenApiGeneratorOptions.cs, IOpenApiGeneratorOptions.cs, OpenApiGeneratorOptions.cs, and OpenApiGeneratorOptionsPage.cs.
  • The GenerateMultipleFiles property value is now included in OpenApiGeneratorOptions.cs.

Screenshot

image

image

Removed unused `System.Diagnostics` namespace from `CSharpFileMerger.cs`. Enhanced logging in `MergeFiles` method to include details such as file count, names, and merged source code size. Updated `MergeFilesAndDeleteSource` method to suppress nullable reference warnings. Added `CopyFilesAndDeleteSource` method to copy all files/directories from input to output directory and delete the input directory. Also introduced a helper method `CopyFolder` for recursive file and directory copying.
@christianhelle christianhelle linked an issue May 6, 2024 that may be closed by this pull request
@christianhelle christianhelle self-assigned this May 6, 2024
@christianhelle christianhelle added enhancement New feature or request .NET Pull requests that update .net code labels May 6, 2024
@christianhelle
Copy link
Owner Author

@kipusoep Is something like this interesting for you (see PR description)? I had someone request this to me at some point but I never got around to building it. I have a cold and have been sitting on the couch coding all day so I thought I could clean up the old backlog on my open-source projects

@kipusoep
Copy link

kipusoep commented May 6, 2024

@kipusoep Is something like this interesting for you (see PR description)? I had someone request this to me at some point but I never got around to building it. I have a cold and have been sitting on the couch coding all day so I thought I could clean up the old backlog on my open-source projects

I'm not sure what the context is? Interesting for what exactly? :-)

Copy link

sonarcloud bot commented May 6, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
11.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@christianhelle
Copy link
Owner Author

I'm not sure what the context is? Interesting for what exactly? :-)

@kipusoep Generating multiple files instead of a single large code-behind file when using OpenAPI Generator. The output in this PR allows for a more understandable diff when re-generating code

@christianhelle
Copy link
Owner Author

@kipusoep the screenshot in the description shows the output of generating code based on the Swagger Petstore v3 spec using OpenAPI Generator v7.5.0 from this extension

@kipusoep
Copy link

kipusoep commented May 6, 2024

Sounds good, but I'm still not sure what it's got to do with me specifically 😅

@christianhelle
Copy link
Owner Author

Sounds good, but I'm still not sure what it's got to do with me specifically 😅

LOL, I was pretty sure that you requested the feature but it seems I remembered wrong 😑

@christianhelle christianhelle merged commit 549975c into master May 6, 2024
46 of 47 checks passed
@christianhelle christianhelle deleted the openapi-generator-multiple-files-output branch May 6, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request .NET Pull requests that update .net code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement option for generating multiple files
2 participants