Inspired by rtk-query-codegen

A CLI tool for generating models and HTTP client for Dart based on OpenApi Specs(json)

Generates Dart 2.12.0 code

This tool currently doesn't support All OpenApi Features (mainly no enum support)

How To Use

First Activate it globally:

dart pub global activate code_gen

Then run it like this:

query_gen --partOf api.dart --fromUrl http://localhost:5000/swagger/v1/swagger.json > ./api.g.dart

You will need to Have to create a file to expose the generated code. for example like this:

// api.dart
library my_api;

import 'dart:convert';

import 'package:http/http.dart';

part 'api.g.dart';

class ApiClient extends BaseClient with QueryClient {
  final client = Client();

  Future<StreamedResponse> send(BaseRequest request) {
    return client.send(request);

You can customize send to add caching/retrying/authentication.


  • partOf <dart file>: The Dart file Uri to be part of
  • fromUrl <url>: Downloads the OpenApi spec from this url
  • fromFile <path>: Reads the OpenApi spec from this url