0% found this document useful (0 votes)
53 views

GitHub - Gabrielbaltazar - Gbswagger

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

GitHub - Gabrielbaltazar - Gbswagger

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

09/04/2022 11:06 GitHub - gabrielbaltazar/gbswagger

gabrielbaltazar / gbswagger Public

35 stars 10 forks

Star Notifications

Code Issues 5 Pull requests 1 Actions Projects Wiki Security Insights

master Go to file

gabrielbaltazar … 13 days ago

View code

README.md

GBSwagger
Middleware for generate Swagger Document based in your classes using RTTI.

How to use with Horse

uses
Horse,
Horse.GBSwagger;

type
TUser = class
private
Fid: Double;
Fname: String;
FlastName: string;
public
property id: Double read Fid write Fid;
property name: String read Fname write Fname;
property lastName: string read FlastName write FlastName;
end;

TAPIError = class
private
Ferror: string;

https://github.com/gabrielbaltazar/gbswagger 1/4
09/04/2022 11:06 GitHub - gabrielbaltazar/gbswagger

public
property error: string read Ferror write Ferror;
end;

var
APP: THorse;

begin
App := THorse.Create(9000);

App.Use(HorseSwagger); // Access http://localhost:9000/swagger/doc/html

API.Get ('user', procedure (Req: THorseRequest; Resp: THorseResponse; Next: TProc)


API.Post('user', procedure (Req: THorseRequest; Resp: THorseResponse; Next: TProc)

Swagger
.BasePath('v1')
.Path('user')
.Tag('User')
.GET('List All', 'List All Users')
.AddResponse(200, 'successful operation')
.Schema(TUser)
.IsArray(True)
.&End
.AddResponse(400, 'Bad Request')
.Schema(TAPIError)
.&End
.AddResponse(500, 'Internal Server Error')
.Schema(TAPIError)
.&End
.&End
.POST('Add user', 'Add a new user')
.AddParamBody('User data', 'User data')
.Required(True)
.Schema(TUser)
.&End
.AddResponse(201, 'Created')
.Schema(TUser)
.&End
.AddResponse(400, 'Bad Request')
.Schema(TAPIError)
.&End
.AddResponse(500, 'Internal Server Error')
.Schema(TAPIError)
.&End
.&End
.&End
.&End;

App.Start;
end.

https://github.com/gabrielbaltazar/gbswagger 2/4
09/04/2022 11:06 GitHub - gabrielbaltazar/gbswagger

Register
You don't need to write the same error response for many paths, just use a Register
interface.

Swagger
.Register
.SchemaOnError(TAPIError)
.&End
.BasePath('v1')
.Path('user')

https://github.com/gabrielbaltazar/gbswagger 3/4
09/04/2022 11:06 GitHub - gabrielbaltazar/gbswagger

.Tag('User')
.GET('List All', 'List All Users')
.AddResponse(200, 'successful operation')
.Schema(TUser)
.IsArray(True)
.&End
.AddResponse(400).&End
.AddResponse(500).&End
.&End
.POST('Add user', 'Add a new user')
.AddParamBody('User data', 'User data')
.Required(True)
.Schema(TUser)
.&End
.AddResponse(201, 'Created')
.Schema(TUser)
.&End
.AddResponse(400).&End
.AddResponse(500).&End
.&End
.&End
.&End;

Releases

10 tags

Packages

No packages published

Languages

Pascal 99.9% HTML 0.1%

https://github.com/gabrielbaltazar/gbswagger 4/4

You might also like