Skip to content

Commit d2544f7

Browse files
override-response-parsing (#484)
Summary: - Support override of response type, driving deserialization, even when reponse `Content-Type` header is misleading. - Added robot test `Google AcceleratorTypes Demonstrating Response Content Type Override`.
1 parent 6f6d522 commit d2544f7

File tree

7 files changed

+69
-4
lines changed

7 files changed

+69
-4
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@
152152
"show methods in azure.dev_center.customization_tasks;",
153153
"set global \"a.b\"=1;",
154154
"set global \"$.auth.google.sub\"='krimmer@stackql.io';",
155-
"select JSON_EXTRACT(saml.samlIdentity, '$.username') as saml_username from github.scim.saml_ids saml where saml.org = 'dummyorg';"
155+
"select JSON_EXTRACT(saml.samlIdentity, '$.username') as saml_username from github.scim.saml_ids saml where saml.org = 'dummyorg';",
156+
"select kind, name, maximumCardsPerInstance from google.compute.acceleratorTypes where project = 'defective-response-content-project' and zone = 'australia-southeast1-a' order by name desc;"
156157
],
157158
"default": "show providers;"
158159
},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/spf13/cobra v1.4.0
2222
github.com/spf13/pflag v1.0.5
2323
github.com/spf13/viper v1.10.1
24-
github.com/stackql/any-sdk v0.0.3-beta27
24+
github.com/stackql/any-sdk v0.0.4-alpha04
2525
github.com/stackql/go-suffix-map v0.0.1-alpha01
2626
github.com/stackql/psql-wire v0.1.1-alpha07
2727
github.com/stackql/stackql-parser v0.0.14-alpha04

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
471471
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
472472
github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
473473
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
474-
github.com/stackql/any-sdk v0.0.3-beta27 h1:WRfGfseXdHcQUD+dXNH2+W7HjzhHzX/JPstmh31JW+0=
475-
github.com/stackql/any-sdk v0.0.3-beta27/go.mod h1:CIMFo3fC2ScpqzkzeCkzUQQuzYA1VuqpG0p1EZXN+wY=
474+
github.com/stackql/any-sdk v0.0.4-alpha04 h1:7QUTQi/mmxWnFZ98/oPJ2eeVsYBj5ZMSdeTW0lhOMbo=
475+
github.com/stackql/any-sdk v0.0.4-alpha04/go.mod h1:CIMFo3fC2ScpqzkzeCkzUQQuzYA1VuqpG0p1EZXN+wY=
476476
github.com/stackql/go-suffix-map v0.0.1-alpha01 h1:TDUDS8bySu41Oo9p0eniUeCm43mnRM6zFEd6j6VUaz8=
477477
github.com/stackql/go-suffix-map v0.0.1-alpha01/go.mod h1:QAi+SKukOyf4dBtWy8UMy+hsXXV+yyEE4vmBkji2V7g=
478478
github.com/stackql/psql-wire v0.1.1-alpha07 h1:LQWVUlx4Bougk6dztDNG5tmXxpIVeeTSsInTj801xCs=

test/python/flask/gcp/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def v1_projects_empty_project_aggregated_usableSubnetworks():
146146
def projects_testing_project_zones_australia_southeast1_a_acceleratorTypes():
147147
return render_template('route_21_template.json'), 200, {'Content-Type': 'application/json'}
148148

149+
@app.route('/projects/defective-response-content-project/zones/australia-southeast1-a/acceleratorTypes', methods=['GET'])
150+
def projects_testing_project_zones_australia_southeast1_a_acceleratorTypes_defective_response_type():
151+
return render_template('defective-content-type-accelerator-type-list.json'), 200, {'Content-Type': 'text/plain'}
152+
149153
@app.route('/projects/another-project/zones/australia-southeast1-a/acceleratorTypes', methods=['GET'])
150154
def projects_another_project_zones_australia_southeast1_a_acceleratorTypes():
151155
return render_template('route_22_template.json'), 200, {'Content-Type': 'application/json'}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"kind": "compute#acceleratorTypeList",
3+
"id": "projects/testing-project/zones/australia-southeast1-a/acceleratorTypes",
4+
"items": [
5+
{
6+
"kind": "compute#acceleratorType",
7+
"id": "10010",
8+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
9+
"name": "nvidia-tesla-p4",
10+
"description": "NVIDIA Tesla P4",
11+
"zone": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a",
12+
"selfLink": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a/acceleratorTypes/nvidia-tesla-p4",
13+
"maximumCardsPerInstance": 4
14+
},
15+
{
16+
"kind": "compute#acceleratorType",
17+
"id": "10012",
18+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
19+
"name": "nvidia-tesla-p4-vws",
20+
"description": "NVIDIA Tesla P4 Virtual Workstation",
21+
"zone": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a",
22+
"selfLink": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a/acceleratorTypes/nvidia-tesla-p4-vws",
23+
"maximumCardsPerInstance": 4
24+
},
25+
{
26+
"kind": "compute#acceleratorType",
27+
"id": "10019",
28+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
29+
"name": "nvidia-tesla-t4",
30+
"description": "NVIDIA Tesla T4",
31+
"zone": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a",
32+
"selfLink": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a/acceleratorTypes/nvidia-tesla-t4",
33+
"maximumCardsPerInstance": 4
34+
},
35+
{
36+
"kind": "compute#acceleratorType",
37+
"id": "10020",
38+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
39+
"name": "nvidia-tesla-t4-vws",
40+
"description": "NVIDIA Tesla T4 Virtual Workstation",
41+
"zone": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a",
42+
"selfLink": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a/acceleratorTypes/nvidia-tesla-t4-vws",
43+
"maximumCardsPerInstance": 4
44+
}
45+
],
46+
"selfLink": "https://www.googleapis.com/compute/beta/projects/testing-project/zones/australia-southeast1-a/acceleratorTypes"
47+
}

test/registry/src/googleapis.com/v0.1.2/resources/compute-v1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ resources:
4747
operation:
4848
$ref: 'googleapis.com/v0.1.2/services-split/compute/compute-v1.yaml#/paths/~1projects~1{project}~1zones~1{zone}~1acceleratorTypes/get'
4949
response:
50+
overrideMediaType: application/json
5051
mediaType: application/json
5152
openAPIDocKey: '200'
5253
name: acceleratorTypes

test/robot/functional/stackql_mocked_from_cmd_line.robot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ Google AcceleratorTypes SQL verb post changeover
129129
... ${SELECT_ACCELERATOR_TYPES_DESC}
130130
... ${SELECT_ACCELERATOR_TYPES_DESC_EXPECTED}
131131

132+
Google AcceleratorTypes Demonstrating Response Content Type Override
133+
Should StackQL Exec Inline Equal
134+
... ${STACKQL_EXE}
135+
... ${OKTA_SECRET_STR}
136+
... ${GITHUB_SECRET_STR}
137+
... ${K8S_SECRET_STR}
138+
... ${REGISTRY_NO_VERIFY_CFG_STR}
139+
... ${AUTH_CFG_STR}
140+
... ${SQL_BACKEND_CFG_STR_CANONICAL}
141+
... select kind, name, maximumCardsPerInstance from google.compute.acceleratorTypes where project \= 'defective\-response\-content\-project' and zone \= 'australia\-southeast1\-a' order by name desc;
142+
... ${SELECT_ACCELERATOR_TYPES_DESC_EXPECTED}
143+
132144
Okta Apps Select Simple
133145
Should StackQL Exec Inline Equal
134146
... ${STACKQL_EXE}

0 commit comments

Comments
 (0)