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(api): return proper json objects #3544

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ReenigneArcher
Copy link
Member

@ReenigneArcher ReenigneArcher commented Jan 17, 2025

Description

The API currently returns strings for boolean and int values. This PR changes that to return proper JSON objects.

Before:

{
    "status_code": "400",
    "status": "false",
    "error": "'index' out of range, max index is 1"
}

After:

{"error":"'index' out of range, max index is 1","status":false,"status_code":400}

TODO:

  • add nlohmann::json to unix builds
  • Test all endpoints
  • Ensure anything in UI using boolean/integer values from the API continues to work properly
  • Ensure API docs accurately reflect updated return types
  • option to return pretty/indented json

Test Results:

$ curl -u user:pass -X GET -k https://localhost:47990/api/apps
{"apps":[{"image-path":"desktop.png","name":"Desktop"},{"auto-detach":true,"cmd":"steam://open/bigpicture","image-path":"steam.png","name":"Steam Big Picture","wait-all":true}],"env":{}}

$ curl -u user:pass -X DELETE -k https://localhost:47990/api/apps/9999
{"error":"'index' out of range, max index is 1","status":false,"status_code":400}

$ curl -u user:pass -X DELETE -k https://localhost:47990/api/apps/1
{"result":"application 1 deleted","status":true}

$ curl -u user:pass -X DELETE -k https://localhost:47990/api/apps/1
{"error":"'index' out of range, max index is 0","status":false,"status_code":400}

$ curl -u user:pass -X GET -k https://localhost:47990/api/apps
{"apps":[{"image-path":"desktop.png","name":"Desktop"}],"env":{}}

$ curl -u user:pass -X POST -k https://localhost:47990/api/apps -d "{\"name\":\"test\",\"elevated\":true,\"exit-timeout\":10}"
{"error":"[json.exception.type_error.302] type must be number, but is null","status":false,"status_code":400}

$ curl -u user:pass -X POST -k https://localhost:47990/api/apps -d "{\"name\":\"test\",\"elevated\":true,\"exit-timeout\":10,\"index\":-1}"
{"status":true}

$ curl -u user:pass -X GET -k https://localhost:47990/api/apps
{"apps":[{"image-path":"desktop.png","name":"Desktop"},{"auto-detach":true,"cmd":"steam://open/bigpicture","image-path":"steam.png","name":"Steam Big Picture","wait-all":true},{"elevated":true,"exit-timeout":10,"name":"test"}],"env":{}}

Screenshot

Issues Fixed or Closed

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 0% with 103 lines in your changes missing coverage. Please review.

Project coverage is 10.30%. Comparing base (bc22cca) to head (1fc5888).

Files with missing lines Patch % Lines
src/confighttp.cpp 0.00% 98 Missing ⚠️
src/nvhttp.cpp 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3544      +/-   ##
==========================================
+ Coverage   10.28%   10.30%   +0.01%     
==========================================
  Files          90       90              
  Lines       16152    16128      -24     
  Branches     7667     7636      -31     
==========================================
  Hits         1662     1662              
- Misses      11930    13910    +1980     
+ Partials     2560      556    -2004     
Flag Coverage Δ
Linux 9.68% <0.00%> (+0.02%) ⬆️
Windows 10.77% <0.00%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
src/nvhttp.cpp 0.00% <0.00%> (ø)
src/confighttp.cpp 0.00% <0.00%> (ø)

... and 31 files with indirect coverage changes

@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch from 3faf6b4 to 30e4404 Compare January 17, 2025 20:01
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch from 30e4404 to 1fc5888 Compare January 17, 2025 20:35
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
6 New issues
6 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant