Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

csharp-opensource/CSharpExtensions-Swagger

Open more actions menu

Repository files navigation

Swagger Generator C#

NuGet Version

this nuget base on NSwag

NuGet Version

How to use (Startup.cs)


using SwaggerGenerator;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        .
        .
        .
        services.AddAutoGeneratedSwagger();
        .
        .
        .
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        .
        .
        .
        app.UseAutoGeneratedSwagger();
        .
        .
        .
    }
}

Example of attributes


using SwaggerGenerator;
using System.Collections.Generic;
using System.ComponentModel;
using System;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;

public class AttributesExample
{
    [JsonProperty(Order = 101)] public string LastProp { get; set; }
    [Description("my desc")] public string HaveDescription { get; set; }
    [Display(Name = "display name")] public string HaveTitle { get; set; }
    [Obsolete] public bool? Deprecated { get; set; }
    public bool HaveDefaultValue { get; set; } = true;
    [RegularExpression("https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\\+.~#?&\\/\\/=]*)")] public string HavePattern { get; set; }
    [StringLength(100, MinimumLength = 10)] public string HaveLength { get; set; }
    [MinLength(10), MaxLength(100)] public string HaveLength2 { get; set; }
    [Range(10, 100)] public int HaveRange { get; set; }
    [MinLength(2), MaxLength(100)] public List<string> ListMinMaxItems { get; set; }
    [SwaggerUniqueItems] public List<string> UniqueList { get; set; }
    // one of those attributes
    [BsonIgnore,JsonIgnore,ForeignKey,InverseProperty,SwaggerExclude] public object HideProp { get; set; }
    // only DogType will be in the swagger
    [SwaggerIgnoreInheritProps] public Dog DogWithoutInheritProps { get; set; }
}

public class Animal
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public class Dog : Animal
{
    public string DogType { get; set; }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.