Azure / autorest.azure-functions-typescript

Typescript Azure Functions code generator using autorest
MIT License
4 stars 6 forks source link

Question: Is there a working example? #2

Open fwiedmann opened 3 years ago

fwiedmann commented 3 years ago

Hey,

I'm currently trying to generate Azure Functions from an OpenApi Spec. But after executing the following command nothing gets generated (at least I can't see a new folder or any new created files):

 autorest --azure-functions-typescript  --input-file:covid-apis.json --output-folder:./generated-azfunctions --verbose

As you can see, I tried it with the example covid-apis.json spec from the test/data/service-description-jsons folder.

I installed autorest via npm install -g autorest.

Does this module even work? This public announcement says TS is supported: https://azure.microsoft.com/en-us/updates/generate-a-new-function-app-from-an-openapi-specification/

Full output:

autorest --azure-functions-typescript  --input-file:covid-apis.json --output-folder:./generated-azfunctions --verbose
AutoRest code generation utility [cli version: 3.3.2; node: v12.19.1]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
No configuration found at 'file:///Users/wiedmannf/git/github.com/azure/autorest.azure-functions-typescript/test/data/service-description-jsons/'.
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/default-configuration.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/inspect.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/directives.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/pipeline.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/loader-openapi.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/miscellaneous.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-powershell.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-azureresourceschema.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-csharp.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-go.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-java.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-nodejs.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-php.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-python.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-ruby.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-typescript.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-validators.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-az.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-terraform.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/plugin-azure-functions.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/graphs.md'
> Including configuration file 'file:///Users/wiedmannf/.nvm/versions/node/v12.19.1/lib/node_modules/autorest/dist/resources/help-configuration.md'
> Loading AutoRest extension '@autorest/azure-functions-typescript' (latest->0.0.1-preview)
> Including extension configuration file 'file:///Users/wiedmannf/.autorest/@autorest_azure-functions-typescript@0.0.1-preview/node_modules/@autorest/azure-functions-typescript/README.md'
> Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_azure-functions-typescript@0.0.1-preview/node_modules/@autorest/azure-functions-typescript/README.md'
> Loading AutoRest extension '@autorest/modelerfour' (4.15.396->4.15.396)
> Including extension configuration file 'file:///Users/wiedmannf/.autorest/@autorest_modelerfour@4.15.396/node_modules/@autorest/modelerfour/readme.md'
> Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_modelerfour@4.15.396/node_modules/@autorest/modelerfour/readme.md'
NOTE: AutoRest core version selected from configuration: 3.0.6302.
   Loading AutoRest core      '/Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/dist' (3.0.6302)
No configuration found at 'file:///Users/wiedmannf/git/github.com/azure/autorest.azure-functions-typescript/test/data/service-description-jsons/'.
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/inspect.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/directives.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/pipeline.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/loader-openapi.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/miscellaneous.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/patches.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-powershell.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-azureresourceschema.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-csharp.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-go.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-java.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-nodejs.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-php.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-python.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-ruby.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-typescript.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-validators.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-az.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/plugin-trenton.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/graphs.md'
   Including configuration file 'file:///Users/wiedmannf/.autorest/@autorest_core@3.0.6302/node_modules/@autorest/core/resources/help-configuration.md'
VERBOSE [0.9 s]: Reading OpenAPI 2.0 file file:///Users/wiedmannf/git/github.com/azure/autorest.azure-functions-typescript/test/data/service-description-jsons/covid-apis.json
[1.13 s] Generation Complete
autorest.azure-functions-typescript/test/da
NickRees91 commented 2 years ago

I second this... the issue is different but I too have not been able to successfully generate Azure functions from this tool. I get the following error:

AutoRest code generation utility [cli version: 3.5.1; node: v14.18.2]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
SourceMapConsumer.initialize is a no-op when running in node.js
info    |    Loading AutoRest core      '/Users/nick/.autorest/@autorestcore@3.7.4/nodemodules/@autorest/core/dist' (3.7.4)
/Users/nick/.autorest/@autorest_azure-functions-typescript@0.0.1-preview/node_modules/@azure-tools/codemodel/dist/model/yaml-schema.js:38
exports.codeModelSchema = js_yaml_1.Schema.create(js_yaml_1.DEFAULT_SAFE_SCHEMA, [
                                           ^

TypeError: js_yaml_1.Schema.create is not a function
    at Object.<anonymous> (/Users/nick/.autorest/@autorest_azure-functions-typescript@0.0.1-preview/node_modules/@azure-tools/codemodel/dist/model/yaml-schema.js:38:44)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/Users/nick/.autorest/@autorest_azure-functions-typescript@0.0.1-preview/node_modules/@azure-tools/codemodel/dist/exports.js:42:14)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
jamief00 commented 2 years ago

Same issue as @NickRees91 above.

TypeError: js_yaml_1.Schema.create is not a function

Have tried multiple JSON/YAML schemas which conform to OpenAPI specs.

jamief00 commented 2 years ago

The issue, I think, is caused by js-yaml:

js-yaml v3:

let schema3 = yaml.Schema.create(yaml.DEFAULT_SAFE_SCHEMA, [ customTags ])

js-yaml v4:

let schema3 = yaml.DEFAULT_SCHEMA.extend([ customTags ])

Looks like it has been built against js-yaml v3 (and is expecting Schema.create), but Autorest is pulling in 4.X of js-yaml which doesn't have that method. No idea how to resolve though.

mdelarocha commented 2 years ago

Made a PR #3 that addresses this, got it to work on my end. You can pull it in your local to use it.

lb-cyway-one commented 1 year ago

Is this project dead?

The option to generate "HTTP trigger(s) from OpenAPI V2/V3 Specification" is still available in the latest version of Azure Functions extension for Visual Studio Code but any attempt failed with :

TypeError: js_yaml_1.Schema.create is not a function

@mdelarocha, I've not yet tried to clone your proposed patch. Is it still current? Are you actively using it?

mdelarocha commented 1 year ago

@lb-cyway-one this is pretty much dead. Stopped using this project and started to just write templates myself since it was more efficient. My fix should probably still work, might need some library upgrades again.