コード例 #1
0
ファイル: SwaggerGenMIddleware.cs プロジェクト: andycmaj/Ahoy
        private void RespondWithSwaggerJson(HttpResponse response, SwaggerDocument swagger)
        {
            response.StatusCode = 200;
            response.ContentType = "application/json";

            using (var writer = new StreamWriter(response.Body))
            {
                _swaggerSerializer.Serialize(writer, swagger);
            }
        }
コード例 #2
0
ファイル: SetVersionInPaths.cs プロジェクト: andycmaj/Ahoy
 public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
 {
     swaggerDoc.Paths = swaggerDoc.Paths.ToDictionary(
         entry => entry.Key.Replace("{version}", swaggerDoc.Info.Version),
         entry =>
         {
             var pathItem = entry.Value;
             RemoveVersionParamFrom(pathItem.Get);
             RemoveVersionParamFrom(pathItem.Put);
             RemoveVersionParamFrom(pathItem.Post);
             RemoveVersionParamFrom(pathItem.Delete);
             RemoveVersionParamFrom(pathItem.Options);
             RemoveVersionParamFrom(pathItem.Head);
             RemoveVersionParamFrom(pathItem.Patch);
             return pathItem;
         });
 }
コード例 #3
0
ファイル: SwaggerProvider.cs プロジェクト: andycmaj/Ahoy
        public SwaggerDocument GetSwagger(
            string apiVersion,
            string host = null,
            string basePath = null,
            string[] schemes = null)
        {
            var schemaRegistry = _schemaRegistryFactory.Create();

            var info = _options.ApiVersions.FirstOrDefault(v => v.Version == apiVersion);
            if (info == null)
                throw new UnknownApiVersion(apiVersion);

            var paths = GetApiDescriptionsFor(apiVersion)
                .Where(apiDesc => !(_options.IgnoreObsoleteActions && apiDesc.IsObsolete()))
                .OrderBy(_options.GroupNameSelector, _options.GroupNameComparer)
                .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString())
                .ToDictionary(group => "/" + group.Key, group => CreatePathItem(group, schemaRegistry));

            var swaggerDoc = new SwaggerDocument
            {
                Info = info,
                Host = host,
                BasePath = basePath,
                Schemes = schemes,
                Paths = paths,
                Definitions = schemaRegistry.Definitions,
                SecurityDefinitions = _options.SecurityDefinitions
            };

            var filterContext = new DocumentFilterContext(
                _apiDescriptionsProvider.ApiDescriptionGroups,
                null);

            foreach (var filter in _options.DocumentFilters)
            {
                filter.Apply(swaggerDoc, filterContext);
            }

            return swaggerDoc;
        }
コード例 #4
0
 public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
 {
     swaggerDoc.Extensions.Add("X-property1", "value");
 }