finalize method

Future<Map<String, dynamic>> finalize()

Finalizes document and returns it as a serializable Map.

This method is invoked by the command line tool for creating OpenAPI documents.

Implementation

Future<Map<String, dynamic>> finalize() async {
  final ops = _deferredOperations;
  _deferredOperations = [];
  await Future.forEach(ops, (dynamic op) => op());

  document.paths?.values
      .expand((p) => p!.operations.values)
      .where((op) => op?.security != null)
      .expand((op) => op!.security!)
      .forEach((req) {
    req?.requirements!.forEach((schemeName, scopes) {
      final scheme = document.components!.securitySchemes[schemeName]!;
      if (scheme.type == APISecuritySchemeType.oauth2) {
        scheme.flows!.values.forEach((flow) {
          scopes.forEach((scope) {
            if (!flow!.scopes!.containsKey(scope)) {
              flow.scopes![scope] = "";
            }
          });
        });
      }
    });
  });

  return document.asMap();
}