Skip to content

Conversation

@padiazg
Copy link
Contributor

@padiazg padiazg commented Aug 19, 2022

Description

This PR introduces two new functions AddRoute and BuildStream

AddRoute

With this function, we can add a route the same way as using an annotation.

Example:
We must use MapAnnotationsInPath to read these annotations and add them to the routes list.

 // @OAS handleCreateUser /users POST // @OAS handleGetUser /users GET 

We can use AddRoute instead to get the same result.

apiDoc.AddRoute(docs.Path{	Route: "/users",	HTTPMethod: "POST",	OperationID: "createUser",	Summary: "Create a new User",	Responses: docs.Responses{	getResponseOK(),	getResponseNotFound(),	},	// HandlerFuncName: "handleCreateUser",	RequestBody: docs.RequestBody{	Description: "Create a new User",	Content: docs.ContentTypes{	getContentApplicationJSON("#/components/schemas/User"),	},	Required: true,	}, }) apiDoc.AddRoute(docs.Path{	Route: "/users",	HTTPMethod: "GET",	OperationID: "getUser",	Summary: "Get a User",	Responses: docs.Responses{	getResponseOK(),	},	// HandlerFuncName: "handleCreateUser",	RequestBody: docs.RequestBody{	Description: "Create a new User",	Content: docs.ContentTypes{	getContentApplicationJSON("#/components/schemas/User"),	},	Required: true,	}, }) 

The main changes are at build.go and routing.go, the examples folder was just reorganized to add a new example.

Motivation and Context

There are cases where you cannot write annotations to specify the routes, like when you are working with a framework that auto-generates the API dynamically or when you need to define/recover the API details from a manifest.

Changes:

  • Added BuildStream and AddRoute functions
  • Moved existing example to examples/file_output
  • Added new example examples/stream_output
  • Updated readme.md
* Moved existing example to examples/file_output * Added new exampe examples/stream_output * Updated readme.md
@padiazg padiazg changed the title Feature addroute n buildstream Feature addroute and buildstream Aug 19, 2022
@kaynetik kaynetik merged commit 2eefb9f into go-oas:main Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants