-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response with text media type is parsed to a JSON object instead of a string #11649
Comments
@nguerrera Looks like this is a recorded test, and the recorded response has content-type of |
Ah! You’re right. I should have checked that!. Looks like the server is not actually responding with text/plain like the swagger says it will! Thanks, I’ll follow up with the service folks. |
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @arerlend, @alzimmermsft. Issue DetailsThe 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.
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
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 });
}
Expected resultTests pass Actual resultTests fail:
|
Quick update: @hmlam and @nickghardwick will update the service to return responses with content-type of |
The official swagger defines the schema to be a file which gets compiled by autorest as a stream. In the SDK, this stream gets read and converted to text, so this is no longer an issue. |
The 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 seemediaType: "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
rush update && rush build
cd sdk/schemaregistry/schema-registry
npm run test
Expected result
Tests pass
Actual result
Tests fail:
The text was updated successfully, but these errors were encountered: