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 parameters' casing in openAPI document are not honoured in Refit interface methods #125

Merged
merged 3 commits into from
Aug 24, 2023

Conversation

christianhelle
Copy link
Owner

The changes here fixes a case sensitivity issue regarding handling query string parameters.

This resolves #124

The follow OpenAPI spec:

openapi: '3.0.0'
paths:
  /job/{Id}:
    post:
      tags:
      - 'Jobs'
      operationId: 'Update job details'
      description: 'Update the details of the specified job.'
      parameters:
        - in: 'path'
          name: 'Id'
          description: 'Foo Id'
          required: true
          schema:
            type: 'string'
        - in: 'query'
          name: 'Title'
          description: 'Job title'
          required: true
          schema:
            type: 'string'
        - in: 'query'
          name: 'Description'
          description: 'Job description'
          required: true
          schema:
            type: 'string'
      responses:
        '200':
          description: 'successful operation'

Generates the following:

[Post("/job/{Id}")]
Task UpdateJobDetails(
    [AliasAs("Id")] string id, 
    [Query, AliasAs("Title")] string title, 
    [Query, AliasAs("Description")] string description);

And

openapi: '3.0.0'
paths:
  /job/{id}:
    post:
      tags:
      - 'Jobs'
      operationId: 'Update job details'
      description: 'Update the details of the specified job.'
      parameters:
        - in: 'path'
          name: 'id'
          description: 'Foo Id'
          required: true
          schema:
            type: 'string'
        - in: 'query'
          name: 'title'
          description: 'Job title'
          required: true
          schema:
            type: 'string'
        - in: 'query'
          name: 'description'
          description: 'Job description'
          required: true
          schema:
            type: 'string'
      responses:
        '200':
          description: 'successful operation'

Generates the following:

[Post("/job/{id}")]
Task UpdateJobDetails(string id, [Query] string title, [Query] string description);

Changed the string comparison method in GetAliasAsAttribute function from case-insensitive to default in ParameterExtractor.cs. This is to match the exact case of the parameter's name and variable's name for reliable alias mapping.
New unit test file created to validate case sensitivity of parameters in Refitter core. This ensures correct generation of code with respect to case sensitive query parameters. The tests also verify the successful build of the generated code.
@christianhelle christianhelle added the enhancement New feature, bug fix, or request label Aug 23, 2023
@christianhelle christianhelle self-assigned this Aug 23, 2023
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Merging #125 (1ab4e51) into main (f5db96f) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #125      +/-   ##
==========================================
+ Coverage   98.25%   98.29%   +0.04%     
==========================================
  Files          31       32       +1     
  Lines         972      997      +25     
==========================================
+ Hits          955      980      +25     
  Misses          6        6              
  Partials       11       11              
Flag Coverage Δ
unittests 98.29% <100.00%> (+0.04%) ⬆️

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

Files Changed Coverage Δ
src/Refitter.Core/ParameterExtractor.cs 97.82% <100.00%> (ø)
...ter.Tests/Examples/CaseSensitiveParametersTests.cs 100.00% <100.00%> (ø)

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@christianhelle christianhelle merged commit 2eb8a11 into main Aug 24, 2023
@christianhelle christianhelle deleted the query-parameters-aliasas branch August 24, 2023 07:08
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.

Parameters' casing in openAPI document are not honoured in Refit interface methods
1 participant