build method

OpenApi build(
  1. Iterable<RouteData> routes
)

The document for routes.

Implementation

OpenApi build(Iterable<RouteData> routes) {
  OpenApiRouteReader reader = OpenApiRouteReader(config);
  ApiDoc docs = ApiDoc();
  for (RouteData route in routes) {
    if (_paths.contains(route.path) ||
        !PathConverter.isSupportedMethod(route.method) ||
        !config.documents(route.path)) {
      continue;
    }
    RouteDoc? doc = reader.read(route);
    if (doc != null) docs.add(doc);
  }
  Map<String, Map<String, dynamic>> schemas = config.registry.schemas;
  if (config.include.isNotEmpty || config.exclude.isNotEmpty) {
    schemas = _usedSchemas(docs);
  }
  for (MapEntry<String, Map<String, dynamic>> schema in schemas.entries) {
    docs.schema(schema.key, schema.value);
  }
  if (reader.usesValidationError) {
    docs.schema(
      OpenApiRouteReader.validationError,
      Dox().flags.laravelErrors
          ? _laravelErrorSchema
          : _validationErrorSchema,
    );
  }

  /// a scheme in the config wins over one found in the code
  Map<String, SecurityScheme> schemes = <String, SecurityScheme>{
    ...reader.usedSchemes,
    ...config.securitySchemes,
  };
  return OpenApi(
    info: config.info,
    servers: config.servers,
    securitySchemes: schemes,
    docs: docs,
  );
}