Swagger c# generation fails
Description
When sending the swagger json to https://generator.swagger.io/api/gen/clients/csharp we get ; Fri Mar 02 2018 16:48:49.0412 [ERROR] TID: 9 GenerateCsharp ; StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT Access-Control-Allow-Headers: Content-Type Connection: close Date: Fri, 02 Mar 2018 16:48:47 GMT Server: Jetty(9.2.9.v20150224) Content-Length: 106 Content-Type: application/json }
Swagger-codegen version
not sure - current live on website
Swagger declaration file content or url
https://gist.github.com/jemprince/a73026aee1eadb8d09c12fecbe65b63b
Command line used for generation
Steps to reproduce
codeGenPath="https://generator.swagger.io/api/gen/"; ... using (var client2 = this.iClientWithProxy.Create()) { client2.BaseAddress = new Uri(codeGenPath); client2.DefaultRequestHeaders.Accept.Clear(); client2.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
using (var request = new HttpRequestMessage(HttpMethod.Post, genPath))
{
request.Content = new StringContent(swaggerSpec, Encoding.UTF8, "application/json");
... (swaggerSpec as above)
Related issues/PRs
We seem to be having the same issue.
We can generate c-sharp client-side code fine using options + swaggerURL but when we try options + spec with even a basic document we get either 400 - Bad Request or 500 - Internal Server Error.
The call is POST to "http://generator.swagger.io/api/gen/clients/csharp"
Example request content:
{ "options":{}, "spec":"{ "swagger": "2.0", "info": { "title": "Company API", "version": "1.0", "description": "This API is used to manage something." }, "host": "api.company.com", "basePath": "/api/v1", "schemes": [ "https" ], "paths": { "/something": { "get": { "description": "Get something.", "operationId": "GetSomething", "summary": "Something", "responses": { "200": { "description": "Returned when the operation is successful." } }, "produces": [ "application/json" ] } } } }"}
Couldn't be more basic, right?
We've tried escaping, not escaping, etc. We're using JSON.NET and, as I said, all is well with a Swagger doc via URL. Things blow up using a spec call, tho.
Found our issue: there was a quote mark before the brace here (and at the end of the spec element) where there shouldn't be:
"spec":"{
This caused the spec content to be treated as a string. It came about because we were manipulating the JSON prior to dispatch. We needed to convert it to a JSON object before adding to content arguments.
A better error than a 400 or 500 would have been appreciated here. Something like "Document is not valid Swagger" would be good.