Repository navigation
openapi: decode ErrorRS.errorCode as an integer - #33
Open
DzmitryHumianiuk wants to merge 1 commit into
Open
DzmitryHumianiuk wants to merge 1 commit into
DzmitryHumianiuk wants to merge 1 commit into
Conversation
ReportPortal writes ErrorRS.errorCode as a number (ErrorTypeSerializer calls writeNumber(error.getCode())), but the upstream spec declares it as a string enum. The generated client therefore failed to decode every error response declared as ErrorRS and returned "json: cannot unmarshal number into Go struct field ...errorCode of type string" instead of the HTTP status and the server's error model. Override the property in scripts/openapi-preprocess.jq (integer/int64, same as the spec's own Error schema) and regenerate the client. The filter now fails if the schema or property disappears upstream. GetErrorCode/SetErrorCode/GetErrorCodeOk of ComEpamReportportalBaseInfrastructureRulesExceptionErrorRS change from string to int64. Fixes #31 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 27, 2026
Member
Author
|
Note for merging: #33 and #34 conflict at the type level. #34's generated test pins |
This was referenced Nov 27, 2026
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.
Summary
Fixes #28. Fixes #31 (a duplicate of #28 with a corrected reproduction).
ReportPortal sends
errorCodein error responses as a number ({"errorCode":4041,"message":"..."}), but the API spec declares it as a string enum. The generatedpkg/openapiclient therefore failed to decode error responses and returnedjson: cannot unmarshal number into Go struct field ...ErrorRS.errorCode of type stringinstead of the HTTP status and the server's error.This PR declares
errorCodeas an integer in the spec preprocessing step and regenerates the client.Changes
scripts/openapi-preprocess.jq: replaceErrorRS.errorCode(string enum) withinteger/int64, the same type the spec's ownErrorschema already uses. The filter stops with an error if the schema or the property disappears upstream, so the override cannot silently go stale.pkg/openapi/(regenerated, not hand-edited):ErrorRS.ErrorCodeis now*int64. Only two generated files change: the model and the embeddedapi/openapi.yaml.pkg/gorp/openapi_errors_test.go: newhttptesttest that returns real error bodies and checks the code and message the caller gets through the generated client.Behaviour change for library users
GetErrorCode(),GetErrorCodeOk()andSetErrorCode()ofopenapi.ComEpamReportportalBaseInfrastructureRulesExceptionErrorRSchange fromstringtoint64. The string version could never hold a value from a real server, so no working code depends on it.Not changed, found on the way
err.Error()is now the HTTP status (404 Not Found), not the server message. The generator only putsTitle/Detailfields into the text (pkg/openapi/client.go,formatErrorMessage). The code and message are inGenericOpenAPIError.Model(), and the raw body is inBody().Model()is nil and the caller has to decodeBody()itself. "Get a launch that doesn't exist" was never hit by the decode bug for this reason; the bug shows on statuses the spec declares (400, 403, 500, and 404 where declared).oneOf(ErrorRS, string), but the server sends an OAuth body ({"error":"invalid_token","error_description":"Invalid access token"}). Worth a separate issue.task generate-openapi-clientalone leaves 372 files modified, because the committed client isgo fmt-formatted and the task does not format its output. Runninggo fmt ./pkg/openapi/(ortask fmt) afterwards brings the diff to zero. This is not documented inAGENTS.md..task/checksum/preprocess-schemais tracked in git although.task/is in.gitignore. It changes whenever the jq filter changes. It is left untouched here.pkg/gorpandinternal/do not decodeerrorCodeanywhere.defaultHTTPErrorHandler(pkg/gorp/util.go:12) keeps the raw body as a string, so the Resty-based clients were not affected.@Schemaannotation onErrorRS.errorType). Once it is, the override becomes a no-op.Investigation log
Paths in service-api refer to
developat017642e9e. Commands run from the repository root unless noted.Symptom. e2e cleanup on ReportPortal 6.0.0 printed
cleanup: could not delete launch 80: json: cannot unmarshal number into Go struct field ComEpamReportportalBaseInfrastructureRulesExceptionErrorRS.errorCode of type string(issue openapi: error responses can't be decoded (errorCode is a number, spec says string) #31).Spec says string.
jq '.components.schemas["com.epam.reportportal.base.infrastructure.rules.exception.ErrorRS"].properties.errorCode | {type, enum_values: (.enum|length)}' reportportal-api-docs.jsonreturns
{"type":"string","enum_values":97}.The generated model had
ErrorCode *string(git show origin/master:pkg/openapi/model_com_epam_reportportal_base_infrastructure_rules_exception_error_rs.go, line 23).Server writes a number. In service-api,
src/main/java/com/epam/reportportal/base/infrastructure/rules/exception/ErrorRS.java:@JsonSerialize(using = ErrorTypeSerializer.class)on theerrorCodeproperty;ErrorTypeSerializer.serializecallsjsonGenerator.writeNumber(error.getCode()).Codes are in
ErrorType.javain the same package:LAUNCH_NOT_FOUND(4041, ...)at line 73,ACTIVITY_NOT_FOUND(40411, ...)at line 136,INCORRECT_SORTING_PARAMETERS(40012, ...)at line 250,UNCLASSIFIED_ERROR(5000, ...)at line 593.Other error-like schemas.
jq -c '.components.schemas | to_entries[] | select(.value.properties.errorCode != null) | {k: .key, type: .value.properties.errorCode.type}' reportportal-api-docs.jsonlists two schemas:
ErrorRS(string, wrong) andError(integer/int64, already right).DeleteBulkRS.errorsrefers toErrorRSand is fixed with it. The 401oneOf(ErrorRS, string)also refers to it, so itsErrorRSbranch now accepts a numeric code, but real 401 responses still do not decode (see "Not changed" above and the last block of step 9). TheBatch*OperationErrorschemas have noerrorCode.Which responses reach the broken decode.
grep -n -A1 "StatusCode == 404" pkg/openapi/api_*.go | grep "var v"shows 404 is declared for 54 operations;grep -c "StatusCode == 404" pkg/openapi/api_launch.goreturns 0. So a missing launch (404) is returned without a model, and the decode error appears on declared statuses, such as the 500 in the issue.Fix choice. Override the schema in
scripts/openapi-preprocess.jq(lines 31-47) and regenerate, asAGENTS.mdrequires. Rejected alternatives:pkg/openapiby hand: the next regeneration would undo it;reportportal-api-docs.json: it is an upstream snapshot and the next refresh would undo it;int32: enough for today's codes, butint64matches the spec's ownError.errorCode;Regeneration. Docker was not running; started it with
colima start.taskis not installed, so it was run asgo run github.com/go-task/task/v3/cmd/task@v3.45.4 <task>.task generate-openapi-client, thengit status --shortshowed 372 modified files; aftergo fmt ./pkg/openapi/the diff was empty. So the noise is formatting only.task generate-openapi-client && go fmt ./pkg/openapi/, thengit status --shortshowspkg/openapi/api/openapi.yaml, theErrorRSmodel, and the tracked.task/checksum/preprocess-schema(restored withgit checkout).jq -c '.components.schemas["com.epam.reportportal.base.infrastructure.rules.exception.ErrorRS"].properties.errorCode' openapi-modified.jsonreturns{"type":"integer","format":"int64","description":"..."}.Test.
go test -count=1 -run TestOpenAPIClientDecodesErrorResponse -v ./pkg/gorp/passes with four cases: launch not found (404, not declared, so decoded fromBody(); the test also accepts a model, in case a later spec declares 404), activity not found (404, declared), wrong sort field (400, declared), delete launch failure (500, declared, the case from the issue).To see it fail without the fix:
git checkout origin/master -- pkg/openapi/model_com_epam_reportportal_base_infrastructure_rules_exception_error_rs.go, run the test (all four cases fail with thecannot unmarshal numbertext), thengit checkout HEAD -- <same file>.Live check, read-only (the demo instance from the issue, reported there as 6.0.0; the server version was not re-checked. Three GET requests for objects that do not exist, plus one GET with an invalid key after the fix. Nothing was created or deleted.) A throwaway program (not committed) built
gorp.NewClient(...)fromRP_ENDPOINT/RP_PROJECT/RP_API_KEYand printederr.Error(),GenericOpenAPIError.Body()andModel()for:c.LaunchAPI.GetLaunch(ctx, "999999999", project).Execute()c.ActivityAPI.GetActivity(ctx, 999999999, project).Execute()c.LaunchAPI.GetProjectLaunches(ctx, project).PageSort("noSuchField,asc").PageSize(1).Execute()Before the fix (
origin/master):After the fix:
Checks.
go build ./...,go vet ./...,go test -count=1 -cover ./...(all pass;pkg/gorp94.1%,internal/commands77.5%),task fmt,task lint(0 issues.).task e2ewas not run: it creates and deletes launches on the server, and this change does not alter what is sent to ReportPortal.🤖 Generated with Claude Code