Giter Site home page Giter Site logo

Comments (16)

clabnet avatar clabnet commented on May 24, 2024 1

For now only options provided by the cli. I'm using Angular 17.3, I don't have tested until now the access to db.

from openapi-ts.

clabnet avatar clabnet commented on May 24, 2024 1

Hi @mrlubos , thank you for the fast response.
I have created a openapi-ts.config.js and located at same level of package.json. I run on Windows 11.
The file content is :

/** @type {import('@nicolas-chaulet/openapi-typescript-codegen').Config} */
export default {
  input: 'http://localhost:5005/openapi.json',
  output: 'web/src/generated/client',
  exportSchemas:true
}

The script command to start on package.json is :

    "gen:api-create-services": "npx @nicolas-chaulet/openapi-typescript-codegen",

The error is :

> npm-run-all -l --sequential gen:*

[gen:api-create-services] 
[gen:api-create-services] > [email protected] gen:api-create-services D:\_lab\src\frontend\xxxxxxxx-smartc-fe
[gen:api-create-services] > npx @nicolas-chaulet/openapi-typescript-codegen
[gen:api-create-services] 
[gen:api-create-services] Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
[gen:api-create-services]     at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11)
[gen:api-create-services]     at defaultLoad (node:internal/modules/esm/load:130:3)
[gen:api-create-services]     at ModuleLoader.load (node:internal/modules/esm/loader:409:13)
[gen:api-create-services]     at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:56)
[gen:api-create-services]     at new ModuleJob (node:internal/modules/esm/module_job:65:26)
[gen:api-create-services]     at #createModuleJob (node:internal/modules/esm/loader:303:17)
[gen:api-create-services]     at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:260:34)
[gen:api-create-services]     at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:17)
[gen:api-create-services]     at async ModuleLoader.import (node:internal/modules/esm/loader:328:23) {
[gen:api-create-services]   code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
[gen:api-create-services] }
[gen:api-create-services]  ELIFECYCLE  Command failed with exit code 1.
ERROR: "gen:api-create-services" exited with 1.

from openapi-ts.

tajnymag avatar tajnymag commented on May 24, 2024 1

@tajnymag you're on Windows, right? Are you able to check which part of the code is causing issues?

I'll be on my PC in a few hours, but I think I found the culprit.

To reliably load a local module, Nodejs expects file:// url protocol. By reading the source, I've found this function, which imports the config file without constructing a proper URL.

https://github.com/nicolas-chaulet/openapi-typescript-codegen/blob/master/src%2Findex.ts#L79

from openapi-ts.

clabnet avatar clabnet commented on May 24, 2024 1

I still trying now. One moment, I will inform you.

from openapi-ts.

clabnet avatar clabnet commented on May 24, 2024 1

It work !

But it is required this code :

/** @type {import('@nicolas-chaulet/openapi-typescript-codegen').UserConfig} */
module.exports = {
  input: 'http://localhost:5003/documentation/json',
  output: 'web/src/generated/client',
  exportSchemas: true,
}

Thank you all @mrlubos @tajnymag @nicolas-chaulet

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

Hey @clabnet, this is something I was actually considering earlier today. Are you looking to put many settings inside that file? Is it a style preference?

P.S. Which Angular version are you using? Is everything working as expected?

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

Hey @clabnet, you can now use a configuration file. Here's how it would look for you

/** @type {import('@nicolas-chaulet/openapi-typescript-codegen').Config} */
export default {
  exportSchemas: true,
  input: 'http://localhost:5005/openapi.json',
  output: 'src/generated/client',
}

Note that you do not need to supply client anymore, it will be automatically detected 🎉

Let me know if this works for you!

P.S. You need to be using Node.js v18 or newer

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

@clabnet which Node version are you on?

from openapi-ts.

clabnet avatar clabnet commented on May 24, 2024

@mrlubos * 20.11.0 (Currently using 64-bit executable)

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

@tajnymag you're on Windows, right? Are you able to check which part of the code is causing issues?

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

@clabnet do you mind trying with v0.27.32? (note that I renamed Config type to UserConfig, though that doesn't affect the runtime)

@tajnymag thanks for your help!

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

@clabnet is this working for you now?

from openapi-ts.

clabnet avatar clabnet commented on May 24, 2024

Unfortunately the version "@nicolas-chaulet/openapi-typescript-codegen": "^0.27.35", don't work on my windows 11 machine

openapi-ts.config.ts

/** @type {import('@nicolas-chaulet/openapi-typescript-codegen').UserConfig} */
export default {
    input: 'http://localhost:5003/documentation/json',
    output: 'web/src/generated/client',
    exportSchemas: true,
}

package.json

scripts: {
    ... 
    "gen:api-create-services": "npx @nicolas-chaulet/openapi-typescript-codegen",
    ....
}

Error :

PS D:\LABS\src\frontend\exiway-smartc-fe> pnpm generate:all

> @schneider/[email protected] generate:all D:\LABS\src\frontend\my-smartc-fe
> npm-run-all -l --sequential gen:*

[gen:api-create-services] 
[gen:api-create-services] > @xxxxx/[email protected] gen:api-create-services D:\LABS\src\frontend\my-smartc-fe
[gen:api-create-services] > npx @nicolas-chaulet/openapi-typescript-codegen
[gen:api-create-services]
[gen:api-create-services] Error: 🚫 input not provided - provide path to OpenAPI specification
[gen:api-create-services]     at To (file:///D:/LABS/src/frontend/my-smartc-fe/node_modules/.pnpm/@[email protected]/node_modules/@nicolas-chaulet/openapi-typescript-codegen/dist/node/index.js:1:229289)
[gen:api-create-services]     at async Eo (file:///D:/LABS/src/frontend/my-smartc-fe/node_modules/.pnpm/@[email protected]/node_modules/@nicolas-chaulet/openapi-typescript-codegen/dist/node/index.js:1:229642)
[gen:api-create-services]     at async start (file:///D:/LABS/src/frontend/my-smartc-fe/node_modules/.pnpm/@[email protected]/node_modules/@nicolas-chaulet/openapi-typescript-codegen/bin/index.js:45:9)
[gen:api-create-services]  ELIFECYCLE  Command failed with exit code 1.
ERROR: "gen:api-create-services" exited with 1.

A partial of openapi.json

{"openapi":"3.0.3","info":{"title":"REST API","description":"Exposing a SQL database as REST","version":"1.0.0"},"components":{"schemas":{"Drawing":{"title":"Drawing","description":"A Drawing","type":"object","properties":{"filename":{"type":"string","nullable":true},"extension":{"type":"string","nullable":true},"size":{"type":"integer","nullable":true},"item":{"type":"string","nullable":true},"creationDate":{"type":"string","nullable":true},"lastAccessDate":{"type":"string","nullable":true},"lastModifiedDate":{"type":"string","nullable":true},"plantId":{"type":"string","nullable":true},"tag":{"type":"string","nullable":true},"uuid":{"type":"string","nullable":true}},"additionalProperties":false},"DrawingInput":{"title":"DrawingInput","description":"A Drawing","type":"object","properties":{"filename":{"type":"string"},"extension":{"type":"string"},"size":{"type":"integer"},"item":{"type":"string","nullable":true},"creationDate":{"type":"string"},"lastAccessDate":{"type":"string"},"lastModifiedDate":{"type":"string"},"plantId":{"type":"string"},"tag":{"type":"string","nullable":true},"uuid":{"type":"string"}},"additionalProperties":false,"required":["creationDate","extension","filename","lastAccessDate","lastModifiedDate","plantId","size"]},"Bom":{"title":"Bom","description":"A Bom","type":"object","properties":{"item":{"type":"string","nullable":true},"path":{"type":"string","nullable":true},"pathId":{"type":"string","nullable":true},"level":{"type":"integer","nullable":true},"parent":{"type":"string","nullable":true},"type":{"type":"string","nullable":true},"id":{"type":"integer","nullable":true},"selection":{"type":"string","nullable":true},"tN":{"type":"integer","nullable":true},"quantity":{"type":"integer","nullable":true},"r

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

@clabnet try with openapi-ts.config.js instead of openapi-ts.config.ts please, we don't support .ts just yet #84

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

@clabnet Did you have any luck with the config file?

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

Great @clabnet! FYI I'm working on making exportSchemas true by default, so you shouldn't need that option soon either!

from openapi-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.