{"id":19241984,"url":"https://github.com/jaxelr/nancy.metadata.openapi","last_synced_at":"2025-07-03T14:33:43.996Z","repository":{"id":38008512,"uuid":"93002057","full_name":"Jaxelr/Nancy.Metadata.OpenApi","owner":"Jaxelr","description":"Open Api Spec library for NancyFx","archived":false,"fork":false,"pushed_at":"2024-01-25T15:34:54.000Z","size":51426,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-17T18:59:51.180Z","etag":null,"topics":["metadata","nancyfx","openapi"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jaxelr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-01T00:59:34.000Z","updated_at":"2022-06-23T11:14:44.000Z","dependencies_parsed_at":"2022-09-09T16:22:16.394Z","dependency_job_id":null,"html_url":"https://github.com/Jaxelr/Nancy.Metadata.OpenApi","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaxelr%2FNancy.Metadata.OpenApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaxelr%2FNancy.Metadata.OpenApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaxelr%2FNancy.Metadata.OpenApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaxelr%2FNancy.Metadata.OpenApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jaxelr","download_url":"https://codeload.github.com/Jaxelr/Nancy.Metadata.OpenApi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250032168,"owners_count":21363785,"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":["metadata","nancyfx","openapi"],"created_at":"2024-11-09T17:13:05.738Z","updated_at":"2025-04-21T09:32:33.161Z","avatar_url":"https://github.com/Jaxelr.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nancy.Metadata.OpenApi [![Mit License][mit-img]][mit]\n\nThis library extends Nancy modules in order to produce a specification file that will follow the OpenAPI spec.\n\nYou can find the latest specifications of [OpenAPI here](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md)\n\nThis library targets Nancy 2.0, for previous versions that target Nancy 1.X check release that target version 0.7.0 and below.\n\n__Note:__ Since Nancyfx is no longer being maintained i will be deprioritizing this library, please read [here for details](https://github.com/NancyFx/Nancy/issues/3010)\n\n## Builds\n\n| Appveyor  | Branch | Coverage |\n| :---:     | :---: | :--: |\n| [![Build status][build-master-img]][build-master] | master | [![CodeCov][codecov-master-img]][codecov-master] |\n| [![Build status][build-develop-img]][build-develop] | develop | [![CodeCov][codecov-develop-img]][codecov-develop] |\n\n## Packages\n\nNuGet (Stable) | MyGet (Prerelease)\n:---: | :---:\n[![NuGet][nuget-img]][nuget] | [![MyGet][myget-img]][myget] |\n\n## Installation\n\nVia nuget:\n\n``` powershell\nPM\u003e Install-Package Nancy.Metadata.OpenApi\n```\n\nYou also need the Metadata library provided by Nancyfx:\n\n``` powershell\nPM\u003e Install-Package Nancy.Metadata.Modules\n```\n\n## Usage\n\nDefine a docs module that will serve our OpenApi Json (currently only json is supported) document:\n\n```c#\nusing Nancy.Metadata.OpenApi.Model;\nusing Nancy.Metadata.OpenApi.Modules;\n\npublic class DocsModule : OpenApiDocsModuleBase //We must inherit from the OpenApiDocsModuleBase\n{\n    //Could be an array of Servers corresponding to different environments. \n    public static Server Server\n        =\u003e new Server() { Description = \"My Descripton\", Url = \"http://localhost:5000/\" };\n\n    public static string[] Tags =\u003e new string[] { \"sample\", \"openapi\" };\n\n    public DocsModule(IRouteCacheProvider routeCacheProvider) :\n        base(routeCacheProvider,\n        \"/api/docs/openapi.json\",       //Document location path\n        \"My API \",                      //Api Title \n        \"v1.0\",                         //Version of the Api\n        Server,\n        \"/api\",                         //Base url\n        Tags)                           //Document Tags\n    {\n    }\n}\n```\n\nWe could optionally, if the information is needed, add Contact, License and External Docs information:\n\n```c#\npublic class DocsModule : OpenApiDocsModuleBase //We must inherit from the OpenApiDocsModuleBase\n{\n    public static Server Server\n        =\u003e new Server() { Description = \"My Descripton\", Url = \"http://localhost:5001/\" };\n\n    public static string[] Tags =\u003e new string[] { \"sample\", \"openapi\" };\n\n    public DocsModule(IRouteCacheProvider routeCacheProvider) :\n        base(routeCacheProvider, \"/api/docs/openapi.json\", \"My API 2\", \"v1.1\", Server, \"/api\", Tags)\n    {\n        //Optional information.\n        WithContact(\"Contact Information\", \"jaxelrojas@email.com\", \"https://jaxelr.github.io\");\n\n        //Optional information.\n        WithLicense(\"MIT\", \"https://opensource.org/licenses/MIT\");\n\n        //Optional Information.\n        WithExternalDocument(\"This is a tutorial or a spec doc.\", \"https://jaxelr.github.io\")\n    }\n}\n```\n\nThen, define the Nancy modules as you would usually do:\n\n```c#\n\n//Example using Nancy v2\npublic class MyModule : NancyModule\n{\n    public MyModule() : base(\"/api\")\n    {\n        Get(\"/hello\", r =\u003e HelloWorld(), name: \"SimpleRequest\");\n        Get(\"/hello/{name}\", r =\u003e Hello(r.name), name: \"SimpleRequestWithParameter\");\n    }\n}\n\n//Skipped method implementations for brevity sake...\n```\n\nFinally, you must define the metadata of the operations. To do so, simply declare the metadata module (using Nancy.Metadata.Modules) on the same namespace as the endpoint operations were defined, using the inherited MetadataModule class and the OpenApiRouteMetadata class defined on Nancy.Metadata.OpenApi.Core.\n\n```c#\nusing Nancy.Metadata.Modules;\nusing Nancy.Metadata.OpenApi.Core;\nusing Nancy.Metadata.OpenApi.Fluent;\n\npublic class MyMetadataModule : MetadataModule\u003cOpenApiRouteMetadata\u003e\n{\n    public MyMetadataModule()\n    {\n        Describe[\"SimpleRequest\"] = desc =\u003e new OpenApiRouteMetadata(desc)\n            .With(i =\u003e i.WithResponseModel(\"200\", typeof(SimpleResponseModel), \"Sample response\")\n                        .WithSummary(\"Simple GET example\"));\n\n        Describe[\"SimpleRequestWithParameter\"] = desc =\u003e new OpenApiRouteMetadata(desc)\n            .With(i =\u003e i.WithResponseModel(\"200\", typeof(SimpleResponseModel), \"Sample response\")\n                        .WithRequestParameter(\"name\")\n                        .WithSummary(\"Simple GET with parameters\"));\n    }\n}\n```\n\nThats pretty much it, the docs endpoint defined above would generate some valid OpenApi Json. You can validate the Open Api endpoint using [swagger-ui](https://github.com/swagger-api/swagger-ui). (For those unaware, OpenApi used to be called Swagger, so any reference to Swagger usually means version \u003c= 2.0) Check the [Compatibility table](https://github.com/swagger-api/swagger-ui#compatibility) of UI for usage.\n\nFor a working example, see the sample app that uses the Swagger-UI site as a validator.\n\n## Contributing\n\nCheck the [guidelines](https://github.com/Jaxelr/Nancy.Metadata.OpenApi/blob/master/.github/CONTRIBUTING.md) for a simple explanation on how you could contribute.\n\n[mit-img]: http://img.shields.io/badge/License-MIT-blue.svg\n[mit]: https://github.com/Jaxelr/Nancy.Metadata.OpenApi/blob/master/LICENSE\n[build-master-img]: https://ci.appveyor.com/api/projects/status/bk8fiqknunkegnv7/branch/master?svg=true\n[build-master]: https://ci.appveyor.com/project/Jaxelr/nancy-metadata-openapi/branch/master\n[build-develop-img]: https://ci.appveyor.com/api/projects/status/bk8fiqknunkegnv7/branch/develop?svg=true\n[build-develop]: https://ci.appveyor.com/project/Jaxelr/nancy-metadata-openapi/branch/develop\n[codecov-master-img]: https://codecov.io/gh/Jaxelr/Nancy.Metadata.OpenApi/branch/master/graph/badge.svg\n[codecov-master]: https://codecov.io/gh/Jaxelr/Nancy.Metadata.OpenApi/branch/master\n[codecov-develop-img]: https://codecov.io/gh/Jaxelr/Nancy.Metadata.OpenApi/branch/develop/graph/badge.svg\n[codecov-develop]: https://codecov.io/gh/Jaxelr/Nancy.Metadata.OpenApi/branch/develop\n[build-img]: https://ci.appveyor.com/api/projects/status/bk8fiqknunkegnv7?svg=true\n[nuget]: https://www.nuget.org/packages/Nancy.Metadata.OpenApi\n[nuget-img]: https://img.shields.io/nuget/v/Nancy.Metadata.OpenApi.svg\n[myget]: https://www.myget.org/feed/nancy-metadata-openapi/package/nuget/Nancy.Metadata.OpenApi\n[myget-img]: https://img.shields.io/myget/nancy-metadata-openapi/v/Nancy.Metadata.OpenApi.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaxelr%2Fnancy.metadata.openapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaxelr%2Fnancy.metadata.openapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaxelr%2Fnancy.metadata.openapi/lists"}