Azure / Azure/autorest.powershell

serializeToContent doesn´t take "text/plain" into account

Open
#738 0 comments 0 reactions 0 assignees View on GitHub
feature-request P2
Dominant language
C#
Stars
123
Forks
99
PR merge metrics
No merged PRs in 30d

Description

When generating a module, the content type of the requestBody is not correctly generated
The whole definition file is [here](https://gist.github.com/kamilkosek/fa7d9a97fcdcb7233e038c3d601d0438#file-openhab_swagger_definition-json-L2341)

iE. this part
```json
"post": {
"tags": [
"items"
],
"summary": "Sends a command to an item.",
"operationId": "sendItemCommand",
"parameters": [
{
"name": "itemname",
"in": "path",
"description": "item name",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"description": "valid item command (e.g. ON, OFF, UP, DOWN, REFRESH)",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
},
"404": {
"description": "Item not found"
},
"400": {
"description": "Item command null"
}
}
},
```
..generates following code:
```csharp
/// Sends a command to an item.
/// item name
/// valid item command (e.g. ON, OFF, UP, DOWN, REFRESH)
/// a delegate that is called when the remote service returns 200 (OK).
/// a delegate that is called when the remote service returns 400 (BadRequest).
/// a delegate that is called when the remote service returns 404 (NotFound).
/// an instance that will receive events.
/// an instance of an OpenHab.Runtime.ISendAsync pipeline to use to make the request.
///
/// A that will be complete when handling of the response is completed.
///
public async global::System.Threading.Tasks.Task SendItemCommand(string itemname, string body, global::System.Func onOk, global::System.Func onBadRequest, global::System.Func onNotFound, OpenHab.Runtime.IEventListener eventListener, OpenHab.Runtime.ISendAsync sender)
{
// Constant Parameters
using( NoSynchronizationContext )
{
// construct URL
var pathAndQuery = global::System.Text.RegularExpressions.Regex.Replace(
"/items/"
+ global::System.Uri.EscapeDataString(itemname)

,"\\?&*$|&*$|(\\?)&+|(&)&+","$1$2");

await eventListener.Signal(OpenHab.Runtime.Events.URLCreated, pathAndQuery); if( eventListener.Token.IsCancellationRequested ) { return; }

// generate request object
var _url = new global::System.Uri($"{OpenHabHost}/rest{pathAndQuery}");
var request = new global::System.Net.Http.HttpRequestMessage(OpenHab.Runtime.Method.Post, _url);
await eventListener.Signal(OpenHab.Runtime.Events.RequestCreated, request.RequestUri.PathAndQuery); if( eventListener.Token.IsCancellationRequested ) { return; }

await eventListener.Signal(OpenHab.Runtime.Events.HeaderParametersAdded); if( eventListener.Token.IsCancellationRequested ) { return; }
// set body content
request.Content = null /* serializeToContent doesn't support 'application/json' C:\Users\k\.autorest\@autorest_powershell@3.0.419\node_modules\@autorest\powershell\dist\llcsharp\schema\string.js*/;
request.Content.Headers.ContentType = global::System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
await eventListener.Signal(OpenHab.Runtime.Events.BodyContentSet); if( eventListener.Token.IsCancellationRequested ) { return; }
// make the call
await this.SendItemCommand_Call(request,onOk,onBadRequest,onNotFound,eventListener,sender);
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.