query_gen 0.2.0 copy "query_gen: ^0.2.0" to clipboard
query_gen: ^0.2.0 copied to clipboard

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

query_gen #

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();

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

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

Parameters #

  • 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
1
likes
110
pub points
0%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

args, code_builder, dart_style, http

More

Packages that depend on query_gen