Ejemplo n.º 1
0
 public DefaultSwaggerMetadataConverter(
     IRouteCacheProvider routeCacheProvider,
     ISwaggerModelCatalog modelCatalog)
 {
     _routeCacheProvider = routeCacheProvider;
     _modelCatalog       = modelCatalog;
 }
        public CreateBarcodeMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModels(typeof(CreateBarCodeResponse), typeof(CreateBarCodeResponse));

            Describe["GetBarcode"] = desc => desc.AsSwagger(
                with => with.Operation(
                    op => op.OperationId("GetBarcode")
                    .Tag("BarCode")
                    .Summary("Returns bytes of barcode")
                    .Description("Returns bytes of barcode")
                    //specify the parameters of this api
                    .Parameter(new Parameter
            {
                Name = "text",
                //specify the type of this parameter is path
                In = ParameterIn.Path,
                //specify this parameter is required or not
                Required    = true,
                Description = "text to embed into code"
            })
                    .Parameter(new Parameter
            {
                Name = "checkSumEnabled",
                //specify the type of this parameter is path
                In = ParameterIn.Path,
                //specify this parameter is required or not
                Required    = true,
                Description = "enable checksum on barcode"
            })
                    .Response(r => r.Schema <CreateBarCodeResponse>(modelCatalog).Description("Returns barcode bytes"))
                    .Response(404, r => r.Description("Can't find stuffs"))
                    ));
        }
Ejemplo n.º 3
0
        public static Schema GetSchema(ISwaggerModelCatalog modelCatalog, Type t, bool isDefinition)
        {
            if (SwaggerTypeMapping.IsMappedType(t))
            {
                t = SwaggerTypeMapping.GetMappedType(t);
            }
            var model  = modelCatalog.GetModelForType(t);
            var schema = new Schema();

            if (model != null)
            {
                schema = model.GetSchema(isDefinition);
            }
            else if (Primitive.IsPrimitive(t))
            {
                var primitive = Primitive.FromType(t);

                schema.Type = primitive.Type.ToLower();
                if (!string.IsNullOrEmpty(primitive.Format))
                {
                    schema.Format = primitive.Format.ToLower();
                }
            }
            return(schema);
        }
Ejemplo n.º 4
0
        public ApiMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModels(typeof(User), typeof(Address), typeof(Role));
            Describe["GetUsers"] = description => description.AsSwagger(
                with => with.Operation(
                    op => op.OperationId("GetUsers")
                    .Tag("Users")
                    .Summary("The list of users")
                    .Description("This returns a list of users from our awesome app")
                    .Response(r => r.Schema <User>().Description("The list of users"))));


            Describe["PostUsers"] =
                description =>
                description.AsSwagger(
                    with =>
                    with.Operation(
                        op =>
                        op.OperationId("PostUsers")
                        .Tag("Users")
                        .Summary("Create a User")
                        .Description("Creates a user with the shown schema for our awesome app")
                        .Response(201, r => r.Description("Created a User"))
                        .Response(422, r => r.Description("Invalid input"))
                        .BodyParameter(p => p.Description("A User object").Name("user").Schema <User>())));
        }
Ejemplo n.º 5
0
        public InfoMetadataModule(ISwaggerModelCatalog _)
        {
            this.Describe["Info"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("Info")
                        .Tag("Info")
                        .Summary("Deployment Info")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .SecurityRequirement(SecuritySchemes.ApiKey)
                        .Response(x => x.Description("Deployment Info").Build()))
                    );

            this.Describe["Auth"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("Auth")
                        .Tag("Info")
                        .Summary("Auth status")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .Response(x => x.Description("Shows the status of the provided API key").Build()))
                    );
        }
Ejemplo n.º 6
0
        public PrometheusMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModels(
                typeof(Prometheus),
                typeof(ScrapeConfigs),
                typeof(Global),
                typeof(StaticConfigs),
                typeof(BuildConfiguration),
                typeof(BuildConfigurationInput),
                typeof(Config <Prometheus>),
                typeof(Input <Prometheus>)
                );

            this.Describe["DeployPrometheus"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("DeployPrometheus")
                        .Tag("Deploy")
                        .Summary("Deploy Prometheus")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .SecurityRequirement(SecuritySchemes.ApiKey)
                        .BodyParameter(
                            para =>
                            para.Name("Build")
                            .Schema(
                                new Schema()
            {
                Example = Defaults.Prometheus
            }
                                )
                            .Build()
                            ).Response(x => x.Description("Container UUID").Build()))
                    );
        }
Ejemplo n.º 7
0
        public PrincipalsMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
            : base(modelCatalog, tagCatalog)
        {
            modelCatalog.AddModel <FabricPrincipalApiModel>();

            RouteDescriber.DescribeRouteWithParams(
                "Search",
                "",
                "Searches for users and groups in an identity provider",
                new[]
            {
                new HttpResponseMetadata <IdpSearchResultApiModel>
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "Search was successful"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "Invalid type parameter provided"
                }
            },
                new[]
            {
                _searchTextParameter,
                _typeParameter
            },
                new[]
            {
                _searchTag
            }).SecurityRequirement(_oAuth2SearchScopeBuilder);
        }
Ejemplo n.º 8
0
        public ServiceDetailsModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog) : base("/service")
        {
            modelCatalog.AddModel <ServiceOwner>();
            modelCatalog.AddModel <Widget>();

            tagCatalog.AddTag(new Tag()
            {
                Name        = ServiceTagName,
                Description = ServiceTagDescription
            });

            Get("/", _ => GetHome(), null, "ServiceHome");

            Get("/details", _ => GetServiceDetails(), null, "GetDetails");

            Get("/widgets", _ => GetWidgets(), null, "GetWidgets");

            Get("/customers", _ => GetServiceCustomers(), null, "GetCustomers");

            //shows massaging multiple query params into single handler parameter.
            Get("/customerspaged", _ => GetServiceCustomersPaged(GetRequestPaging()), null, "GetCustomersPaged");

            Get("/customers/{name}", parameters => GetServiceCustomer(parameters.name), null, "GetCustomer");

            Post("/customer/{serviceGuid:guid}", parameters => PostServiceCustomer(parameters.serviceGuid, this.Bind <ServiceCustomer>()), null, "PostNewCustomer");

            Post("/customer/{name}/file", parameters => PostCustomerReview(parameters.name, null), null, "PostCustomerReview");
        }
 public SwaggerAnnotationsProvider(INancyModuleCatalog moduleCatalog, NancyContext context, ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
 {
     _moduleCatalog = moduleCatalog;
     _context = context;
     _modelCatalog = modelCatalog;
     _tagCatalog = tagCatalog;
 }
Ejemplo n.º 10
0
        public AnnotatedOperation(string name, MethodInfo handler, ISwaggerModelCatalog modelCatalog)
        {
            _modelCatalog = modelCatalog;

            OperationId = name;

            if (handler == null)
            {
                Description = "This route is not annotated. Please see " +
                              "https://github.com/yahehe/Nancy.Swagger/wiki/Nancy.Swagger-for-Nancy-v2 " +
                              "for information on how to annotate routes or to hide unannotated routes.";
                Summary = "Warning: no annotated method found for this route";

                return;
            }

            foreach (var attr in handler.GetCustomAttributes <RouteAttribute>())
            {
                Summary      = attr.Summary ?? Summary;
                Description  = attr.Notes ?? Description;
                ResponseType = attr.Response ?? ResponseType;
                Consumes     = attr.Consumes ?? Consumes;
                Produces     = attr.Produces ?? Produces;
                Tags         = attr.Tags ?? Tags;
            }

            Responses = handler.GetCustomAttributes <SwaggerResponseAttribute>()
                        .Select(CreateSwaggerResponseObject)
                        .ToDictionary(x => x.GetStatusCode().ToString(), y => (global::Swagger.ObjectModel.Response)y);


            Parameters = handler.GetParameters().Where(x => x.GetCustomAttributes <RouteParamAttribute>().Any())
                         .Select(CreateSwaggerParameterData)
                         .ToList();
        }
 public V2SwaggerMetadataProvider(
     IRouteCacheProvider routeCacheProvider,
     ISwaggerModelCatalog modelCatalog)
 {
     _routeCacheProvider = routeCacheProvider;
     _modelCatalog       = modelCatalog;
 }
Ejemplo n.º 12
0
        public TelegrafMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModels(
                typeof(Telegraf),
                typeof(Agent),
                typeof(Outputs),
                typeof(Inputs),
                typeof(PrometheusClient),
                typeof(VSphere),
                typeof(BuildConfiguration),
                typeof(BuildConfigurationInput),
                typeof(Internal),
                typeof(Config <Telegraf>),
                typeof(Input <Telegraf>)
                );

            this.Describe["DeployTelegraf"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("DeployTelegraf")
                        .Tag("Deploy")
                        .Summary("Deploy Telegraf")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .SecurityRequirement(SecuritySchemes.ApiKey)
                        .BodyParameter(
                            para =>
                            para.Name("Build")
                            .Schema(
                                new Schema()
            {
                Example = Defaults.Telegraf
            }
                                )
                            .Build()
                            ).Response(x => x.Description("Container UUID").Build()))
                    );

            this.Describe["DeployVCSim"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("DeployVCSim")
                        .Tag("Deploy")
                        .Summary("Deploy VC Simulator")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .SecurityRequirement(SecuritySchemes.ApiKey)
                        .BodyParameter(
                            para =>
                            para.Name("Build")
                            .Schema(
                                new Schema()
            {
                Example = Defaults.VCSim
            }
                                )
                            .Build()
                            ).Response(x => x.Description("Container UUID").Build()))
                    );
        }
Ejemplo n.º 13
0
        public CafeModule(ISwaggerModelCatalog modelCatalog) : base("/cafe")
        {
            modelCatalog.AddModel <CafeMenu>();
            modelCatalog.AddModel <MenuItem>();

            Get(
                "/menu",
                parameter =>
            {
                var cafeMenuQuery = new CafeMenuQuery
                {
                    Page          = Request.Query.page ?? 1,
                    PageCount     = Request.Query.pagecount ?? 10,
                    Sort          = Request.Query.sort ?? null,
                    SortDirection = Request.Query.sortdirection ?? null,
                    MinumumPrice  = Request.Query.minimumprice ?? Double.MinValue,
                    MaximumPrice  = Request.Query.maximumprice ?? Double.MaxValue,
                    VeganOnly     = Request.Query.veganonly ?? null,
                    Category      = string.IsNullOrEmpty(Request.Query.category) ? MenuCategory.All  : Enum.Parse(typeof(MenuCategory), Request.Query.category),
                };

                return(GetMenu(cafeMenuQuery));
            },
                null,
                "GetMenu");
        }
 public DefaultSwaggerMetadataProvider(
     IRouteCacheProvider routeCacheProvider,
     ISwaggerModelCatalog modelCatalog)
 {
     _routeCacheProvider = routeCacheProvider;
     _modelCatalog = modelCatalog;
 }
        public ServiceDetailsMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog) :base (modelCatalog, tagCatalog)
        {
            RouteDescriber.AddBaseTag(new Tag()
            {
                Description = "Operations for handling the service",
                Name = "Service"
            });

            var customerSubTag = new Tag()
            {
                Name = "Service/Customers",
                Description = "Operations of 'Service' relating to Customers"
            };

            RouteDescriber.DescribeRoute("ServiceHome", "", "Get Home", new[]
            {
                new HttpResponseMetadata {Code = 200, Message = "OK"}
            });

            RouteDescriber.AddAdditionalModels(typeof(ServiceOwner), typeof(ServiceCustomer));
            RouteDescriber.DescribeRoute<ServiceDetails>("GetDetails", "", "Get Details", new[]
            {
                new HttpResponseMetadata {Code = 200, Message = "OK"}
            });

            RouteDescriber.DescribeRoute<IEnumerable<ServiceCustomer>>("GetCustomers", "", "Get Customers", new[]
            {
                new HttpResponseMetadata {Code = 200, Message = "OK"}
            }, new[]
            {
                customerSubTag
            });

            RouteDescriber.DescribeRouteWithParams("GetCustomer", "", "Get Customer", new HttpResponseMetadata[] 
            {
                new HttpResponseMetadata<ServiceCustomer> {Code = 200, Message = "OK"},
                new HttpResponseMetadata<IEnumerable<ServiceCustomer>> {Code = 202, Message = "Multiple Customers Found"},
                new HttpResponseMetadata {Code = 404, Message = "No Customers Found"},

            }, new[]
            {
                new Parameter{Name = "name", In = ParameterIn.Path, Required = true, Description = "The customer's name", Default = "Jack", Type = "string" }
            }, new[]
            {
                customerSubTag
            });

            RouteDescriber.DescribeRouteWithParams<ServiceCustomer>("PostNewCustomer", "", "Add a new customer", new[]
            {
                new HttpResponseMetadata { Code = 200, Message = "Customer Added"},
            }, new[]
            {
                new Parameter{Name = "service", In = ParameterIn.Path, Required = true, Description = "The service's name", Default = "Nancy Swagger Service", Type = "string" },
                new BodyParameter<ServiceCustomer>(ModelCatalog) {Name = "user",  Required = true, Description = "The user"}, 
            }, new []
            {
                customerSubTag
            });
        }
Ejemplo n.º 16
0
        public GrafanaMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModels(
                typeof(Grafana),
                typeof(string),
                typeof(BuildConfiguration),
                typeof(BuildConfigurationInput),
                typeof(Config <Grafana>),
                typeof(Input <Grafana>)
                );

            this.Describe["DeployGrafana"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("DeployGrafana")
                        .Tag("Deploy")
                        .Summary("Deploy Grafana")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .SecurityRequirement(SecuritySchemes.ApiKey)
                        .BodyParameter(
                            para =>
                            para.Name("Build")
                            .Schema(
                                new Schema()
            {
                Example = Defaults.Grafana
            }
                                )
                            .Build()
                            ).Response(x => x.Description("Container UUID").Build()))
                    );

            this.Describe["DeployGrafanaDataSource"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("DeployGrafanaDataSource")
                        .Tag("Config")
                        .Summary("Add Grafana DataSource")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .SecurityRequirement(SecuritySchemes.ApiKey)
                        .Response(x => x.Description("Container UUID").Build()))
                    );

            this.Describe["DeployGrafanaDashboard"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("DeployGrafanaDashboard")
                        .Tag("Config")
                        .Summary("Add Grafana Dashboard")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .SecurityRequirement(SecuritySchemes.ApiKey)
                        .Response(x => x.Description("Container UUID").Build()))
                    );
        }
Ejemplo n.º 17
0
 public DemoMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog) : base(modelCatalog, tagCatalog)
 {
     RouteDescriber.DescribeRoute("Demo", string.Empty, string.Empty, new []
     {
         new HttpResponseMetadata {
             Code = 200, Message = "OK"
         },
     }, null);
 }
Ejemplo n.º 18
0
        public AnnotatedResponse(SwaggerResponseAttribute attr, ISwaggerModelCatalog modelCatalog)
        {
            Description = attr.Message;
            StatusCode  = (int)attr.Code;

            if (attr.Model != null)
            {
                Schema = SwaggerExtensions.GetSchema(modelCatalog, attr.Model);
            }
        }
Ejemplo n.º 19
0
        public AnnotatedResponse(SwaggerResponseAttribute attr, ISwaggerModelCatalog modelCatalog)
        {
            Description = attr.Message;
            StatusCode = (int) attr.Code;

            if (attr.Model != null)
            {
                Schema = modelCatalog.GetModelForType(attr.Model)?.GetSchema();
            }
        }
Ejemplo n.º 20
0
        public AnnotatedOperation(string name, MethodInfo handler, ISwaggerModelCatalog modelCatalog)
        {
            _modelCatalog = modelCatalog;

            OperationId = name;

            if (handler == null)
            {
                Description = "This route is not annotated. Please see " +
                              "https://github.com/yahehe/Nancy.Swagger/wiki/Nancy.Swagger-for-Nancy-v2 " +
                              "for information on how to annotate routes or to hide unannotated routes.";
                Summary = "Warning: no annotated method found for this route";

                return;
            }

            foreach (var attr in handler.GetCustomAttributes <RouteAttribute>())
            {
                Summary      = attr.Summary ?? Summary;
                Description  = attr.Notes ?? Description;
                ResponseType = attr.Response ?? ResponseType;
                Consumes     = attr.Consumes ?? Consumes;
                Produces     = attr.Produces ?? Produces;
                Tags         = attr.Tags ?? Tags;
            }

            foreach (var attr in handler.GetCustomAttributes <RouteSecurityAttribute>())
            {
                if (SecurityRequirements == null)
                {
                    SecurityRequirements = new Dictionary <SecuritySchemes, IEnumerable <string> >();
                }

                SecurityRequirements[attr.Scheme] = attr.Scopes ?? new string[0];
            }

            try
            {
                Responses = handler.GetCustomAttributes <SwaggerResponseAttribute>()
                            .Select(CreateSwaggerResponseObject)
                            .ToDictionary(x => x.GetStatusCode().ToString(), y => (global::Swagger.ObjectModel.Response)y);
            }
            catch (ArgumentException e) when(e.Message == "An item with the same key has already been added.")
            {
                throw new Exception($"Duplicated status code found at operation {name}");
            }

            var paramsList = new List <Parameter>();

            CreateSwaggerParametersFromMethodAttributes(handler, paramsList);
            CreateSwaggerParametersFromParameters(handler, paramsList);
            Parameters = paramsList;
        }
Ejemplo n.º 21
0
        public StatisticsMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
            : base(modelCatalog, tagCatalog)
        {
            SwaggerTypeMapping.AddTypeMapping(typeof(DateTime), typeof(DateTime));

            RouteDescriber.AddBaseTag(new Tag
            {
                Description = "Operations for getting projection statistics",
                Name        = "Statistics"
            });

            RouteDescriber.DescribeRoute <IEnumerable <ProjectorSummary> >("GetAll", "",
                                                                           "Returns a list of all known projectors and a summary of their status", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            });

            RouteDescriber
            .DescribeRoute <ProjectorDetails>("GetSpecific", "", "Returns the details of a specific projector", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            })
            .Parameter(p => p.Name("id").In(ParameterIn.Path).Description("Identifies the projector"));


            RouteDescriber
            .DescribeRoute <ProjectorEventCollection>("GetEvents", "", "Returns the events logged for a specific projector", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            })
            .Parameter(p => p.Name("id").In(ParameterIn.Path).Description("Identifies the projector"));;

            RouteDescriber
            .DescribeRoute <string>("GetEta", "", "Returns the ETA for a specific projector to reach a certain checkpoint", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            })
            .Parameter(p => p.Name("id").In(ParameterIn.Path).Description("Identifies the projector"))
            .Parameter(p => p.Name("targetCheckpoint").In(ParameterIn.Path).Description("The target checkpoint for which to calculate the ETA"));

            RouteDescriber.AddAdditionalModels(
                typeof(ProjectorEvent), typeof(ProjectorProperty), typeof(ProjectorSummary));
        }
        public IdentitySearchMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
            : base(modelCatalog, tagCatalog)
        {
            modelCatalog.AddModels(
                typeof(IdentitySearchRequest),
                typeof(IdentitySearchResponse));

            RouteDescriber.DescribeRouteWithParams(
                "GetIdentities",
                string.Empty,
                "Searches for users and (non-custom) groups by client ID and other optional parameters.",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <IEnumerable <IdentitySearchResponse> >
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "OK"
                },
                new HttpResponseMetadata <IEnumerable <IdentitySearchResponse> >
                {
                    Code    = (int)Nancy.HttpStatusCode.PartialContent,
                    Message = "Partial success (e.g., results were found in Fabric.Authorization but the call out to Fabric.Identity failed). Properties populated by Fabric.Identity data are FirstName, MiddleName, LastName, and LastLoginDateTimeUtc."
                },
                new HttpResponseMetadata
                {
                    Code    = (int)Nancy.HttpStatusCode.Forbidden,
                    Message = "Client does not have the required scopes to read data in Fabric.Authorization (fabric/authorization.read)."
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)Nancy.HttpStatusCode.BadRequest,
                    Message = "Group already exists"
                }
            },
                new[]
            {
                _clientIdParameter,
                PageNumberParameter,
                PageSizeParameter,
                FilterParameter,
                SortKeyParameter,
                SortDirectionParameter
            },
                new[]
            {
                _searchTag
            }).SecurityRequirement(OAuth2ReadScopeBuilder);
        }
Ejemplo n.º 23
0
        public static Schema GetSchema <T>(ISwaggerModelCatalog modelCatalog)
        {
            var t      = typeof(T);
            var model  = modelCatalog.GetModelForType <T>();
            var schema = new Schema();

            if (model != null)
            {
                schema = model.GetSchema();
            }
            else if (t.IsPrimitive || t == typeof(string))
            {
                schema.Type = t.Name.ToLower();
            }
            return(schema);
        }
Ejemplo n.º 24
0
        public HealthMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModels(typeof(HealthResponse), typeof(HealthResponse));

            Describe["GetHealth"] = desc => desc.AsSwagger(
                with => with.Operation(
                    op => op.OperationId("GetHealth")
                        .Tag("Health")
                        .Summary("Returns a message if the endpoint can be reached")
                        .Description("Returns a message if the endpoint can be reached")
                        .Response(r => r.Schema<HealthResponse>(modelCatalog).Description("Here is the health status"))
                        .Response(404, r => r.Description("Can't find stuffs"))
                ));

            Describe["GetDateTime"] = desc => desc.AsSwagger(
                with => with.Operation(
                    op => op.OperationId("GetDateTime")
                        .Tag("Health")
                        .Summary("Returns a message with server datetime")
                        .Description("Returns a message with server datetime")
                        //specify the parameters of this api
                        .Parameter(new Parameter
                        {
                            Name = "isLongFormat",
                            //specify the type of this parameter is path
                            In = ParameterIn.Path,
                            //specify this parameter is required or not
                            Required = true,
                            Description = "returns long format of datetime if true"
                        })
                        .Response(r => r.Schema<HealthResponse>(modelCatalog).Description("Returns timestamp from server"))
                        .Response(404, r => r.Description("Can't find stuffs"))
                ));

            Describe["GetManual"] = desc => desc.AsSwagger(
                with => with.Operation(
                    op => op.OperationId("GetManaul")
                        .Tag("Health")
                        .Summary("Returns a pdf of the system manual")
                        .Description("Returns a pdf of the system manual")
                        .ProduceMimeType("application/pdf")
                        .Response(r => r.Schema<Stream>(modelCatalog).Description("Pdf manual"))
                        .Response(404, r => r.Description("Can't find stuffs"))
                ));
        }
Ejemplo n.º 25
0
        public GetEmailItemMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModel <EmailDto>();
            modelCatalog.AddModel <EmailState>();

            Describe[nameof(GetEmailItemModule)] = description => description.AsSwagger(
                with => with.Operation(
                    op => op.OperationId(nameof(GetEmailItem))
                    .Tag(nameof(GetEmailItem))
                    .Summary("Получить информацию о email-сообщении")
                    .Parameter(p => p.In(ParameterIn.Path).Name("id").Description("id сообщения"))
                    .Response(
                        (int)HttpStatusCode.NotFound, r => r.Description("Email с таким id не найден"))
                    .Response(
                        (int)HttpStatusCode.OK,
                        r => r.Description("Email-сообщение").Schema <EmailDto>())
                    ));
        }
Ejemplo n.º 26
0
        public DefaultMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModels(
                typeof(DefaultSettings),
                typeof(Input)
                );

            this.Describe["Default"] =
                desc => desc.AsSwagger(
                    with => with.Operation(
                        op => op.OperationId("Default")
                        .Tag("Info")
                        .Summary("Default Data")
                        .ConsumeMimeType("application/json")
                        .ProduceMimeType("application/json")
                        .SecurityRequirement(SecuritySchemes.ApiKey)
                        .Response(x => x.Description("Returns an object containing all default settings").Build()))
                    );
        }
        public RenderReportMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModels(typeof(RenderReportRequest), typeof(RenderReportRequest));

            Describe["PostReport"] = desc => desc.AsSwagger(
                with => with.Operation(
                    op => op.OperationId("PostReport")
                    .Tag("Report")
                    .Summary("Returns pdf report")
                    .Description("Returns pdf report")
                    //specify the parameters of this api
                    .Parameter(new Parameter
            {
                Name = "RenderReportRequest",
                //specify the type of this parameter is path
                In = ParameterIn.Body,
                //specify this parameter is required or not
                Required    = true,
                Description = "text to embed into code",
                Default     = new {
                    FileName     = "DemoForm.pdf",
                    ListOfFields = "[]",
                    QrCodeData   = new {
                        Text            = "unique id here",
                        CheckSumEnabled = true
                    },
                    attachQrCodeRequest = new{
                        PageNumber  = 1,
                        LowerLeftX  = 100f,
                        LowerLeftY  = 100f,
                        UpperRightX = 200f,
                        UpperRightY = 200f,
                    },
                    Password = "******"
                },
            })
                    .Response(r => r.Schema <Stream>(modelCatalog).Description("Returns report"))
                    .Response(404, r => r.Description("Can't find stuffs"))
                    ));
        }
Ejemplo n.º 28
0
        public ServiceDetailsModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog) : base("/service")
        {
            modelCatalog.AddModel <ServiceOwner>();

            tagCatalog.AddTag(new Tag()
            {
                Name        = ServiceTagName,
                Description = ServiceTagDescription
            });

            Get("/", _ => GetHome(), null, "ServiceHome");

            Get("/details", _ => GetServiceDetails(), null, "GetDetails");

            Get("/customers", _ => GetServiceCustomers(), null, "GetCustomers");

            Get("/customers/{name}", parameters => GetServiceCustomer(parameters.name), null, "GetCustomer");

            Post("/customer/{service}", parameters => PostServiceCustomer(parameters.service, this.Bind <ServiceCustomer>()), null, "PostNewCustomer");

            Post("/customer/{name}/file", parameters => PostCustomerReview(parameters.name, null), null, "PostCustomerReview");
        }
Ejemplo n.º 29
0
        public ServiceDetailsModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog) : base("/service")
        {
            modelCatalog.AddModel<ServiceOwner>();

            tagCatalog.AddTag(new Tag()
            {
                Name = ServiceTagName,
                Description = ServiceTagDescription
            });

            Get("/", _ => GetHome(), null, "ServiceHome");

            Get("/details", _ => GetServiceDetails(), null, "GetDetails");

            Get("/customers", _ => GetServiceCustomers(), null, "GetCustomers");

            Get("/customers/{name}", parameters => GetServiceCustomer(parameters.name), null, "GetCustomer");

            Post("/customer/{service}", parameters => PostServiceCustomer(parameters.service, this.Bind<ServiceCustomer>()), null, "PostNewCustomer");


        }
Ejemplo n.º 30
0
        public SendEmailMetadataModule(ISwaggerModelCatalog modelCatalog)
        {
            modelCatalog.AddModel <SendEmail>();

            Describe[nameof(SendEmailModule)] = description => description.AsSwagger(
                with => with.Operation(
                    op => op.OperationId(nameof(SendEmail))
                    .Tag(nameof(SendEmail))
                    .Summary("Отправка email-сообщения")
                    .ConsumeMimeType("application/json")
                    .BodyParameter(p => p.Name("body").Schema <SendEmail>())
                    .Response(
                        (int)HttpStatusCode.UnprocessableEntity, r => r.Description("Невалидные данные"))
                    .Response(
                        (int)HttpStatusCode.Created,
                        r => r.Description("Успех").Header(
                            "Location",
                            new Header {
                Description = description.Path + "{id}"
            }))
                    ));

            Describe[nameof(SendEmailModule) + "_id"] = description => description.AsSwagger(
                with => with.Operation(
                    op => op.OperationId(nameof(SendEmail) + "_id")
                    .Tag(nameof(SendEmail))
                    .Summary("Отправка email-сообщения (с указанием id)")
                    .Parameter(p => p.In(ParameterIn.Path).Name("id").Description("id сообщения"))
                    .ConsumeMimeType("application/json")
                    .BodyParameter(p => p.Name("body").Schema <SendEmail>())
                    .Response(
                        (int)HttpStatusCode.UnprocessableEntity, r => r.Description("Невалидные данные"))
                    .Response(
                        (int)HttpStatusCode.Created,
                        r => r.Description("Успех"))
                    ));
        }
Ejemplo n.º 31
0
        public AnnotatedOperation(string name, MethodInfo handler, ISwaggerModelCatalog modelCatalog)
        {
            _modelCatalog = modelCatalog;

            OperationId = name;

            if (handler == null)
            {
                Description = "This route is not annotated. Please see " +
                              "https://github.com/yahehe/Nancy.Swagger/wiki/Nancy.Swagger-for-Nancy-v2 " +
                              "for information on how to annotate routes or to hide unannotated routes."; 
                Summary = "Warning: no annotated method found for this route";

                return;
            }
            
            foreach (var attr in handler.GetCustomAttributes<RouteAttribute>())
            {
                Summary = attr.Summary ?? Summary;
                Description = attr.Notes ?? Description;
                ResponseType = attr.Response ?? ResponseType;
                Consumes = attr.Consumes ?? Consumes;
                Produces = attr.Produces ?? Produces;
                Tags = attr.Tags ?? Tags;
            }

            Responses = handler.GetCustomAttributes<SwaggerResponseAttribute>()
                .Select(CreateSwaggerResponseObject)
                .ToDictionary(x => x.StatusCode.ToString(), y => (global::Swagger.ObjectModel.Response) y);


            Parameters = handler.GetParameters()
                .Select(CreateSwaggerParameterData)
                .ToList();

        }
Ejemplo n.º 32
0
        public ValueSetMetadataModule(
            ISwaggerModelCatalog modelCatalog,
            ISwaggerTagCatalog tagCatalog,
            TerminologySqlSettings settings)
            : base(modelCatalog, tagCatalog)
        {
            modelCatalog.AddModels(
                typeof(CodeSetCodeApiModel),
                typeof(CodeSystem),
                typeof(FindByTermQuery),
                typeof(PagedCollection <ValueSetApiModel>),
                typeof(PagerSettings),
                typeof(ValueSetApiModel),
                typeof(ValueSetCodeApiModel),
                typeof(ValueSetCreationApiModel));

            // /{valueSetId}
            this.RouteDescriber.DescribeRouteWithParams(
                "GetValueSet",
                "Returns one or more ValueSet(s) by ValueSetUniqueId(s)",
                "Gets a ValueSet by it's ValueSetUniqueId or a collection of ValueSets by CSV of ValueSetUniqueId(s)",
                new[]
            {
                new HttpResponseMetadata <ValueSetApiModel> {
                    Code = 200, Message = "OK"
                },
                new HttpResponseMetadata {
                    Code = 404, Message = "Not Found"
                },
                new HttpResponseMetadata {
                    Code = 500, Message = "Internal Server Error"
                }
            },
                new[] { ParameterFactory.GetValueSetIdArray(), ParameterFactory.GetSummary(), ParameterFactory.GetCodeSystemCodesArray() },
                new[] { TagsFactory.GetValueSetTag() });

            this.RouteDescriber.DescribeRouteWithParams(
                "GetPaged",
                "Returns a paged list of ValueSets",
                "Gets a paged collection of ValueSets",
                new[]
            {
                new HttpResponseMetadata <PagedCollection <ValueSetApiModel> > {
                    Code = 200, Message = "OK"
                },
                new HttpResponseMetadata {
                    Code = 500, Message = "Internal Server Error"
                }
            },
                new[]
            {
                ParameterFactory.GetSkip(),
                ParameterFactory.GetTop(settings.DefaultItemsPerPage),
                ParameterFactory.GetSummary(),
                ParameterFactory.GetCodeSystemCodesArray()
            },
                new[] { TagsFactory.GetValueSetTag() });


            this.RouteDescriber.DescribeRouteWithParams(
                "Find",
                "Search by 'Name' of ValueSet operation",
                "Gets a paged collection of ValueSet's matching the 'Name' filter",
                new[]
            {
                new HttpResponseMetadata <PagedCollection <ValueSetApiModel> > {
                    Code = 200, Message = "OK"
                },
                new HttpResponseMetadata {
                    Code = 500, Message = "Internal Server Error"
                }
            },
                new[]
            {
                //ParameterFactory.GetContentType(),
                new BodyParameter <FindByTermQuery>(modelCatalog)
                {
                    Required = false
                }
            },
                new[] { TagsFactory.GetValueSetFindTag() });

            this.RouteDescriber.DescribeRouteWithParams(
                "AddValueSet",
                "Creates a new value set",
                "Creates a new value set",
                new[]
            {
                new HttpResponseMetadata <ValueSetApiModel> {
                    Code = 200, Message = "OK"
                },
                new HttpResponseMetadata {
                    Code = 500, Message = "Internal Server Error"
                }
            },
                new[]
            {
                //ParameterFactory.GetContentType(),
                new BodyParameter <ValueSetCreationApiModel>(modelCatalog)
                {
                    Required = true
                }
            },
                new[]
            {
                TagsFactory.GetValueSetTag()
            });
        }
        public UsersMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
            : base(modelCatalog, tagCatalog)
        {
            ModelCatalog.AddModels(typeof(PermissionAction));
            ModelCatalog.AddModels(typeof(PermissionRoleApiModel));
            ModelCatalog.AddModels(typeof(ResolvedPermissionApiModel));
            ModelCatalog.AddModels(typeof(UserApiModel));
            ModelCatalog.AddModels(typeof(List <RoleApiModel>));
            ModelCatalog.AddModels(typeof(PermissionRequestContext));

            RouteDescriber.DescribeRouteWithParams(
                "AddUser",
                "",
                "Adds a new user.",
                new []
            {
                new HttpResponseMetadata <UserApiModel>
                {
                    Code    = (int)HttpStatusCode.Created,
                    Message = "Created"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "User does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "User object in body failed validation"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.Conflict,
                    Message = "User with specified IdentityProvider and Subject already exists"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.UnsupportedMediaType,
                    Message = "Content-Type header was not included in request"
                }
            },
                new[]
            {
                new BodyParameter <UserApiModel>(modelCatalog)
                {
                    Name        = "User",
                    Description = "The user to add"
                }
            },
                new []
            {
                _usersTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "AddRolesToUser",
                "",
                "Adds roles to an existing user.",
                new[]
            {
                new HttpResponseMetadata <UserApiModel>
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "Roles added."
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "User does not have access to add the specified roles."
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "List of roles in body failed validation"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Specified user does not exist"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.UnsupportedMediaType,
                    Message = "Content-Type header was not included in request"
                }
            },
                new[]
            {
                new BodyParameter <List <RoleApiModel> >(modelCatalog)
                {
                    Name        = "Roles",
                    Description = "The roles to add"
                }
            },
                new[]
            {
                _usersTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "DeleteRolesFromUser",
                "",
                "Deletes roles from existing user.",
                new[]
            {
                new HttpResponseMetadata <UserApiModel>
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "Roles deleted."
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "User does not have access to add the specified roles."
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "List of roles in body failed validation"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Specified user does not exist"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.UnsupportedMediaType,
                    Message = "Content-Type header was not included in request"
                }
            },
                new[]
            {
                new BodyParameter <List <RoleApiModel> >(modelCatalog)
                {
                    Name        = "Roles",
                    Description = "The roles to delete."
                }
            },
                new[]
            {
                _usersTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            RouteDescriber.DescribeRoute(
                "GetCurrentUserPermissions",
                "",
                "Gets permissions for currently authenticated user",
                new[]
            {
                new HttpResponseMetadata <UserPermissionsApiModel> {
                    Code = (int)HttpStatusCode.OK, Message = "OK"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                }
            },
                new[]
            {
                _usersTag
            }).SecurityRequirement(OAuth2ReadScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "GetUserPermissions",
                "",
                "Gets permissions for specified user. Note this will only retrieve 1) granular permissions and 2) permissions under roles mapped to Custom groups.",
                new[]
            {
                new HttpResponseMetadata <List <ResolvedPermissionApiModel> > {
                    Code = (int)HttpStatusCode.OK, Message = "OK"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                }
            },
                new[]
            {
                _identityProviderParameter,
                _subjectIdParameter
            },
                new[]
            {
                _usersTag
            }).SecurityRequirement(OAuth2ReadScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "AddGranularPermissions",
                "",
                "Adds granular permissions for a user, either to allow or deny",
                new[]
            {
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.NoContent,
                    Message = "Granular permissions were added"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "No permissions to add included in request."
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Conflict,
                    Message = "The permissions specified already exist either as duplicates or with a different permission action than the one specified or a permission is in the request as both allow and deny"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.UnsupportedMediaType,
                    Message = "Content-Type header was not included in request"
                }
            },
                new[]
            {
                _identityProviderParameter,
                _subjectIdParameter,
                new BodyParameter <List <PermissionApiModel> >(modelCatalog)
                {
                    Name        = "GranularPermissions",
                    Description = "The permissions to add for the user."
                }
            },
                new[]
            {
                _usersTag
            }).SecurityRequirement(OAuth2ManageClientsScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "DeleteGranularPermissions",
                "",
                "Deletes granular permissions for a user",
                new[]
            {
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.NoContent,
                    Message = "The permissions were deleted"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "No permissions were specified or the permissions specified do not exist or already exist with a different permission action."
                }
            },
                new[]
            {
                _identityProviderParameter,
                _subjectIdParameter,
                new BodyParameter <List <PermissionApiModel> >(modelCatalog)
                {
                    Name        = "GranularPermissions",
                    Description = "The permissions to delete from the user."
                }
            },
                new[]
            {
                _usersTag
            }).SecurityRequirement(OAuth2ManageClientsScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "GetUserGroups",
                "",
                "Gets custom groups for a user",
                new[]
            {
                new HttpResponseMetadata <IEnumerable <GroupUserApiModel> >
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "List of GroupUserApiModel entities representing groups in which the user belongs"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "User was not found"
                }
            },
                new[]
            {
                _subjectIdParameter
            },
                new[]
            {
                _usersTag
            }).SecurityRequirement(OAuth2ReadScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "GetUserRoles",
                "",
                "Gets the roles associated with a user",
                new[]
            {
                new HttpResponseMetadata <List <RoleApiModel> >
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "List of roles representing the roles this user has been directly associated to."
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "User was not found"
                }
            },
                new[]
            {
                _identityProviderParameter,
                _subjectIdParameter
            },
                new[]
            {
                _usersTag
            }).SecurityRequirement(OAuth2ReadScopeBuilder);
        }
Ejemplo n.º 34
0
        public ServiceDetailsMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog) : base(modelCatalog, tagCatalog)
        {
            RouteDescriber.AddBaseTag(new Tag()
            {
                Description = "Operations for handling the service",
                Name        = "Service"
            });

            var customerSubTag = new Tag()
            {
                Name        = "Service/Customers",
                Description = "Operations of 'Service' relating to Customers"
            };

            RouteDescriber.DescribeRoute("ServiceHome", "", "Get Home", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            });

            RouteDescriber.AddAdditionalModels(typeof(ServiceOwner), typeof(ServiceCustomer));
            RouteDescriber.DescribeRoute <ServiceDetails>("GetDetails", "", "Get Details", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            });

            RouteDescriber.DescribeRoute <IEnumerable <ServiceCustomer> >("GetCustomers", "", "Get Customers", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            }, new[]
            {
                customerSubTag
            });

            RouteDescriber.DescribeRouteWithParams("GetCustomer", "", "Get Customer", new HttpResponseMetadata[]
            {
                new HttpResponseMetadata <ServiceCustomer> {
                    Code = 200, Message = "OK"
                },
                new HttpResponseMetadata <IEnumerable <ServiceCustomer> > {
                    Code = 202, Message = "Multiple Customers Found"
                },
                new HttpResponseMetadata {
                    Code = 404, Message = "No Customers Found"
                },
            }, new[]
            {
                new Parameter {
                    Name = "name", In = ParameterIn.Path, Required = true, Description = "The customer's name", Default = "Jack", Type = "string"
                }
            }, new[]
            {
                customerSubTag
            });

            RouteDescriber.DescribeRouteWithParams <ServiceCustomer>("PostNewCustomer", "", "Add a new customer", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "Customer Added"
                },
            }, new[]
            {
                new Parameter {
                    Name = "service", In = ParameterIn.Path, Required = true, Description = "The service's name", Default = "Nancy Swagger Service", Type = "string"
                },
                new BodyParameter <ServiceCustomer>(ModelCatalog)
                {
                    Name = "user", Required = true, Description = "The user"
                },
            }, new []
            {
                customerSubTag
            });

            RouteDescriber.DescribeRouteWithParams <SwaggerFile>("PostCustomerReview", "", "Add a customer's review", new[]
            {
                new HttpResponseMetadata <SwaggerFile> {
                    Code = 200, Message = "Review Added"
                },
            }, new[]
            {
                new Parameter {
                    Name = "name", In = ParameterIn.Path, Required = true, Description = "The customer's name", Default = "Jill", Type = "string"
                },
                new Parameter {
                    Name = "file", In = ParameterIn.Form, Required = true, Description = "The customer's review", Type = "file"
                },
            }, new[]
            {
                customerSubTag
            })
            //If you need to add something that is not a parameter to DescribeRoute,
            //the function will return the OperationBuilder so you can add it.
            .ProduceMimeTypes(new[] { "multipart/form-data", "application/x-www-form-urlencoded" });
        }
Ejemplo n.º 35
0
 public AnnotatedBodyParameter(ParameterInfo pi, ISwaggerModelCatalog modelCatalog)
 {
     Name = pi.Name;
     this.AddBodySchema(pi.ParameterType, modelCatalog);
 }
 public DefaultSwaggerMetadataProvider(IRouteCacheProvider routeCacheProvider, ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
 {
     this.routeCacheProvider = routeCacheProvider;
     this.modelCatalog = modelCatalog;
     this.tagCatalog = tagCatalog;
 }
Ejemplo n.º 37
0
 public virtual Schema GetSchema(ISwaggerModelCatalog modelCatalog)
 {
     return null;
 }
        public GroupsMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
            : base(modelCatalog, tagCatalog)
        {
            modelCatalog.AddModels(
                typeof(GroupRoleApiModel),
                typeof(GroupUserApiModel),
                typeof(UserApiModel));

            RouteDescriber.DescribeRouteWithParams(
                "AddGroup",
                "GroupSource can be either \"Custom\" for creating custom groups in Fabric or the displayName of the 3rd party identity provider if the group is from an external Idp. If groupSource is empty, it will be defaulted to the group source defined in the appsettings.json",
                "Adds a new group",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <GroupRoleApiModel>
                {
                    Code    = (int)HttpStatusCode.Created,
                    Message = "Created"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "Group already exists"
                }
            },
                new[]
            {
                new BodyParameter <GroupRoleApiModel>(modelCatalog)
                {
                    Name        = "Group",
                    Description = "The group to add"
                }
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2ReadWriteScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "UpdateGroups",
                "",
                "Updates a list of groups, useful for syncing 3rd party ID Provider groups with Fabric.Authorization groups.",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.NoContent,
                    Message = "Groups updated"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "Group already exists"
                }
            },
                new[]
            {
                new BodyParameter <IEnumerable <GroupRoleApiModel> >(modelCatalog)
                {
                    Name        = "Group",
                    Description = "The groups to update"
                }
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "GetGroup",
                "",
                "Gets a group by name",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <GroupRoleApiModel>
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "OK"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Group with specified name was not found"
                }
            },
                new[]
            {
                _groupNameParameter
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2ReadScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "DeleteGroup",
                "",
                "Deletes a group",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.NoContent,
                    Message = "Group deleted"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Group with specified name was not found"
                }
            },
                new[]
            {
                _groupNameParameter
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            #region Group -> Role Mapping Docs

            RouteDescriber.DescribeRouteWithParams(
                "GetRolesFromGroup",
                "",
                "Gets roles for a group by group name",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <GroupRoleApiModel>
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "OK"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Group with specified name was not found"
                }
            },
                new[]
            {
                _groupNameParameter,
                _securableItemParameter,
                _grainParameter
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2ReadScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "AddRoleToGroup",
                "",
                "Adds a role to a group",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <GroupRoleApiModel>
                {
                    Code    = (int)HttpStatusCode.Created,
                    Message = "Created"
                },
                new HttpResponseMetadata
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Group with specified name was not found or the role was not found"
                }
            },
                new[]
            {
                _groupNameParameter,
                _roleIdParameter
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "DeleteRoleFromGroup",
                "",
                "Deletes a role from a group",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <GroupRoleApiModel>
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "Updated group entity including any mapped roles"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Group with specified name was not found or the role was not found"
                }
            },
                new[]
            {
                _groupNameParameter,
                _roleIdParameter
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            #endregion

            #region Group -> User Mapping Docs

            RouteDescriber.DescribeRouteWithParams(
                "GetUsersFromGroup",
                "",
                "Gets users for a custom group by group name",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <GroupUserApiModel>
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "OK"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Group with specified name was not found"
                }
            },
                new[]
            {
                _groupNameParameter
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2ReadScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "AddUserToGroup",
                "1) This operation is only valid for custom groups. 2) The user specified by SubjectId parameter will be added silently if not found.",
                "Adds a user to a group.",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <GroupUserApiModel>
                {
                    Code    = (int)HttpStatusCode.Created,
                    Message = "Created"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Group with specified name was not found"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.BadRequest,
                    Message = "1) Group is not a custom group or 2) User is already a member of the group"
                }
            },
                new[]
            {
                _groupNameParameter,
                _subjectIdParameter,
                _identityProviderParameter
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            RouteDescriber.DescribeRouteWithParams(
                "DeleteUserFromGroup",
                "",
                "Deletes a user from a group",
                new List <HttpResponseMetadata>
            {
                new HttpResponseMetadata <GroupUserApiModel>
                {
                    Code    = (int)HttpStatusCode.OK,
                    Message = "Updated group entity including any mapped users"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.Forbidden,
                    Message = "Client does not have access"
                },
                new HttpResponseMetadata <Error>
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = "Group with specified name was not found or the user was not found"
                }
            },
                new[]
            {
                _groupNameParameter,
                _subjectIdParameter,
                _identityProviderParameter
            },
                new[]
            {
                _groupsTag
            }).SecurityRequirement(OAuth2WriteScopeBuilder);

            #endregion
        }
Ejemplo n.º 39
0
 public DefaultSwaggerMetadataProvider(IRouteCacheProvider routeCacheProvider, ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
 {
     this.routeCacheProvider = routeCacheProvider;
     this.modelCatalog       = modelCatalog;
     this.tagCatalog         = tagCatalog;
 }