Code Monkey home page Code Monkey logo

nancy.openapi's Introduction

nancy.openapi

OpenApi/swagger documentation generation for NancyFX. Integration with this repository is designed to be as trivial as possible:

  • Pull down the NuGet package.
  • Create an implementation of the IApiDescription interface to describe your Api at the top-level (Ie author, license information).
  • Create a derivative of MetadataModule for every module you wish to serve Api documentation from.

2 new routes will be added at the root of your application:

  • /swagger.json

This is the combined documentation which is automatically generated using each of the metadata modules.

  • /api-docs

This is a bundled implementation of the Swagger Ui project. It consumes the specification created at the swagger.json route.


Example

  • Install-Package Nancy.OpenApi
  • Extend Bootstrapper:
using Nancy.Bootstrapper;
using Nancy.OpenApi.Infrastructure;

namespace MyApiProject
{
    public class Bootstrapper : DefaultNancyBootstrapper
    {
        ///...
    
        protected override NancyInternalConfiguration InternalConfiguration => this.WithOpenApi(Conventions, ApplicationContainer);
    
        ///...
    }
}
  • Create Metadata Implementation

Module

namespace MyExampleApi
{
    public class HelloWorldModule : NancyModule
    {
        public HelloWorldModule()
        {
            Get["/api/helloWorld"] = p => null;
            Post["/api/helloWorld"] = p => null;
            Put["/api/helloWorld"] = p => null;
            Delete["/api/helloWorld"] = p => null;
            Patch["/api/helloWorld"] = p => null;
            Options["/api/helloWorld"] = p => null;
        }
    }
}

Metadata

using System.Collections.Generic;

namespace MyExampleApi
{
    public class HelloWorldMetadata : ModuleMetadata
    {
        public PathMetadata PostMetadata = new PathMetadata
        {
            OperationId = "addTest",
            Summary = "Add a test object",
            Consumes = new List<string> { "application/json", "application/xml" },
            Produces = new List<string> { "application/json", "application/xml" },
            Tags = new List<string> { "Test" }
        };

        public HelloWorldMetadata()
        {
            Post["/api/helloWorld"] = PostMetadata;
        }
    }
}

Make sure your Metadata module matches your Nancy Module. HelloWorldModule should have a ModuleMetadata derivative named HelloWorldMetadata

For further information as to what information to include in your metadata module, please refer to the official swagger/open api documentation over at The Official Docs :)

nancy.openapi's People

Contributors

thesheps avatar shepc avatar modeengage avatar

Stargazers

Eugene Duvenage avatar Yves Reynhout avatar Leonardo Lana avatar Phuong avatar  avatar Daniel James avatar xlong avatar  avatar

Watchers

Petter Sandholdt avatar xlong avatar James Cloos avatar  avatar Leonardo Lana avatar  avatar

nancy.openapi's Issues

Create use example

Create an example explaining the use of the library.
It seems to be very promising, though, it does not adequately explain.

Located multiple bootstrappers problem

When adding the Nuget I get a problem that my bootstraper and the one in OpenApi interfere.

Located multiple bootstrappers:
- Web.Api.Core.ApiBootstrapper
- Nancy.OpenApi.Infrastructure.Bootstrapper

Either remove unused bootstrapper types or specify which type to use.

Where the first one is my bootstraper and the second comes from the nuget package.

Whats the correct procedure to fix this?

Clash with RazorViewengine

Hi,

When i added the line

protected override NancyInternalConfiguration InternalConfiguration => this.WithOpenApi(Conventions, ApplicationContainer);

to bootstrapper, it break the razor view engine. Not sure how to avoid that :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.