Moonglade

Modern Markdown blogging with AI-powered localization and search.


OpenAPI client generation

This article documents the selection process and practical experience of automatically generating SDKs based on OpenAPI metadata. The author compared three libraries: `autorest`, `swagger-codegen-cli`, and `@hey-api/openapi-ts`, ultimately choosing the latter due to its superior performance in frontend environment compatibility, code conciseness, and type reuse. This choice effectively reduces the workload of manually writing request code and improves development efficiency. Using a NestJS backend and Vue frontend as examples, the article details the complete technical pipeline: configuring `nest-cli.json` to extract DTO and Entity types, utilizing a GitHub Actions pipeline to start the service in a CI environment to retrieve metadata, invoking `@hey-api/openapi-ts` to generate the SDK, and pushing it to a separate sub-repository. The frontend wraps the `@hey-api/client-fetch` client to implement unified authentication interception and error handling, directly importing the generated types and functions within Pinia Stores to achieve type safety and code reuse. This workflow not only reduces the collaboration cost between frontend and backend teams but also minimizes format errors through standardized interface definitions. Although the currently auto-generated parameter validation feature has limitations, the overall solution offers significant advantages in terms of type safety and development efficiency.

Views 385
2024 ci-cd github openapi study swagger vue work

debug vue3 source code

This article introduces a simple solution for implementing source code debugging in Vue 3 projects. The core idea is to leverage the sourcemap files generated during the Vue 3 build process, combined with VS Code debugging configuration, allowing direct execution without modifying complex configurations. The article first demonstrates how to install dependencies using `pnpm` and run the development command, resulting in build artifacts in the `dist` directory that include map files. It then provides detailed `launch.json` configuration examples covering three debugging scenarios: first, Node.js debugging for the `npm run build` script; second, debugging remotely loaded Vue projects via URL, where it is important to set `webRoot`; and third, debugging original HTML files that reference local Vue packages, requiring correct configuration of `outFiles` to map source code paths. The article also lists complete environment setup steps, including cloning the Vue core repository, creating temporary HTML test files, and creating a Vue project using the official template. This solution aims to help developers quickly establish a debugging chain from browser breakpoints to Vue source code, improving development efficiency. Plans are in place to supplement this with a debugging video demonstration in the future.

Views 59
daily sourcemap study vue vue3 web

Debug Vue3 source code (deprecated)

This article primarily shares an awkward experience of accidentally using Vue 2 source code while debugging Vue 3 source code, and elaborates in detail on the correct debugging approach and configuration methods. The core strategy is to have the Vue 3 source code generate sourcemaps and link them to the project template via a local build, replacing remote package references. Specifically, in Vue's Rollup build configuration file, you need to add `sourcemap: true` in the `output` section to enable source mapping. Regarding the debugging environment configuration, the article provides a VS Code `launch.json` example covering three debugging scenarios: first, debugging the `npm run build` build script itself; second, debugging a remote project based on the official Vue template, where you need to configure `outFiles` to correctly map the source code; and third, debugging raw HTML files, which also requires specifying the `outFiles` path to point to the local Vue source code directory. By combining local builds with source mapping, developers can more effectively track and debug Vue 3 internal logic, avoiding the difficulties of directly debugging minified code, and providing a practical technical solution for deeply understanding the framework's source code.

Views 83
2024 source-code study vue vue3 web