c# - How to define response error metadata in swagger/swashbuckle WebAPI 2 -


i have figured out how create response object metadata in swashbuckle:

[route("x/{y:guid}")] [httpget] [swaggerresponse(httpstatuscode.ok, "bla", typeof(bladto))] public ihttpactionresult getsomething([fromuri] guid someguid) {     bla returnobject;     try     {         returnobject = _service.get(someguid);     }     catch (databaseexception databaseexception)     {         modelstate.addmodelerror("databaseexception", databaseexception.message);         return badrequest(modelstate);     }      return ok(returnobject);      } 

i still looking examples define request object meta data , meta data 400 errors etc. pointers appreciated.

object metadata of operation detected swashbuckle automatically. object metadata of errors can specified adding more swaggerresponseattributes.

here's example:

[route("x}")] [httppost] [swaggerresponse(httpstatuscode.created, "bla", typeof(bladto))] [swaggerresponse(httpstatuscode.conflict, type = typeof(errorresponse))] [swaggerresponse(httpstatuscode.badrequest, type = typeof(errorresponse))] public ihttpactionresult createbla(bladto bla) {     bladdto returnobject;      try     {         returnobject = _service.create(bla);     }     catch (databaseexception databaseexception)     {         var error = new errorresponse { message = databaseexception.message);         return content(httpstatuscode.badrequest, error);     }     catch (someotherexception ex)     {         var error = new errorresponse { message = ex.message);         return content(httpstatuscode.conflict, error);     }     return ok(returnobject);      }  public class errorresponse {     string message { get; set; } } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -