Giter Club home page Giter Club logo

fubumvc-swagger's Introduction

FubuMVC Swagger

This project helps your FubuMVC web application generate API documentation via Swagger.

swagger demo

See our Hello Swagger live demo.

How do I get it?

We have a nuget package available.

PM> Install-Package FubuMVC.Swagger

Building Swagger

To build just run rake grabbing the albacore gem if you don't already have it.

gem install albacore
rake

How do I put this in my peanut butter?

Note: This should all be simplified when I find the time to figure out Fubu Bottles.

Your API documented should support content negitiation and be grouped under the route /api. Take a look at the HelloSwagger for examples.

Checklist

Add a reference to this project. Why not use nuget!

Add the following to your FubuRegistry:

ApplyConvention<SwaggerConvention>();
Services(s=> s.AddService<IActionGrouper, APIRouteGrouper>());

Copy the swagger-ui directory into your /content direcotry.

Launch your web app and take a look at the /api to see if it is working.

What does this convention do?

Three routes will be added to your application:

GET /api

This route serves up the Swagger-UI page currently embedded into FubuSwagger. This part needs work.

GET /api/resources.json

Swagger UI does some resource discovery and uses the output of this route to find all of the API groups in your project.

GET /api/{GroupKey}.json

Details of each API group present in your app.

Pointing a Swagger UI web site at http://localhost:port/api/ should render pretty API documentation for your web application.

Why do I not see documentation for my actions?

Make sure the actions you wish to document are enabled for "Conneg"

In this example I have two marker interfaces which are used to mark input models on actions which will be APIs.

graph.Behaviors
 .Where(x => x.InputType().CanBeCastTo<IApi>() || x.InputType().CanBeCastTo<IUnauthenticatedApi>())
 .Each(x => x.MakeAsymmetricJson());

This example will force the result of these actions to be JSON. Note: This configuration is working around a bug in FubuMVC where normal browser usage will return XML for Conneg enabled endpoints. :(

Better yet take a look at the HelloSwagger demo application and see how it is wired up and organized.

How do I add more detail to my APIs

You can use data annotations to mark up your input models and their properties.

[Description("Workflow object history")]
public class HistoryRequest : IApi 
{
    [Required, Description("Type of workflow object. Typically this is 'case'.")]
    [AllowableValues("case", "subcase", "solution", "<any workflow object name>")]
    public string Type { get; set; }
    [Required, Description("Id of the workflow object.")]
    public string Id { get; set; }

    [Description("Limit the amout of history returned the given number of days. When this parameter is not specified. All history items will be returned.")]
	public int DaysOfHistory { get; set; }
}

fubumvc-swagger's People

Contributors

kevm avatar styson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fubumvc-swagger's Issues

API grouping mechanism should be abstracted

Currently there is an assumed route structure for apis.

/api/{group}/action-url

Swagger consumes APIs grouped by resource. To me it feels very domain entity bounded. "Pets", "User".

On my first pass the tactic of grouping them by directory structure made more sense for my needs. So currently I group conneg actions by the second part of their url the /api/{group}.

Likely people using Fubu will want flexibility at this point and not be forced into my route structure tactic. Likely they'll be more domain oriented and want to group by domain entity.

Use Embedded Swagger-UI

Providing a route the the swagger UI in /api would be pretty sweet.

  • Need to emit the /swagger-ui/index.html as a view telling the view where the resource discovery route is (/api/resources.json)
    @huboard:{"order":3.0}

Add bottle support

Allowing swagger to be pulled in via Bottle would be sweet.

  • Should the embedded swagger-ui app be emitted via route?

Note until bottle support is added consumers will need to register the Convention and register services in their FubuRegistry:

//TODO replace this with Swagger Bottle
ApplyConvention<SwaggerConvention>();

Services(s=> s.AddService<IActionGrouper, APIRouteGrouper>());

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.