- @override
Returns an entire APIDocument
describing an OpenAPI specification.
This method is typically invoked on a RequestSink
. This method is invoked on root of documentable chain, RequestSink
.
Source
@override APIDocument documentAPI(PackagePathResolver resolver) { var doc = new APIDocument()..info = apiInfo; doc.paths = initialController.documentPaths(resolver); doc.securitySchemes = this.documentSecuritySchemes(resolver); var host = new Uri(scheme: "http", host: "localhost"); if (doc.hosts.length > 0) { host = doc.hosts.first.uri; } doc.securitySchemes?.values?.forEach((scheme) { if (scheme.isOAuth2) { var authCodePath = _authorizationPath(doc.paths); if (authCodePath != null) { scheme.authorizationURL = host.resolve(authCodePath).toString(); } var tokenPath = _authorizationTokenPath(doc.paths); if (tokenPath != null) { scheme.tokenURL = host.resolve(tokenPath).toString(); } } }); var distinct = (Iterable<ContentType> items) { var retain = <ContentType>[]; return items.where((ct) { if (!retain.any((retained) => ct.primaryType == retained.primaryType && ct.subType == retained.subType && ct.charset == retained.charset)) { retain.add(ct); return true; } return false; }).toList(); }; doc.consumes = distinct( doc.paths.expand((p) => p.operations.expand((op) => op.consumes))); doc.produces = distinct( doc.paths.expand((p) => p.operations.expand((op) => op.produces))); return doc; }