Giter VIP home page Giter VIP logo

rtk-query-codegen's Introduction

Code Generator

Discord server

Introduction

This is a utility library meant to be used with RTK Query that will generate a typed API client from an OpenAPI schema.

Usage

By default, running the CLI will only log the output to the terminal. You can either pipe this output to a new file, or you can specify an output file via CLI args.

Piping to a file (including react hooks generation)

npx @rtk-incubator/rtk-query-codegen-openapi --hooks https://petstore3.swagger.io/api/v3/openapi.json > petstore-api.generated.ts

Specifying an output file (including react hooks generation)

npx @rtk-incubator/rtk-query-codegen-openapi --file petstore-api.generated.ts --hooks https://petstore3.swagger.io/api/v3/openapi.json

Using a custom baseQuery

npx @rtk-incubator/rtk-query-codegen-openapi --file generated.api.ts --baseQuery ./customBaseQuery.ts:namedBaseQueryFn --hooks https://petstore3.swagger.io/api/v3/openapi.json

CLI Options

  • --exportName <name> - change the name of the exported api (default: api)
  • --reducerPath <path> - change the name of the reducerPath (default: api)
  • --baseQuery <file> - specify a file with a custom baseQuery function. Optionally takes a named function in that file. (default: fetchBaseQuery - ex: ./customBaseQuery.ts:myCustomBaseQueryFn)
  • --argSuffix <name> - change the suffix of the arg type (default: ApiArg - ex: AddPetApiArg)
  • --responseSuffix <name> - change the suffix of the response type (default: ApiResponse - ex: AddPetApiResponse)
  • --baseUrl <url> - set the baseUrl when using fetchBaseQuery (will be ignored if you pass --baseQuery)
  • --hooks - include React Hooks in the output (ex: export const { useGetModelQuery, useUpdateModelMutation } = api)
  • --file <filename> - specify a filename to output to (ex: ./generated.api.ts)

Documentation

View the RTK Query Code Generation docs

rtk-query-codegen's People

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.