Repository navigation
Add the endpoint definition layer and request bodies (T13, T13d) - #12
Merged
Merged
Conversation
A definition carries everything the generic executor needs for one endpoint: the wire contract, the request and response types, and the three hooks D27 specifies. Send<Definition>() is the only entry point, and it returns the id the executor assigned. NormalizeResponse is optional. A definition with no endpoint-specific convenience should not have to write an empty one, so a SFINAE trait detects it and dispatches. The worked ListBroadcastsDef omits it, which is what proves the trait works. rom_json now returns Result<Empty> rather than �oid. A void decoder cannot report a missing field, which is the silent-default failure D23 exists to prevent. The spec is revised to match. LL-Version is pinned to 2021-03-01 rather than omitted: the backend defaults a missing header to that same value, so omitting it would silently opt every adopter into the oldest API version. Found while testing: Add(name, "literal") picked the �ool overload, because const char* to �ool is a standard conversion and to std::string is a user-defined one. Every string literal in a query string became rue. Fixed with an explicit const char* overload and verified by sabotage. There is no request body, and the spec has no hook for one. Every MVP endpoint is a GET, so this task is complete without it, but the gap is now recorded in the api-sketch and is T13c's first job. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved correctness issues remain in response handling, error metadata preservation, locale-independent query formatting, uint64_t parameter support, and decoder validation.
6 open issues
Handle 204 empty responses before parsing JSON · New Preserve transport metadata on JSON parse errors · New Format floating-point query values independently of locale · New Add a non-narrowing uint64_t query parameter overload · New Reject missing or non-string rank in the decoder · New Validate required fields in nested broadcast items · New
What changed in this PR
Adds the internal endpoint-definition layer for the SDK, connecting typed endpoint definitions and query construction to the existing executor while updating response decoding to report malformed data explicitly.
Changes:
- Added generic request construction, dispatch, URL and header helpers, response normalization, and ADL-based decoding.
- Added typed, insertion-ordered, percent-encoded query parameters with numeric formatting.
- Updated tests, build integration, and documentation for the Result-based decoder contract.
| File | Description |
|---|---|
| tests/test_definition.cpp | Adds tests for endpoint dispatch, request construction, response decoding, errors, headers, and query parameter serialization. |
| tests/CMakeLists.txt | Registers the endpoint-definition test target. |
| src/core/query_parameters.h | Declares typed, insertion-ordered query parameter storage and serialization. |
| src/core/query_parameters.cpp | Implements query parameter encoding and numeric formatting. |
| src/core/json.h | Adds the ADL-based Result JSON decoding contract. |
| src/core/definition.h | Defines endpoint metadata, request construction, response decoding, normalization, and executor dispatch. |
| README.md | Documents the updated Result-based custom decoder pattern. |
| CMakeLists.txt | Adds the query parameter implementation to the core library. |
Review effort: Lite
The definition layer had no way to send a body, which blocks guest auth and white-label login - both POST. The owner chose the hook shape: an ADL o_json on the request type, the same mechanism rom_json uses for responses, rather than a fourth hook on the definition. The reason is the nested optionals object that guest, Steam and PSN sessions all send. That type needs a o_json whichever way the outer body is built, so a ConstructBody hook would mean two mechanisms for one job. JsonBuilder is a new public type, deliberately separate from JsonValue. JsonValue is a path into a shared immutable document, which is what makes it cheap and safe to hold across a callback; making it writable would mean copying on every write or giving up that sharing. Send<Definition>() detects o_json with a trait. A request type without one sends no body and no Content-Type, so every existing GET definition is unchanged. When there is a body, Content-Type is set by the executor rather than by a definition. Two traps found while testing, both fixed and both verified by sabotage: - Set(key, "literal") picked the �ool overload, exactly as QueryParameters::Add did. Every string literal became rue. - ToJson() with nlohmann's default error handler aborts on invalid UTF-8, because a throw under JSON_NOEXCEPTION is an abort. A player name with a stray byte would have terminated the process. Now uses error_handler_t::replace. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kirre-bylund
commented
Nov 25, 2026
Owner findings: - is-development is not a default header. It is read only on the white-label login path, so it belongs in that definition's ConstructHeaders rather than on every request. - LL-SDK-Version and LL-Instance-Identifier were missing. The other SDKs send both and the backend's tracing middleware reads both, so without them every request is attributed to "unknown". The instance identifier is generated once per Client, so two clients in one process are distinguishable. Copilot findings: - A 204 was parsed as JSON, so EndSession - the one legitimate empty success - reported MalformedResponse. Handled before the parser, and NormalizeResponse still runs. - A decode failure replaced the whole error, losing the executor's request_id and status_code. Only the code and message are replaced now, so a malformed body still reports which request it was. - %g is governed by the process-wide C locale, so in a comma-decimal locale 1.5 became 1,5 and then 1%2C5 on the wire. The separator is normalised to '.' rather than calling setlocale, which would change global process state. - QueryParameters had no uint64 overload, so the call was ambiguous between int64_t and bool and a definition could not add an unsigned wire id at all. - The README's from_json example and the test's decoder both assigned AsString() without validating, so a missing field became an empty string - contradicting the contract the same PR documents. Verified by sabotage: removing the 204 branch fails two assertions, and dropping the locale normalisation produces ratio=1%2C5. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Implements T13 and T13d from
specs-library/specs/discipline/sdk/cpp-sdk/tasks.md.What this adds
src/core/definition.h—RawResponse, theHasNormalizeResponseandHasToJsontraits,BuildUrl,BuildDefaultHeaders,BuildBodyandSend<Definition>().src/core/query_parameters.{h,cpp}— typed, insertion-ordered, percent-encoded query parameters.include/lootlocker/json_builder.h— the write handle for request bodies.tests/test_definition.cpp— 18 test functions, including the workedListBroadcastsDefand a POST definition with a nested reused type.Verification
The task's stated check: the worked
ListBroadcastsDefcompiles and its typed wrapper returns the sameRequestIdthe executor assigned.TestTypedWrapperReturnsExecutorIdasserts exactly that, and also that nothing has been sent yet — the request is queued, not dispatched, untilUpdate().14/14 CTest targets pass with curl, 13/13 in the
-DLOOTLOCKER_MODULE_ONLY=coreconfiguration. Include boundary and module boundary both clean.Request bodies
You chose the ADL
to_jsonon the request type over aConstructBodyhook. The reason holds up in the code: the nestedoptionalsobject that guest, Steam and PSN sessions all send needs ato_jsonwhichever way the outer body is built, so a definition hook would have meant two mechanisms for one job.JsonBuilderis a separate type fromJsonValue, not a mutable one.JsonValueis a path into a shared immutable document, which is what makes it cheap and safe to hold across a callback; making it writable would mean copying on every write or giving up that sharing.Send<Definition>()detectsto_jsonwith a trait, so a request type without one sends no body and noContent-Type— every existing GET definition is unchanged. When there is a body,Content-Typeis set by the executor rather than by a definition, because a body without it is a request the server rejects and no definition should have to remember.Three bugs found while testing, all verified by sabotage
Set(key, "literal")picked thebooloverload.const char*toboolis a standard conversion and tostd::stringis a user-defined one, so every string literal silently becametrue. Exactly the same trapQueryParameters::Addhad. Fixed with an explicitconst char*overload.ToJson()aborted on invalid UTF-8. nlohmann's default error handler throws, and a throw underJSON_NOEXCEPTIONis an abort — so a player name with a stray byte would have terminated the process. Now useserror_handler_t::replace. Sabotaging it back to the default exits -1.NormalizeResponseis optional. The sketch shows it on every definition, but a definition with no endpoint-specific convenience should not have to write an empty one. A SFINAE trait detects it.ListBroadcastsDefomits it, which is what proves the trait works.Spec changes carried in lootlocker/index#1935
from_jsonreturnsResult<Empty>rather thanvoid— avoiddecoder cannot report a missing field, which is the silent-default failure D23 exists to prevent. The api-sketch's "Request bodies are not yet specified" section is replaced by the decision, and the sketchedto_json(JsonValue&, ...)is corrected toJsonBuilder&.