fix: report an error when the fetched openapi schema is not JSON - #6263
fix: report an error when the fetched openapi schema is not JSON#6263PragalvaXFREZ wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: PragalvaXFREZ The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @PragalvaXFREZ. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
printSchema runs kubectl get --raw /openapi/v2 and unmarshals stdout.
The json.Unmarshal error is discarded, not even assigned to _:
var jsonSchema map[string]interface{}
output := stdout.Bytes()
json.Unmarshal(output, &jsonSchema)
output, _ = json.MarshalIndent(jsonSchema, "", " ")
When kubectl succeeds but the response is not JSON, for example an auth
portal or corporate proxy returning HTML, jsonSchema is left nil,
MarshalIndent renders it as null, and the command prints that and exits
0:
$ kustomize openapi fetch
null
$ echo $?
0
The function already guards the two neighbouring failures, kubectl
exiting non-zero and empty stdout, and both reuse the errMsg advice.
Only "kubectl succeeded but returned something that is not a schema"
was unguarded, so a scripted fetch writes null to a file and nothing
notices.
After the fix the same input reports the parse error alongside the
existing advice and exits 1. A valid schema still round-trips unchanged
in both --format=json and --format=yaml.
Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
0a9722c to
8433994
Compare
|
/ok-to-test |
printSchemarunskubectl get --raw /openapi/v2and unmarshals stdout. Thejson.Unmarshalerror is discarded, not even assigned to_:When kubectl succeeds but the response is not JSON, for example an auth portal or corporate proxy returning HTML,
jsonSchemais left nil,MarshalIndentrenders it asnull, and the command prints that and exits 0:The function already guards the two neighbouring failures, kubectl exiting non-zero and empty stdout, and both reuse the
errMsgadvice. Only "kubectl succeeded but returned something that is not a schema" was unguarded, so a scripted fetch writesnullto a file and nothing notices.After the fix:
A valid schema still round-trips unchanged in both
--format=jsonand--format=yaml. Reproduced with a stubkubectlonPATH.