@otqs/core
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

npm version License: MIT

OpenAPI Generator for Tanstack Query with Solid Integration

This project is fork of orval.dev.

Code Generation

otqs is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats.

Generate, valid, cache and mock in your SolidJS applications all with your OpenAPI specification.


Installation

  • NPM: npm install otqs
  • YARN: yarn add otqs
  • PNPM: pnpm install otqs

Configuration

This package generates code that depends on the axios, @tanstack-query/solid, and solid-js packages.

  • NPM: npm install axios @tanstack/solid-query solid-js
  • YARN: yarn add axios @tanstack/solid-query solid-js
  • PNPM: pnpm install axios @tanstack/solid-query solid-js

More details: solid-query

otqs.config.ts:

import { defineConfig } from 'otqs';

export default defineConfig({
    petstore: {
        output: {
            mode: 'split',
            target: 'src/api/endpoints/petstore-endpoints.ts',
            schemas: 'src/api/model',
            client: 'solid-query',
            mock: true,
            prettier: true,
            override: {
                //Optional
                mutator: {
                    path: './src/api/mutator/custom-instance.ts',
                    name: 'customInstance',
                },
                operations: {
                    listPets: {
                        query: {
                            useQuery: true,
                            useInfinite: true,
                            useInfiniteQueryParam: 'limit',
                        },
                    }
                }
            }
        },
        input: {
            target: './petstore.yaml' //or json format
        },
    },
});

custom-instance.ts:

import Axios, { AxiosError, AxiosRequestConfig } from 'axios';

export const AXIOS_INSTANCE = Axios.create({ baseURL: '' });

export const customInstance = <T>(config: AxiosRequestConfig): Promise<T> => {
    const source = Axios.CancelToken.source();
    const promise = AXIOS_INSTANCE({ ...config, cancelToken: source.token }).then(
        ({ data }) => data,
    );

    // @ts-ignore
    promise.cancel = () => {
        source.cancel('Query was cancelled by Vue Query');
    };

    return promise;
};

export default customInstance;

export interface ErrorType<Error> extends AxiosError<Error> {}

Usage

Command for generate open-api sdk:

otqs

Example

Readme

Keywords

none

Package Sidebar

Install

npm i @otqs/core

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

462 kB

Total Files

5

Last publish

Collaborators

  • adin_sk