fetchDatabaseSwagger function

Future<DatabaseSwagger?> fetchDatabaseSwagger(
  1. String url,
  2. String apiKey,
  3. Map<String, List<String>> mapOfEnums,
  4. bool jsonbToDynamic, {
  5. List<String> schemas = const ['public'],
  6. Map<String, JsonbModelConfig>? jsonbModels,
  7. Client? client,
})

Fetches the PostgREST schema of each of schemas (the first is the primary, see DatabaseSwagger.fromSchemas), or null if any fails.

Implementation

Future<DatabaseSwagger?> fetchDatabaseSwagger(String url, String apiKey,
    Map<String, List<String>> mapOfEnums, bool jsonbToDynamic,
    {List<String> schemas = const ['public'],
    Map<String, JsonbModelConfig>? jsonbModels,
    http.Client? client}) async {
  url = withScheme(url);

  try {
    final specs = <String, Map<String, dynamic>>{};
    for (final schema in schemas) {
      final spec = await _fetchSchema(url, apiKey, schema, client);
      if (spec == null) return null;
      specs[schema] = spec;
    }
    return DatabaseSwagger.fromSchemas(specs, mapOfEnums, jsonbToDynamic,
        jsonbModels: jsonbModels);
  } catch (e) {
    print("Error fetching Supabase Swagger: $e");
  }

  return null;
}