Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotImplementedError: Unexpected scenario where a(n) OpenBraceToken was not found. #673

Closed
TylerLeonhardt opened this issue Jun 20, 2020 · 11 comments
Assignees

Comments

@TylerLeonhardt
Copy link
Member

I tried using the latest build today. It looks like generation isn't quite there yet for v3.

The YAML I used is here: https://github.com/TylerLeonhardt/AutoRest-PowerShell-Nodejs-Demo/blob/master/FDIC/fdic.yaml
The original YAML is here: https://banks.data.fdic.gov/docs/swagger.yaml

PS > autorest-beta --input-file=./fdic.yaml --output-folder=./fdic.js --typescript --use:@autorest/typescript@6.0.0-dev.20200618.1 --v3 

AutoRest code generation utility [cli version: 3.0.6187; node: v13.5.0, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
   Loading AutoRest core      '/Users/tyleonha/.autorest/@autorest_core@3.0.6258/node_modules/@autorest/core/dist' (3.0.6258)
   Installing AutoRest extension '@autorest/typescript' (6.0.0-dev.20200618.1)
   Installed AutoRest extension '@autorest/typescript' (6.0.0-dev.20200618.1->6.0.0-dev.20200618.1)
   Loading AutoRest extension '@autorest/modelerfour' (4.13.358->4.13.358)

WARNING (PreCheck/CheckDuplicateSchemas): Checking for duplicate schemas, this could take a (long) while.  Run with --verbose for more detail.
An error was encountered while handling a request: NotImplementedError: Unexpected scenario where a(n) OpenBraceToken was not found.
    at getTokenEnd (/Users/tyleonha/.autorest/@autorest_typescript@6.0.0-dev.20200618.1/node_modules/ts-morph/dist/ts-morph.js:2524:23)
    at Function.getContainerBodyPos (/Users/tyleonha/.autorest/@autorest_typescript@6.0.0-dev.20200618.1/node_modules/ts-morph/dist/ts-morph.js:2516:20)
    at getNodes (/Users/tyleonha/.autorest/@autorest_typescript@6.0.0-dev.20200618.1/node_modules/ts-morph/dist/ts-morph.js:2534:48)
    at getNodes.next (<anonymous>)
    at Function.from (<anonymous>)
    at Function.getOrParseChildren (/Users/tyleonha/.autorest/@autorest_typescript@6.0.0-dev.20200618.1/node_modules/ts-morph/dist/ts-morph.js:2476:30)
    at Function.getContainerArray (/Users/tyleonha/.autorest/@autorest_typescript@6.0.0-dev.20200618.1/node_modules/ts-morph/dist/ts-morph.js:2697:34)
    at ClassDeclaration.getMembersWithComments (/Users/tyleonha/.autorest/@autorest_typescript@6.0.0-dev.20200618.1/node_modules/ts-morph/dist/ts-morph.js:13342:44)
    at ClassDeclaration.addConstructor (/Users/tyleonha/.autorest/@autorest_typescript@6.0.0-dev.20200618.1/node_modules/ts-morph/dist/ts-morph.js:13075:69)
    at writeConstructor (/Users/tyleonha/.autorest/@autorest_typescript@6.0.0-dev.20200618.1/node_modules/@autorest/typescript/dist/src/generators/clientFileGenerator.js:114:48)
FATAL: Error: Unexpected scenario where a(n) OpenBraceToken was not found.
  Error: Plugin typescript reported failure.

For now, I'll continue using the node.js generator.

@joheredi
Copy link
Member

@TylerLeonhardt thanks for reporting this issue. I'm currently investigating and will report back as soon as I get more information.

@joheredi
Copy link
Member

@TylerLeonhardt I have merged a fix for the issue you reported. Would you mind trying to generate again using version 6.0.0-dev.20200623.1

@TylerLeonhardt
Copy link
Member Author

@joheredi it looks like it generates but now it requires some kind of credential object?:

new FdicBankDataAPIBeta(credentials: TokenCredential | ServiceClientCredentials, options?: FdicBankDataAPIBetaOptionalParams): FdicBankDataAPIBeta

This API doesn't have any such token/credential (AFAIK)

@joheredi
Copy link
Member

If you use the flag --add-credentials=false it should remove the credentials parameter

@TylerLeonhardt
Copy link
Member Author

Something's still not right...

autorest-beta --input-file=https://github.com/TylerLeonhardt/AutoRest-PowerShell-Nodejs-Demo/master/FDIC/fdic.yaml --output-folder=./fdic.ts --add-credentials=false --typescript --use:@autorest/typescript@6.0.0-dev.20200623.1 --v3

# then do

cd fdic.ts
npm install
npm run build
cd ..

Now create a ts file here

import { FdicBankDataAPIBeta } from './fdic.ts/dist/FdicBankDataAPIBeta'

// weird "options: any" as parameter
const myFDIC = new FdicBankDataAPIBeta(null);

myFDIC.searchInstitutions({
    filters: "STALP:NC AND ACTIVE:1 AND CITY:Charlotte",
    limit: 100
}).then(val => console.log(val.data));

and here's my package.json:

{
  "name": "fdic",
  "author": "Microsoft Corporation",
  "description": "FDICBankDataAPIBeta Library with typescript type definitions for node",
  "version": "1.0.0",
  "dependencies": {
  },
  "devDependencies": {
    "typescript": "3.4.3"
  },
  "keywords": [
    "node",
    "azure"
  ],
  "scripts": {
    "compile": "tsc ./fdic-test.ts",
    "start": "node ./fdic-test.js"
  },
  "license": "MIT",
  "main": "./lib/fDICBankDataAPIBeta.js",
  "homepage": "https://github.com/azure/azure-sdk-for-node",
  "repository": {
    "type": "git",
    "url": "https://github.com/azure/azure-sdk-for-node.git"
  },
  "bugs": {
    "url": "https://github.com/azure/azure-sdk-for-node/issues"
  }
}

Using the nodejs generator, I got output from my TS file. Using the typescript generator, I do not get any.

@joheredi
Copy link
Member

@TylerLeonhardt is the problem you're describing that your console.log

myFDIC
  .searchInstitutions({
    filters: "STALP:NC AND ACTIVE:1 AND CITY:Charlotte",
    limit: 100,
  })
.then((val) => console.log(val.data));

is logging undefined? If so, would you mind trying the following when creating FdicBankDataAPIBeta:

const myFDIC = new FdicBankDataAPIBeta({
  endpoint: "https://banks.data.fdic.gov/api/",
});

I see that https://banks.data.fdic.gov/api/ is defined in the yaml so I need to investigate why it is not picking it up. But meanwhile it would be helpful if you can help me confirm if this gets you the expected behavior.

As for the any parameter, do you get the same if instead import FdicBankDataAPIBeta this way?

import { FdicBankDataAPIBeta } from "./fdic.ts";

@TylerLeonhardt
Copy link
Member Author

TylerLeonhardt commented Jun 24, 2020

const myFDIC = new FdicBankDataAPIBeta({
  endpoint: "https://banks.data.fdic.gov/api/",
});

This worked!

Also the any parameter goes away when I do that yes:

import { FdicBankDataAPIBeta } from "./fdic.ts";

bit I still need to specify that endpoint in the ctor for it to actually work.

@joheredi
Copy link
Member

@TylerLeonhardt thanks for reporting these issues. I'm investigating why the server url in the swagger is not being correctly used. The problem seems to be in @azure/core-http. I have filed an issue in its repo to track this Azure/azure-sdk-for-js/issues/9700

I'm going to close this issue as the original problem has been resolved, however feel free to follow the linked Issue, once that one is fixed you should be able to remove the endpoint in the constructor.

@joheredi
Copy link
Member

@TylerLeonhardt I have merged a fix which should remove the necessity to pass endpoint to the constructor. The build is 6.0.0-dev.20200625.1 please give it a try

@TylerLeonhardt
Copy link
Member Author

Looks like it works :) thanks!

@TylerLeonhardt
Copy link
Member Author

btw this is related:
https://github.com/Azure/autorest/issues/35135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants