Skip to content

Instantly share code, notes, and snippets.

@MisinformedDNA
Created May 24, 2016 21:50
Show Gist options
  • Save MisinformedDNA/bf3d1a9469ae61e36c7e356e1dbef27e to your computer and use it in GitHub Desktop.
Save MisinformedDNA/bf3d1a9469ae61e36c7e356e1dbef27e to your computer and use it in GitHub Desktop.
AutoRest code generation
Generating client code and adding to project started
Generate client code for REST API with following parameters:
REST API Name: MyApplication.Web, Base namespace: EpicastMedia.PodcastAggregator.ApiClient, Metadata file path: C:\Users\dan\Downloads\EpicastSwagger.json
[Info]AutoRest Core 0.9.7.0
[Info]Initializing code generator.
[Info]Successfully initialized CSharp Code Generator 1.0.5584.22489
[Info]Initializing modeler.
[Info]Successfully initialized Swagger Modeler 1.0.5584.22490
[Info]Parsing swagger json file.
[Info]Generating client model from swagger model.
[Info]Initializing code generator.
[Info]Successfully initialized CSharp Code Generator 1.0.5584.22489
[Fatal]Error generating syntax tree: Failure during generation of method Put.
Failure during serialization generation of method Put.
System.NotSupportedException: MyApplication.Services.Models.UserSettings - False
System.NotSupportedException: MyApplication.Services.Models.UserSettings - False
at Hyak.SerializationGenerator.CreateSerializationMethod(ISerializationBase serializationFormat)
at Hyak.JsonSerializationGenerator.SerializeJsonRequest[T](StatementsBuilder`1 builder, IJsonBase root)
at Hyak.JsonSerializationFramework.Serialize[T](ISerializationBase serialization, StatementsBuilder`1& builder)
at Hyak.CodeGeneratorExtensions.SerializationExtensions`1.Serialize(IDictionary`2 requestBodyDefinitions, Type& requestType)
at Hyak.ClientGenerator.<>c__DisplayClass3a`1.<SerializeRequest>b__37()
at Hyak.Ensure.ErrorContext(Action action, String context)
Exception: There was an error during code generation when trying to add a client for the REST API
Generating client code and adding to project failed
Adding REST API client for failed
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "MyApplication.Web"
},
"host": "localhost:62614",
"schemes": [
"http"
],
"paths": {
"/api/user/settings": {
"put": {
"tags": [
"UserSettings"
],
"operationId": "UserSettings_Put",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "settings",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MyApplication.Services.Models.UserSettings"
}
}
],
"responses": {
"204": {
"description": "NoContent"
}
},
"deprecated": false
}
}
},
"definitions": {
"MyApplication.Services.Models.UserSettings": {
"type": "object",
"properties": {
"BackSeconds": {
"format": "int32",
"type": "integer"
},
"ForwardSeconds": {
"format": "int32",
"type": "integer"
}
}
}
}
}
using MyApplication.Data;
using MyApplication.Services.Models;
using Swashbuckle.Swagger.Annotations;
using System.Data.Entity;
using System.Net;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;
namespace MyApplication.Web.Controllers.api
{
[RoutePrefix("api/user/settings")]
public class UserSettingsController : ApiController
{
// PUT: api/Settings
[Route("")]
[SwaggerResponseRemoveDefaults]
[SwaggerResponse(HttpStatusCode.NoContent)]
public async Task<IHttpActionResult> Put(UserSettings settings)
{
return StatusCode(HttpStatusCode.NoContent);
}
}
}
@bradygaster-zz
Copy link

Why did you clear the route so it's empty? (just curious)
Just curious - could you change the Put to a Post, I'm wondering if that'd work.
Also, comment out the Swagger... attributes and let's try this bare-bones and see what the error looks like (or if it goes away).

@MisinformedDNA
Copy link
Author

MisinformedDNA commented May 24, 2016

Clearing the route appears to be due to a bug. If I don't do it, the api path is "api/usersettings" instead of the desired "api/user/settings".
Updated code:

        public async Task<IHttpActionResult> Post(UserSettings settings)
        {
            return StatusCode(HttpStatusCode.NoContent);
        }

Updated JSON:

    "/api/UserSettings": {
      "post": {
        "tags": [
          "UserSettings"
        ],
        "operationId": "UserSettings_Post",
        "consumes": [
          "application/json",
          "text/json",
          "application/xml",
          "text/xml",
          "application/x-www-form-urlencoded"
        ],
        "produces": [
          "application/json",
          "text/json",
          "application/xml",
          "text/xml"
        ],
        "parameters": [
          {
            "name": "settings",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/EpicastMedia.PodcastAggregator.Services.Models.UserSettings"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/System.Object"
            }
          }
        },
        "deprecated": false
      }
    }

And I get the same error message.

@MisinformedDNA
Copy link
Author

Running:
Azure Tools 2.9.1
VS 2015 Update 2
Microsoft.Rest.ClientRuntime 0.9.6 (I tried upgrading but it reverted back when I ran the add REST API client again)

@MisinformedDNA
Copy link
Author

Any other ideas @bradygaster?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment