Giter Site home page Giter Site logo

Comments (11)

Alamonall avatar Alamonall commented on September 22, 2024 1

i hope this will be fixed soon...

from openapi-ts.

SinnerAir avatar SinnerAir commented on September 22, 2024 1

pnpm: 9.9.0
@hey-api/client-fetch: 0.2.4
@hey-api/openapi-ts: 0.53.0

Configuration in file openapi-ts.config.ts

import { createClient } from '@hey-api/openapi-ts';

export default createClient({
    input: 'http://localhost:8080/api/swagger/v2/swagger.json',
    output: './generated/v2/',
    exportCore: false,
    services: false,
    schemas: false,
    client: '@hey-api/client-fetch',
    types: {
        name: 'preserve',
        enums: 'javascript',
    },
});

Error:

await is only valid in async functions and the top level bodies of modules
D:/projects/XXX/src/apps/xxx.worker.criticalcss/dist/server.js:21996
\r${errorMessage}`), addError(errors2, "", { url: "", statusCode: 0, message: errorMessage, options: _opts }), [name, Buffer.from("")];}},bundles = {};for (_dataCopy.size === 0 && logger3.warn("data size is 0"); _dataCopy.size > 0;) {logger3.debug("run in parallel an creating critical css");let result = await Promise.all(runInParallel(Math.min(_dataCopy.size, _opts.parallelStreamsCount), fn));if (result != null) {for (let item of result) if (item != null) {let [name, css] = item;bundles[name] = css;}}logger3.debug("end create critical css");}return logger3.debug("browser close"), await browser.close(), { bundles, errors: errors2 };};var generate = async ({ data, options, baseUrl, logger: logger3 }) => {let _bundles = {},_errors = {};for (let option of options) {let { bundles, errors: errors2 } = await getCriticalCSS(data, baseUrl, { ...option, logger: logger3 }, { executablePath: await getLocateChrome() });bundles != null && Object.keys(bundles).forEach((name) => {_bundles[name] = Buffer.concat([_bundles[name] ?? Buffer.from(""), bundles[name]]);}), Object.keys(errors2).forEach((name) => {_errors[name] ? _errors[name] = _errors[name].concat(errors2[name]) : _errors[name] = errors2[name];});}let result = { bundles: {}, errors: _errors };return Object.keys(_bundles).forEach((name) => {result.bundles[name] = cssMinify(_bundles[name]);}), result;};var requestDataToGenerateParams = (requestData) => {let data = new Map();for (let item of requestData.bundles) item.name !== null && item.paths !== null && data.set(item.name, item.paths);return { data, options: requestData.options, baseUrl: requestData.baseUrl };};function assertEnvVariables(env) {let temp = env;if ([temp.APP_NAME, temp.QUEUE_HOSTNAME, temp.QUEUE_PORT, temp.QUEUE_USERNAME, temp.QUEUE_PASSWORD, temp.QUEUE_TASKS, temp.QUEUE_PREFETCH_COUNT, temp.QUEUE_RETRY_CONNECT, temp.TYPE].some((x) => x == null)) throw new Error("Invalid env variables");let levels = ["debug", "error", "fatal", "info", "silent", "trace", "warn"];if (temp.LOGGER_LEVEL != null && !levels.includes(temp.LOGGER_LEVEL)) throw new Error("Invalid logger level for pino");}(0, import_dotenv.config)();assertEnvVariables(process.env);var { APP_NAME, QUEUE_HOSTNAME, QUEUE_PORT, QUEUE_USERNAME, QUEUE_PASSWORD, QUEUE_TASKS, QUEUE_PREFETCH_COUNT, NODE_ENV, LOGGER_LEVEL, QUEUE_RETRY_CONNECT, TYPE, VERSION } = process.env,isWillKilled = !1;initLogger(NODE_ENV, LOGGER_LEVEL);var logger2 = getLogger();logger2.debug("Starting...");var connectToQueue = async (options, attempt, socketOptions) => {let onError = (err) => {let newCountAttempt = attempt - 1;if (newCountAttempt === 0) throw logger2.fatal("Consumer failed connect to queue"), err;let delay = getRetryDelay(newCountAttempt);return logger2.debug(`Connect fail. Attempts left ${newCountAttempt}.`), logger2.debug(`New retry connect through ${delay}ms`), wait(delay).then(() => connectToQueue(options, newCountAttempt, socketOptions));};return (0, import_amqplib.connect)(options, socketOptions).catch(onError);},connection = await connectToQueue({ hostname: QUEUE_HOSTNAME, port: parseInt(QUEUE_PORT), username: QUEUE_USERNAME, password: QUEUE_PASSWORD }, parseInt(QUEUE_RETRY_CONNECT), { clientProperties: { connection_name: APP_NAME } });logger2.debug("Connected to queue");var channel = await connection.createChannel();channel.prefetch(parseInt(QUEUE_PREFETCH_COUNT));process.once("SIGTERM", () => {isWillKilled = !0, logger2.fatal("terminate worker due to SIGTERM");});var userAgent = `XXX ${TYPE} Worker ${VERSION != null && VERSION.length > 0 ? "v" + VERSION : "Dev"}`;logger2.info("Awaiting for tasks..");await channel.consume(QUEUE_TASKS, async (msg) => {if (isWillKilled === !0 && (logger2.fatal("Consumer can't take because soon will dead"), await channel.close(), await connection.close(), process.exit(1)), msg !== null) {let requestData = JSON.parse(msg.content.toString()),childLogger = logger2.child({ taskId: requestData.taskId });childLogger.info("Accepted task");let { data, options, baseUrl } = requestDataToGenerateParams(requestData),result = await generate({ data, baseUrl, options: options.map((x) => ({ ...x, onSetContextOptions: (contextOptions) => ({ ...contextOptions, userAgent: (contextOptions.userAgent != null ? contextOptions.userAgent + " " : "") + userAgent }) })), logger: childLogger });result.taskId = requestData.taskId, childLogger.info("Sending to queue task result"), channel.sendToQueue(msg.properties.replyTo, Buffer.from(JSON.stringify(result)), { persistent: !0 }), childLogger.info("Acknowledge task"), channel.ack(msg);} else logger2.fatal("Consumer cancelled by server"), await channel.close(), await connection.close(), process.exit(1);}); /*! Bundled license information:
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

SyntaxError: await is only valid in async functions and the top level bodies of modules
    at new Script (node:vm:116:7)
    at createScript (node:vm:268:10)
    at Object.runInThisContext (node:vm:316:10)
    at evalModule (D:\projects\XXX\src\node_modules\.pnpm\[email protected]\node_modules\jiti\dist\jiti.js:1:247124)
    at Object.jiti (D:\projects\XXX\src\node_modules\.pnpm\[email protected]\node_modules\jiti\dist\jiti.js:1:245241)
    at resolveConfig (D:\projects\XXX\src\node_modules\.pnpm\[email protected]\node_modules\c12\dist\shared\c12.24612422.cjs:365:26)
    at Object.loadConfig (D:\projects\XXX\src\node_modules\.pnpm\[email protected]\node_modules\c12\dist\shared\c12.24612422.cjs:167:29)
    at Ks (D:\projects\XXX\src\node_modules\.pnpm\@[email protected][email protected]\node_modules\@hey-api\openapi-ts\dist\node\index.cjs:1:183049)
    at exports.createClient (D:\projects\XXX\src\node_modules\.pnpm\@[email protected][email protected]\node_modules\@hey-api\openapi-ts\dist\node\index.cjs:1:184996)
    at D:/projects/XXX/src/apps/xxx.worker.criticalcss/openapi-ts.config.ts:3:29
    at evalModule (D:\projects\XXX\src\node_modules\.pnpm\[email protected]\node_modules\jiti\dist\jiti.js:1:247313)
    at Object.jiti (D:\projects\XXX\src\node_modules\.pnpm\[email protected]\node_modules\jiti\dist\jiti.js:1:245241)
    at resolveConfig (D:\projects\XXX\src\node_modules\.pnpm\[email protected]\node_modules\c12\dist\shared\c12.24612422.cjs:365:26)
    at Object.loadConfig (D:\projects\XXX\src\node_modules\.pnpm\[email protected]\node_modules\c12\dist\shared\c12.24612422.cjs:167:29)
    at Ks (D:\projects\XXX\src\node_modules\.pnpm\@[email protected][email protected]\node_modules\@hey-api\openapi-ts\dist\node\index.cjs:1:183049)
    at exports.createClient (D:\projects\XXX\src\node_modules\.pnpm\@[email protected][email protected]\node_modules\@hey-api\openapi-ts\dist\node\index.cjs:1:184996)
    at start (D:\projects\XXX\src\node_modules\.pnpm\@[email protected][email protected]\node_modules\@hey-api\openapi-ts\bin\index.cjs:80:11)
    at Object.<anonymous> (D:\projects\XXX\src\node_modules\.pnpm\@[email protected][email protected]\node_modules\@hey-api\openapi-ts\bin\index.cjs:94:1)
    at Module._compile (node:internal/modules/cjs/loader:1467:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1551:10)
    at Module.load (node:internal/modules/cjs/loader:1282:32)
    at Module._load (node:internal/modules/cjs/loader:1098:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:158:5)
    at node:internal/main/run_main_module:30:49

from openapi-ts.

SinnerAir avatar SinnerAir commented on September 22, 2024 1

Sorry. False alarm. I updated the pnpm and packages version and everything worked.

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

Thanks @swachter, will check!

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

@swachter I identified the issue, it's due to circular references in CloudProviderAccessRole, CloudProviderAccessAWSIAMRole, and CloudProviderAccessAzureServicePrincipal. I really wanted to get this fixed today for you, but it's a bit more work. :(

I made progress on untangling circular references in the parser, it's not ready for a release though. Once it's ready, can I ask you to generate types and let me know the expected result? I had it running locally earlier so I know that even when I fix circular references in the parser, they will still exist in the final types so TypeScript will complain. I suspect that might be due to incorrect implementation of discriminators, but I didn't want to look deeper into it before I fix the first part.

from openapi-ts.

StefanWachter1507 avatar StefanWachter1507 commented on September 22, 2024

Many thanks for looking into the issue! There is no hurry, I have some workaround for now. Sure, I will give it a try again, after the issue is fixed.

from openapi-ts.

AlbertoV5 avatar AlbertoV5 commented on September 22, 2024

Having trouble with circular references in my spec:

  const _mainConfig = await resolveConfig(".", options);
                            ^

RangeError: Maximum call stack size exceeded

...

🔥 Unexpected error occurred. 🚫 missing input - which OpenAPI specification should we use to generate your client?

The package openapi-typescript-codegen is able to deal with them but recommends migrating to this package.

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

@AlbertoV5 Are you able to share your spec? Just to make sure when I get to this it fixes every use case

from openapi-ts.

ryan-cat avatar ryan-cat commented on September 22, 2024

Any update on this? New user here, and I am hitting into the same issue. Though, my API is very simple and doesn't have circular references.

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

@ryan-cat can you share your OpenAPI spec?

from openapi-ts.

ryan-cat avatar ryan-cat commented on September 22, 2024

@mrlubos Attached. Thanks for looking into this.
open-api-spec.json

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.