christianhelle / httpgenerator

Generate .http files from OpenAPI (Swagger) specifications
MIT License
86 stars 6 forks source link

Add support for generating IntelliJ HTTP client tests #147

Closed christianhelle closed 1 month ago

christianhelle commented 1 month ago

This pull request introduces a new feature to generate IntelliJ tests, along with updates to the documentation and tests to support this feature. The most important changes include adding the --generate-intellij-tests option, updating the generator settings, and ensuring the generated code includes IntelliJ test assertions.

Sample generated code using --generate-intellij-tests

@contentType = application/json

#######################################
### Request: GET /pet/{petId}
### Summary: Find pet by ID
### Description: Returns a single pet
#######################################

### Path Parameter: ID of pet to return
@petId = 1

GET https://petstore3.swagger.io/api/v3/pet/{{petId}}
Content-Type: {{contentType}}

> {%
    client.test("Request executed successfully", function() {
        client.assert(
            response.status === 200, 
            "Response status is not 200");
    });
%}

Screenshot of running test from IntelliJ

In this screenshot there are 2 requests made, one returns 200 (OK) and the other returns 404 (NotFound) image

New Feature: IntelliJ Test Generation

Documentation Updates

Test Enhancements

Command Updates

Miscellaneous

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 75.24%. Comparing base (be35257) to head (04ecf70). Report is 12 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #147 +/- ## ========================================== + Coverage 67.14% 75.24% +8.09% ========================================== Files 9 9 Lines 350 311 -39 ========================================== - Hits 235 234 -1 + Misses 101 63 -38 Partials 14 14 ``` | [Flag](https://app.codecov.io/gh/christianhelle/httpgenerator/pull/147/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Christian+Helle) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/christianhelle/httpgenerator/pull/147/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Christian+Helle) | `75.24% <100.00%> (+8.09%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Christian+Helle#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.