MultipleApiVersions with Swagger -


i trying enable versioning on rest api, version specified in header, "api-version":2, vendor media type, "accept: application/vnd.company.resource-v2+json, application/json; version=2", or in query string "?version=2". implementation using ihttprouteconstraint , routefactoryattribute. works perfectly. however, swagger not able match right model correct versioned document. operationid version 1 model.

public class devicescontroller : apicontroller {     [httpget, routeversion( "api/devices", 1, name = "v1.devices" )]     [responsetype( typeof( ienumerable<models.v1.device> ) )]     public ihttpactionresult getv1( )     {         return ok( new list<models.v1.device> { ... } );     }      [httpget, routeversion( "api/devices", 2, name = "v2.devices" )]     [responsetype( typeof( ienumerable<models.v2.device> ) )]     public ihttpactionresult getv2( )     {         return ok( new list<models.v2.device> { ... } );     } } 

swagger docs v2 has wrong operationid , mime types.

"tags": [     "devices" ], "summary": "get list of device(s) device identifier", "operationid": "devices_getv1", "consumes": [ ], "produces":  [     "application/vnd.safe.inventory-v1+json",     "application/json",     "text/json",     "application/vnd.safe.inventory-v1+xml",     "application/xml",     "text/xml" ], ... 

swashbuckle 5.2.2

i have tried customizing apiexplorer descripted in these post:

github.com/domaindrivendev/swashbuckle/issues/558 github.com/domaindrivendev/swashbuckle/issues/317 

i have tried building custom selector.

i went down route well, don’t think same issue. https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-swashbuckle-customize/

asking direction appreciated.

thanks in advance.

we figured out solution custom apiexplorer described in http://blog.ulriksen.net/versioned-iapiexplorer

in swagger configuration: using multipleapiversions

c.multipleapiversions( ( apidesc, version ) => {     var versionconstraint = apidesc.route.constraints[ "version" ] routeversionconstraint;     return ( versionconstraint != null ) && versionconstraint.allowedversion == version.convertto<int>( ); }, vc => {     vc.version( "2", "api v2" ); //add line when v2 released     vc.version( "1", "api v1" ); } ); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -