Response with text media type is parsed to a JSON object instead of a string
See original GitHub issueThe schema registry service returns schemas as text/plain. Avro schemas happen to be JSON, but future serialization formats could represent their schema in text that is not JSON.
Prior version of schema registry swagger indicated to send the schema as a string in JSON. So the body was quoted and escaped. It was very confusing. Now the body is just text/plain, UTF-8. However, upon regenerating the code from the new swagger, I started getting back the body as parsed JSON object, even though the generated code typed it as string.
I’m not sure if this is an issue with the core ServiceClient or with the code that autorest has generated. I do see mediaType: "text"
in the generated code FWIW.
EDIT: The issue appears to be that the service doesn’t actually response with Content-Type: text/plain. Self assigning, tagging schema registry and following up with service owners.
Repro steps
- Check out https://github.com/Azure/azure-sdk-for-js/pull/11650
- Apply the following patch
diff --git a/sdk/schemaregistry/schema-registry/src/conversions.ts b/sdk/schemaregistry/schema-registry/src/conversions.ts
index 35c60a467..09121d5b8 100644
--- a/sdk/schemaregistry/schema-registry/src/conversions.ts
+++ b/sdk/schemaregistry/schema-registry/src/conversions.ts
@@ -30,10 +30,7 @@ type GeneratedResponse = GeneratedSchemaResponse | GeneratedSchemaIdResponse;
* @internal
*/
export function convertSchemaResponse(response: GeneratedSchemaResponse): Schema {
- // https://github.com/Azure/azure-sdk-for-js/issues/11649
- // Although response.body is typed as string, it is a parsed JSON object,
- // so we use _response.bodyAsText instead as a workaround.
- return convertResponse(response, { content: response._response.bodyAsText });
+ return convertResponse(response, { content: response.body });
}
rush update && rush build
cd sdk/schemaregistry/schema-registry
npm run test
Expected result
Tests pass
Actual result
Tests fail:
1 failing
1) SchemaRegistryClient
gets schema by ID:
AssertionError: expected { Object (type, name, ...) } to equal '{"type":"record","name":"User","namespace":"com.azure.schemaregistry.samples","fields":[{"name":"name","type":"string"},{"name":"favoriteNumber","type":"int"}]}'
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
Quick update: @hmlam and @nickghardwick will update the service to return responses with content-type of
text/plain;charset=UTF-8
.@nguerrera Looks like this is a recorded test, and the recorded response has content-type of
application/json
? So core-http will de-serialize it from JSON to object.