Azure / autorest.typescript

Extension for AutoRest (https://github.com/Azure/autorest) that generates TypeScript code. The transpiled javascript code is isomorphic. It can be run in browser and in node.js environment.
MIT License
176 stars 75 forks source link

TypeScript Compile Error: Cannot find name 'Mappers'. #346

Closed ryanelian closed 5 years ago

ryanelian commented 5 years ago

This is probably related to https://github.com/Azure/autorest.typescript/issues/337 (sorry)

swagger.json

{"swagger":"2.0","info":{"version":"v1","title":"WorkflowManagementApi"},"paths":{"/api/v1/value":{"get":{"tags":["ValueApi"],"operationId":"ApiV1ValueGet","consumes":[],"produces":["application/json"],"parameters":[],"responses":{"200":{"description":"Success","schema":{"uniqueItems":false,"type":"array","items":{"type":"string"}}}}},"post":{"tags":["ValueApi"],"operationId":"ApiV1ValuePost","consumes":["application/json-patch+json","application/json","text/json","application/*+json"],"produces":["application/json"],"parameters":[{"name":"value","in":"body","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","schema":{"type":"string"}}}}}},"definitions":{}}

Console Used

autorest --input-file=swagger.json --output-folder=./client/js/rest-api --typescript --model-date-time-as-string

Compile Error

PS C:\VS\EricAutorestDemo\EricAutorestDemo> tsc
client/js/rest-api/lib/workflowManagementApi.ts:72:42 - error TS2304: Cannot find name 'Mappers'.

72 const serializer = new msRest.Serializer(Mappers);
                                            ~~~~~~~

The Actual Web API

    [ApiController]
    [Produces("application/json")]
    [Route("api/v1/value")]
    public class ValueApiController : Controller
    {
        [HttpGet]
        public ActionResult<string[]> Get()
        {
            return new string[] { "value1", "value2" };
        }

        [HttpPost]
        public ActionResult<string> Post([FromBody][Required]string value)
        {
            return value;
        }
    }

I suspect this is actually being caused by the mapper file not being generated / imported from fix https://github.com/Azure/autorest.typescript/pull/338

ghost commented 5 years ago

We appreciate you filing these issues and we're sorry that you're running into all of the problems. It's not very often that we come across swagger files without definitions/mappers, but we'll fix this as soon as we can.

ryanelian commented 5 years ago

Sorry for the troubles.

The bugged examples are very simple because I'm trying to mentor junior developers using simple examples before moving to more complex cases with classes and stuffs. (Imagine their surprised faces when the simple example broke but the complex cases aren't)

Thank you for the fix, in advance. 👍

ghost commented 5 years ago

This pull request should fix this problem. I'll comment on this issue again when it is published, but when that happens, please run autorest --reset and then try to regenerate these SDKs.

ghost commented 5 years ago

https://www.npmjs.com/package/@microsoft.azure/autorest.typescript/v/2.0.597 was just published and set to latest, so you should be able to run the command I mentioned above (autorest --reset) and regenerate and the problem should be solved.