Skip to content
Draft
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
16 changes: 16 additions & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,19 @@

return mux
}


func GetBoardNameHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
// micro.GetBoardName() will be defined in internal/micro/micro.go as per plan
name := micro.GetBoardName()
response := map[string]string{"name": name}
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, "Failed to encode response: "+err.Error(), http.StatusInternalServerError)
return
}
}
}

mux.Handle("GET /v1/system/name", GetBoardNameHandler())

Check failure on line 119 in internal/api/api.go

View workflow job for this annotation

GitHub Actions / go-test-internal

syntax error: non-declaration statement outside function body
21 changes: 21 additions & 0 deletions internal/api/docs/openapi.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the openapi.yaml file is generated from cmd/gendoc/docs.go file.

You have to add your definition programmatically.

You can take inspiration from:

'data: {"code":"INTERNAL_SERVER_ERROR","message":"An error occurred during operation"}'
`,
},
Description: "Returns the system resources usage, such as memory, disk and CPU.",
Summary: "Get system resources usage",
Tags: []Tag{SystemTag},
PossibleErrors: []ErrorResponse{
{StatusCode: http.StatusInternalServerError, Reference: "#/components/responses/InternalServerError"},
},
},
{
OperationId: "checkUpdate",
Method: http.MethodGet,
Path: "/v1/system/update/check",
Parameters: (*struct {
OnlyArduino bool `query:"only-arduino" description:"If true, check only for Arduino packages that require an upgrade. Default is false."`
})(nil),
CustomSuccessResponse: &CustomResponseDef{
ContentType: "application/json",
DataStructure: handlers.UpdateCheckResult{},
Description: "Successful response",
StatusCode: http.StatusOK,
},
Description: "Returns the details of packages to be upgraded.",
Summary: "Get the packages that requires an upgrade",
Tags: []Tag{SystemTag},
PossibleErrors: []ErrorResponse{
{StatusCode: http.StatusInternalServerError, Reference: "#/components/responses/InternalServerError"},
{StatusCode: http.StatusBadRequest, Reference: "#/components/responses/BadRequest"},
{StatusCode: http.StatusNoContent, Reference: "#/components/responses/NoContent"},
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucarin91 perhaps would be better to go back to spec first approach, to ease future contributions?

Original file line number Diff line number Diff line change
Expand Up @@ -1669,3 +1669,24 @@ components:
version:
type: string
type: object


/v1/system/name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use a more generic endpoint like /v1/system/information.
This would make the API more cohesive and easier to extend in the future if new properties are added that still fall under the general “information” category.

If you only need to retrieve the system name, you could either include a query parameter filter (e.g. ?filter=name) or use a more specific endpoint such as /v1/system/information/name.

get:
description: Returns the name of the board.
operationId: getBoardName
responses:
"200":
content:
application/json:
schema:
properties:
name:
type: string
type: object
description: Successful response
"500":
$ref: '#/components/responses/InternalServerError'
summary: Get the board's name
tags:
- System
Loading