{"id":15688356,"url":"https://github.com/martincostello/openapi-extensions","last_synced_at":"2025-10-20T10:22:21.828Z","repository":{"id":250678158,"uuid":"834823232","full_name":"martincostello/openapi-extensions","owner":"martincostello","description":"Extensions for Microsoft.AspNetCore.OpenApi","archived":false,"fork":false,"pushed_at":"2025-04-09T15:07:55.000Z","size":462,"stargazers_count":73,"open_issues_count":5,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T16:23:16.184Z","etag":null,"topics":["aspnetcore","dotnet","openapi"],"latest_commit_sha":null,"homepage":"https://blog.martincostello.com/whats-new-for-openapi-with-dotnet-9/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martincostello.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.MD","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["martincostello"],"buy_me_a_coffee":"martincostello"}},"created_at":"2024-07-28T13:24:37.000Z","updated_at":"2025-04-09T14:59:36.000Z","dependencies_parsed_at":"2024-08-06T17:30:43.491Z","dependency_job_id":"2213645f-3af6-44eb-a22c-012f7971da94","html_url":"https://github.com/martincostello/openapi-extensions","commit_stats":{"total_commits":161,"total_committers":4,"mean_commits":40.25,"dds":0.3354037267080745,"last_synced_commit":"1289474dd037ace8aa9704c101fe625e99478457"},"previous_names":["martincostello/openapi-extensions"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martincostello%2Fopenapi-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martincostello%2Fopenapi-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martincostello%2Fopenapi-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martincostello%2Fopenapi-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martincostello","download_url":"https://codeload.github.com/martincostello/openapi-extensions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119294,"owners_count":21050755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnetcore","dotnet","openapi"],"created_at":"2024-10-03T17:58:28.384Z","updated_at":"2025-10-20T10:22:21.822Z","avatar_url":"https://github.com/martincostello.png","language":"C#","funding_links":["https://github.com/sponsors/martincostello","https://buymeacoffee.com/martincostello"],"categories":[],"sub_categories":[],"readme":"# OpenAPI Extensions for ASP.NET Core\n\n[![NuGet][package-badge-version]][package-download]\n[![NuGet Downloads][package-badge-downloads]][package-download]\n\n[![Build status][build-badge]][build-status]\n[![codecov][coverage-badge]][coverage-report]\n[![OpenSSF Scorecard][scorecard-badge]][scorecard-report]\n\n## Introduction\n\nA NuGet package of extensions for the [Microsoft.AspNetCore.OpenApi][aspnetcore-openapi] package.\n\nFeatures include:\n\n- Adding examples to OpenAPI operations and schemas.\n- Customizing descriptions for:\n  - OpenAPI operation parameters and responses;\n  - OpenAPI schemas and their properties.\n- Adding application URLs to the OpenAPI document.\n- Adding OpenAPI schema documentation from XML comments.\n- Adding an HTTP endpoint to get OpenAPI documents as YAML.\n\nThe library is also designed to be compatible with support for [native AoT][aspnetcore-native-aot] in ASP.NET Core 9.\n\nThere is also [a sample application using the library][sample-app].\n\nAn overview of the library and how it works can be found on YouTube in this talk from\n.NET Conf 2024: [📺 _Extending ASP.NET Core OpenAPI_][dotnet-conf]\n\n## Installation\n\nTo install the library from [NuGet][package-download] using the .NET SDK run the following command:\n\n```console\ndotnet add package MartinCostello.OpenApi.Extensions\n```\n\n## Usage\n\nBelow is an example code snippet showing how to use the features of the library:\n\n```csharp\nusing System.ComponentModel;\nusing System.Text.Json.Serialization;\nusing MartinCostello.OpenApi;\nusing Microsoft.AspNetCore.Mvc;\n\nvar builder = WebApplication.CreateBuilder(args);\n\nbuilder.Services.AddOpenApi((options) =\u003e\n{\n    // Configure ASP.NET Core support for OpenAPI documentation...\n});\n\nbuilder.Services.AddOpenApiExtensions((options) =\u003e\n{\n    // Always return the server URLs in the OpenAPI document\n    // Only enable this option in production if you are sure\n    // you wish to explicitly expose your server URLs.\n    options.AddServerUrls = true;\n\n    // Set a default URL to use for generation of the OpenAPI document using\n    // https://www.nuget.org/packages/Microsoft.Extensions.ApiDescription.Server.\n    options.DefaultServerUrl = \"https://localhost:50001\";\n\n    // Add examples for OpenAPI operations and components\n    options.AddExamples = true;\n\n    // Add JSON serialization context to use to serialize examples when enabled\n    options.SerializationContexts.Add(TodoJsonSerializerContext.Default);\n\n    // Add a custom example provider for ProblemDetails\n    options.AddExample\u003cProblemDetails, ProblemDetailsExampleProvider\u003e();\n\n    // Configure XML comments for the schemas in the OpenAPI document\n    // from the assembly that the Program class is defined in.\n    options.AddXmlComments\u003cProgram\u003e();\n\n    // Add a custom transformation for the descriptions in the OpenAPI document\n    options.DescriptionTransformations.Add((p) =\u003e p.ToUpper());\n});\n\n// Required if AddServerUrls=true\nbuilder.Services.AddHttpContextAccessor();\n\nvar app = builder.Build();\n\n// Configure endpoint to get OpenAPI documents as JSON\napp.MapOpenApi();\n\n// Optionally also (or instead) configure endpoint to get OpenAPI documents as YAML\napp.MapOpenApiYaml();\n\n// The [Description] attribute can be used to add parameter descriptions\n// The [OpenApiExample] attribute can be used to add simple string examples\n// The ProducesOpenApiResponse() method can be used to customize the description for responses\napp.MapGet(\"/todo\", ([Description(\"The Todo item's ID\"), OpenApiExample(\"42\")] string id) =\u003e\n{\n    return new Todo()\n    {\n        Id = id,\n        Text = \"Example\",\n        IsComplete = false,\n    };\n}).ProducesOpenApiResponse(StatusCodes.Status200OK, \"The Todo item.\");\n\napp.MapPost(\"/todo\", (Todo model) =\u003e\n{\n    var todo = new Todo()\n    {\n        Id = Guid.NewGuid().ToString(),\n        Text = model.Text,\n        IsComplete = false,\n    };\n    return Results.Created($\"/todo/{todo.Id}\", todo);\n}).ProducesOpenApiResponse(StatusCodes.Status201Created, \"The created Todo item.\");\n\napp.Run();\n\n// Classes can implement IExampleProvider\u003cTodo\u003e and decorate\n// themselves with the [OpenApiExample\u003cT\u003e] attribute to use\n// the example for all usage of the type in the OpenAPI document.\n// Examples can also be added as attributes to parameters of operations,\n// endpoint methods themselves, or as endpoint metadata.\n\n[OpenApiExample\u003cTodo\u003e]\npublic class Todo : IExampleProvider\u003cTodo\u003e\n{\n    public string Id { get; set; }\n    public string Text { get; set; }\n    public bool IsComplete { get; set; }\n\n    public static Todo GenerateExample() =\u003e\n        new()\n        {\n            Id = \"42\",\n            Text = \"Buy milk\",\n            IsComplete = false,\n        };\n}\n\n// Custom IExampleProvider\u003cT\u003e implementations can be used to add more specific\n// examples for types in the OpenAPI document, or for types that are not owned\n// by the application itself (e.g. ASP.NET Core's ProblemDetails class).\n\npublic class ProblemDetailsExampleProvider : IExampleProvider\u003cProblemDetails\u003e\n{\n    public static ProblemDetails GenerateExample()\n    {\n        return new()\n        {\n            Type = \"https://tools.ietf.org/html/rfc7231#section-6.5.1\",\n            Title = \"Bad Request\",\n            Status = StatusCodes.Status400BadRequest,\n            Detail = \"The specified value is invalid.\",\n        };\n    }\n}\n\n// JSON source generation context to use to generate examples for JSON\n// payloads that matches the runtime behaviour of the application itself\n// (for example whether to use camelCase or PascalCase etc.)\n\n[JsonSerializable(typeof(Todo))]\n[JsonSerializable(typeof(ProblemDetails))]\n[JsonSourceGenerationOptions(\n    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,\n    PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,\n    WriteIndented = true)]\npublic partial class TodoJsonSerializerContext : JsonSerializerContext;\n```\n\n## Building and Testing\n\nCompiling the application yourself requires Git and the [.NET SDK][dotnet-sdk] to be installed.\n\nTo build and test the application locally from a terminal/command-line, run the\nfollowing set of commands:\n\n```powershell\ngit clone https://github.com/martincostello/openapi-extensions.git\ncd openapi-extensions\n./build.ps1\n```\n\n## Feedback\n\nAny feedback or issues can be added to the issues for this project in [GitHub][issues].\n\n## Repository\n\nThe repository is hosted in [GitHub][repo]: \u003chttps://github.com/martincostello/openapi-extensions.git\u003e\n\n## License\n\nThis project is licensed under the [Apache 2.0][license] license.\n\n[aspnetcore-native-aot]: https://learn.microsoft.com/aspnet/core/fundamentals/native-aot \"ASP.NET Core support for Native AOT\"\n[aspnetcore-openapi]: https://www.nuget.org/packages/Microsoft.AspNetCore.OpenApi\n[build-badge]: https://github.com/martincostello/openapi-extensions/actions/workflows/build.yml/badge.svg?branch=main\u0026event=push\n[build-status]: https://github.com/martincostello/openapi-extensions/actions?query=workflow%3Abuild+branch%3Amain+event%3Apush \"Continuous Integration for this project\"\n[coverage-badge]: https://codecov.io/gh/martincostello/openapi-extensions/branch/main/graph/badge.svg\n[coverage-report]: https://codecov.io/gh/martincostello/openapi-extensions \"Code coverage report for this project\"\n[dotnet-conf]: https://www.youtube.com/watch?v=ooP0vkST3X8 \"Extending ASP.NET Core OpenAPI - .NET Conf 2024\"\n[dotnet-sdk]: https://dotnet.microsoft.com/download \"Download the .NET SDK\"\n[issues]: https://github.com/martincostello/openapi-extensions/issues \"Issues for this project on GitHub.com\"\n[license]: https://www.apache.org/licenses/LICENSE-2.0.txt \"The Apache 2.0 license\"\n[package-badge-downloads]: https://img.shields.io/nuget/dt/MartinCostello.OpenApi.Extensions?logo=nuget\u0026label=Downloads\u0026color=blue\n[package-badge-version]: https://img.shields.io/nuget/v/MartinCostello.OpenApi.Extensions?logo=nuget\u0026label=Latest\u0026color=blue\n[package-download]: https://www.nuget.org/packages/MartinCostello.OpenApi.Extensions \"Download MartinCostello.OpenApi.Extensions from NuGet\"\n[repo]: https://github.com/martincostello/openapi-extensions \"This project on GitHub.com\"\n[sample-app]: https://github.com/martincostello/openapi-extensions/tree/main/samples/TodoApp \"Sample application using the library\"\n[scorecard-badge]: https://api.securityscorecards.dev/projects/github.com/martincostello/openapi-extensions/badge\n[scorecard-report]: https://securityscorecards.dev/viewer/?uri=github.com/martincostello/openapi-extensions \"OpenSSF Scorecard for this project\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartincostello%2Fopenapi-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartincostello%2Fopenapi-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartincostello%2Fopenapi-extensions/lists"}