question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[typescript] Endpoint with string content produces unbuildable code

See original GitHub issue

With the following input:

openapi: 3.0.1
info:
  title: Data
  description: Services for general drinkaware data
  version: 1.0.0
paths:
  /:
    get:
      operationId: Home
      summary: Get Home Page
      responses:
        '200':
          description: Home page
          content:
            text/plain; utf-8:
              schema:
                type: string
                pattern: '^.*$'
                maxLength: 1000
                example: unauthorized 

The typescript emitter creates a data.ts file with the following specification:

const homeOperationSpec: coreHttp.OperationSpec = {
  path: "/",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: {
        type: { name: "String" },
        constraints: { MaxLength: 1000, Pattern: {} }
      }
    }
  },
  urlParameters: [Parameters.$host],
  headerParameters: [Parameters.accept],
  serializer
};

The bodyMapper property cannot be mapped to a valid type:

      TS2322: Type '{ type: { name: "String"; }; constraints: { MaxLength: number; Pattern: {}; }; }' is not assignable to type 'BaseMapper | CompositeMapper | SequenceMapper | DictionaryMapper | EnumMapper | undefined'.
  Type '{ type: { name: "String"; }; constraints: { MaxLength: number; Pattern: {}; }; }' is not assignable to type 'EnumMapper'.
    Types of property 'type' are incompatible.
      Property 'allowedValues' is missing in type '{ name: "String"; }' but required in type 'EnumMapperType'.

Expected behavior Valid YAML produces a valid typescript file

Additional context

AutoRest code generation utility [cli version: 3.1.2; node: v12.18.2, max-memory: 2048 MB]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest

There is a new version of AutoRest available (3.2.0).
 > You can install the newer version with with npm install -g autorest@latest

   Loading AutoRest core      '/home/craignicol/.autorest/@autorest_core@3.0.6375/node_modules/@autorest/core/dist' (3.0.6375)
   Loading AutoRest extension '@autorest/typescript' (6.0.0-dev.20201105.2->6.0.0-dev.20201105.2)
   Loading AutoRest extension '@autorest/modelerfour' (4.15.421->4.15.421)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
timotheeguerincommented, May 7, 2021

Seems to be an issue with the typescript generator itself here, will transfer to their repo

0reactions
sarangan12commented, Jun 21, 2022

Fixed it with the PR https://github.com/Azure/autorest.typescript/pull/1426. No more action items pending on this issue. Closing it now. Feed free to reopen if you face this issue again. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

[typescript] Endpoint with string content produces unbuildable ...
The typescript emitter creates a data.ts file with the following specification: const homeOperationSpec: coreHttp.OperationSpec = { path: "/", ...
Read more >
Documentation - Do's and Don'ts - TypeScript
Don't ever use the types Number , String , Boolean , Symbol , or Object These ... boxed objects that are almost never...
Read more >
Typescript Type 'string' is not assignable to type - Stack Overflow
Essentially cast it to itself, and tell the compiler no I don't want this to be a string! // so this gives no...
Read more >
Node.js and TypeScript Tutorial: Build a CRUD API - Auth0
This tutorial shows you how to build a feature-complete API using Node.js, Express, and TypeScript that lets clients perform data operations on ...
Read more >
Introduction to RESTful APIs with NestJS - This Dot Labs
The installation of NestJS comes with a sample API endpoint that we ... TypeScript interfaces do not produce any JavaScript code during the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found