Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARO-9390: Add asynchronous methods #208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/concepts/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func (m *Method) IsDelete() bool {
return m.name.Equals(nomenclator.Delete)
}

// IsAsyncDelete return true if this is an asynchronous add method.
func (m *Method) IsAsyncDelete() bool {
return m.name.Equals(nomenclator.AsyncDelete)
}

// IsGet returns true if this is a get method.
func (m *Method) IsGet() bool {
return m.name.Equals(nomenclator.Get)
Expand All @@ -111,13 +116,20 @@ func (m *Method) IsUpdate() bool {
return m.name.Equals(nomenclator.Update)
}

// IsAsyncUpdate returns true if this is an asynchronous update method.
func (m *Method) IsAsyncUpdate() bool {
return m.name.Equals(nomenclator.AsyncUpdate)
}

// IsAction determined if this method is an action instead of a regular REST method.
func (m *Method) IsAction() bool {
switch {
case m.IsAdd():
return false
case m.IsDelete():
return false
case m.IsAsyncDelete():
return false
case m.IsGet():
return false
case m.IsList():
Expand All @@ -128,6 +140,8 @@ func (m *Method) IsAction() bool {
return false
case m.IsUpdate():
return false
case m.IsAsyncUpdate():
return false
default:
return true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/concepts/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (p *Parameter) IsBody() bool {
if p.owner == nil {
return false
}
isRest := p.owner.IsAdd() || p.owner.IsGet() || p.owner.IsSearch() || p.owner.IsUpdate()
isRest := p.owner.IsAdd() || p.owner.IsGet() || p.owner.IsSearch() || p.owner.IsUpdate() || p.owner.IsAsyncUpdate()
if isRest && p.name.Equals(nomenclator.Body) {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/generators/docs/docs_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ func (g *DocsGenerator) httpMethod(method *concepts.Method) string {
if name.Equals(nomenclator.Add) {
return "POST"
}
if name.Equals(nomenclator.Update) {
if name.Equals(nomenclator.Update) || name.Equals(nomenclator.AsyncUpdate) {
return "PATCH"
}
if name.Equals(nomenclator.Delete) {
if name.Equals(nomenclator.Delete) || name.Equals(nomenclator.AsyncDelete) {
return "DELETE"
}
return "POST"
Expand Down
4 changes: 2 additions & 2 deletions pkg/generators/golang/json_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ func (g *JSONSupportGenerator) generateMethodSource(method *concepts.Method) {
switch {
case method.IsAdd():
g.generateAddMethodSource(method)
case method.IsDelete():
case method.IsDelete() || method.IsAsyncDelete():
g.generateDeleteMethodSource(method)
case method.IsGet():
g.generateGetMethodSource(method)
Expand All @@ -848,7 +848,7 @@ func (g *JSONSupportGenerator) generateMethodSource(method *concepts.Method) {
g.generatePostMethodSource(method)
case method.IsSearch():
g.generateSearchMethodSource(method)
case method.IsUpdate():
case method.IsUpdate() || method.IsAsyncUpdate():
g.generateUpdateMethodSource(method)
case method.IsAction():
g.generateActionMethodSource(method)
Expand Down
8 changes: 6 additions & 2 deletions pkg/http/binding_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ func (c *BindingCalculator) Method(method *concepts.Method) string {
switch {
case name.Equals(nomenclator.Add):
return http.MethodPost
case name.Equals(nomenclator.Delete):
case name.Equals(nomenclator.Delete) || name.Equals(nomenclator.AsyncDelete):
return http.MethodDelete
case name.Equals(nomenclator.Get):
return http.MethodGet
case name.Equals(nomenclator.List):
return http.MethodGet
case name.Equals(nomenclator.Post):
return http.MethodPost
case name.Equals(nomenclator.Update):
case name.Equals(nomenclator.Update) || name.Equals(nomenclator.AsyncUpdate):
return http.MethodPatch
default:
return http.MethodPost
Expand All @@ -173,10 +173,14 @@ func (c *BindingCalculator) DefaultStatus(method *concepts.Method) string {
status = http.StatusCreated
case name.Equals(nomenclator.Add):
status = http.StatusCreated
case name.Equals(nomenclator.AsyncUpdate):
status = http.StatusAccepted
case name.Equals(nomenclator.Update):
status = http.StatusOK
case name.Equals(nomenclator.Delete):
status = http.StatusNoContent
case name.Equals(nomenclator.AsyncDelete):
status = http.StatusAccepted
}
return strconv.Itoa(status)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/language/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *Reader) checkMethod(method *concepts.Method) {
switch {
case method.IsAdd():
r.checkAdd(method)
case method.IsDelete():
case method.IsDelete() || method.IsAsyncDelete():
r.checkDelete(method)
case method.IsGet():
r.checkGet(method)
Expand All @@ -72,7 +72,7 @@ func (r *Reader) checkMethod(method *concepts.Method) {
r.checkPost(method)
case method.IsSearch():
r.checkSearch(method)
case method.IsUpdate():
case method.IsUpdate() || method.IsAsyncUpdate():
r.checkUpdate(method)
case method.IsAction():
r.checkAction(method)
Expand Down
8 changes: 5 additions & 3 deletions pkg/nomenclator/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import (

var (
// A:
Adapt = names.ParseUsingCase("Adapt")
Adapter = names.ParseUsingCase("Adapter")
Add = names.ParseUsingCase("Add")
Adapt = names.ParseUsingCase("Adapt")
Adapter = names.ParseUsingCase("Adapter")
Add = names.ParseUsingCase("Add")
AsyncDelete = names.ParseUsingCase("AsyncDelete")
AsyncUpdate = names.ParseUsingCase("AsyncUpdate")

// B:
Body = names.ParseUsingCase("Body")
Expand Down