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

Merged
merged 1 commit into from
Feb 1, 2025

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}

Additionally, since we're now able to properly parse JSON properly, we can get rid of the extra JSON stringification in src_assets/common/assets/web/config.html. There might be more in here that can be removed/simplified?

TODO:

  • add nlohmann::json to unix builds
  • Test endpoints (results below)
  • Ensure anything in UI using boolean/integer values from the API continues to work properly
  • Ensure API docs accurately reflect updated return types

Test Results:

# get apps
$ 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":{}}

# delete an app that doesn't exist
$ 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}

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

# delete an app that doesn't exist
$ 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}

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

# not providing any index
$ 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}

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

# get apps
$ 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":{}}

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

# get config, when all settings are blank
$ curl -u user:pass -X GET -k https://localhost:47990/api/config
{"platform":"windows","status":true,"version":"0.0.0.30e44041"}

# get config locale setting (no authentication needed)
$ curl -X GET -k https://localhost:47990/api/configLocale
{"locale":"en","status":true}

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 204 lines in your changes missing coverage. Please review.

Project coverage is 11.62%. Comparing base (5b36357) to head (08e6aeb).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/confighttp.cpp 0.00% 56 Missing and 139 partials ⚠️
src/nvhttp.cpp 0.00% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           master    #3544     +/-   ##
=========================================
  Coverage   11.62%   11.62%             
=========================================
  Files          93       93             
  Lines       17321    17319      -2     
  Branches     8093     8085      -8     
=========================================
  Hits         2014     2014             
+ Misses      14713    12823   -1890     
- Partials      594     2482   +1888     
Flag Coverage Δ
Linux 11.30% <0.00%> (+<0.01%) ⬆️
Windows 13.04% <0.00%> (+<0.01%) ⬆️

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

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

... and 29 files with indirect coverage changes

@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch 3 times, most recently from 1fc5888 to a461b46 Compare January 17, 2025 22:05
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch from a461b46 to c092482 Compare January 17, 2025 22:28
@ReenigneArcher ReenigneArcher added this to the stable release milestone Jan 23, 2025
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch 8 times, most recently from bacfe09 to f98a116 Compare January 23, 2025 23:16
@ReenigneArcher ReenigneArcher marked this pull request as ready for review January 23, 2025 23:22
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch from f98a116 to b3a2da8 Compare January 23, 2025 23:24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 6 out of 18 changed files in this pull request and generated no comments.

Files not reviewed (12)
  • cmake/compile_definitions/common.cmake: Language not supported
  • cmake/compile_definitions/windows.cmake: Language not supported
  • cmake/dependencies/common.cmake: Language not supported
  • cmake/dependencies/nlohmann_json.cmake: Language not supported
  • cmake/dependencies/windows.cmake: Language not supported
  • src/nvhttp.cpp: Language not supported
  • src/nvhttp.h: Language not supported
  • src_assets/common/assets/web/apps.html: Language not supported
  • src_assets/common/assets/web/config.html: Language not supported
  • src_assets/common/assets/web/public/assets/locale/en.json: Language not supported
  • src_assets/windows/assets/apps.json: Language not supported
  • src_assets/common/assets/web/configs/tabs/encoders/NvidiaNvencEncoder.vue: Evaluated as low risk
Comments suppressed due to low confidence (1)

docs/app_examples.md:302

  • The word 'UAC' should be 'UAC prompt'.
UAC prompt.
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch from b3a2da8 to d18e12e Compare January 24, 2025 22:07
docs/building.md Show resolved Hide resolved
src/confighttp.cpp Outdated Show resolved Hide resolved
src/confighttp.cpp Outdated Show resolved Hide resolved
src/confighttp.cpp Outdated Show resolved Hide resolved
src/confighttp.cpp Outdated Show resolved Hide resolved
src/confighttp.cpp Outdated Show resolved Hide resolved
src/nvhttp.cpp Outdated Show resolved Hide resolved
src_assets/common/assets/web/config.html Show resolved Hide resolved
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch 2 times, most recently from a99a0d3 to 09773ef Compare January 27, 2025 02:05
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch 5 times, most recently from 8fbf22c to 624bb54 Compare January 27, 2025 19:19
src/nvhttp.h Outdated Show resolved Hide resolved
src_assets/common/assets/web/config.html Show resolved Hide resolved
src/confighttp.cpp Outdated Show resolved Hide resolved
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch 2 times, most recently from 34bc6dc to 5d30c47 Compare January 31, 2025 04:14
@ReenigneArcher ReenigneArcher force-pushed the fix/api/return-proper-json-objects branch from 5d30c47 to 08e6aeb Compare February 1, 2025 03:46
Copy link

sonarqubecloud bot commented Feb 1, 2025

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

@ReenigneArcher ReenigneArcher merged commit 257a102 into master Feb 1, 2025
34 of 37 checks passed
@ReenigneArcher ReenigneArcher deleted the fix/api/return-proper-json-objects branch February 1, 2025 04:38
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.

2 participants