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 Content-Type [Headers] #619

Merged
merged 7 commits into from
Feb 26, 2025

Conversation

christianhelle
Copy link
Owner

@christianhelle christianhelle commented Feb 25, 2025

This resolves #617

This pull request includes several changes to enhance the header generation functionality in the Refitter.Core project. The key changes involve renaming methods to reflect their purpose better, adding support for generating Content-Type headers, and updating tests to verify the new functionality.

With the changes in the pull request, the following OpenAPI document:

openapi: 3.0.1
paths:
  /foo:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: string
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                type: string

Generate the following Refit interface:

public partial interface IApiClient
{
    [Headers("Accept: application/json", "Content-Type: application/json")]
    [Post("/foo")]
    Task<string> Foo([Body] string body);
}

Header Generation Enhancements:

  • Renamed the GenerateAcceptHeaders method to GenerateHeaders and added logic to generate Content-Type headers if specified in the settings. [1] [2] [3] [4] [5] [6] [7] [8]

  • Added a new property AddContentTypeHeaders to the RefitGeneratorSettings class to control the generation of Content-Type headers.

Test Updates:

  • Updated existing tests in src/Refitter.SourceGenerator.Tests/CustomGenerated/CustomGenerated.cs to include Content-Type headers in the Headers attribute. [1] [2] [3] [4] [5] [6]

  • Added new test classes RequestResponseHeadersTests and ResponseHeadersTests to verify the generation of Accept and Content-Type headers. [1] [2]

  • Modified tests in src/Refitter.Tests/SwaggerPetstoreApizrTests.cs and src/Refitter.Tests/SwaggerPetstoreTests.cs to validate the presence or absence of Accept headers based on the OpenAPI specification version. [1] [2]

@christianhelle christianhelle added the enhancement New feature, bug fix, or request label Feb 25, 2025
@christianhelle christianhelle self-assigned this Feb 25, 2025
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.60%. Comparing base (125b398) to head (fd62613).
Report is 19 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #619       +/-   ##
===========================================
- Coverage   98.97%   85.60%   -13.38%     
===========================================
  Files          55       56        +1     
  Lines        2639     3195      +556     
===========================================
+ Hits         2612     2735      +123     
- Misses          4      419      +415     
- Partials       23       41       +18     
Flag Coverage Δ
unittests 85.60% <100.00%> (-13.38%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@christianhelle
Copy link
Owner Author

@all-contributors please add @Metziell for bugs

Copy link
Contributor

@christianhelle

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

@christianhelle christianhelle changed the title Fix missing content type headers Fix missing Content-Type [Headers] Feb 26, 2025
@christianhelle christianhelle merged commit c3bf4f1 into main Feb 26, 2025
9 of 10 checks passed
@christianhelle christianhelle deleted the fix-missing-content-type-headers branch February 26, 2025 18:38
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.

Doesn't add Content-Type request header when body is plain JSON string
1 participant