You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeServiceinterface {
//kok:op PUT /users/{id}//kok:param name in=header name=X-User-NameUpdateUser(ctx context.Context, idint, namestring) (errerror)
}
// HTTP request:// $ http PUT /users/101 X-User-Name:tracey
Bind multiple request parameters to a struct according to tags:
typeUserstruct {
IDint`kok:"in=path"`// name defaults to snake case `id`Namestring`kok:"in=query"`// name defaults to snake case `name`Ageint`kok:"in=header name=X-User-Age"`
}
typeServiceinterface {
//kok:op PUT /users/{id}//kok:param userUpdateUser(ctx context.Context, userUser) (errerror)
}
// HTTP request:// $ http PUT /users/101?name=tracey X-User-Age:1
Bind multiple query parameters to a struct with no tags:
typeUserstruct {
Namestring// equivalent to `kok:"in=query name=name"`Ageint// equivalent to `kok:"in=query name=age"`Hobbies []string// equivalent to `kok:"in=query name=hobbies"`
}
typeServiceinterface {
//kok:op POST /users//kok:param userCreateUser(ctx context.Context, userUser) (errerror)
}
// HTTP request:// $ http POST /users?name=tracey&age=1&hobbies=music&hobbies=sport
Argument aggregation:
typeServiceinterface {
//kok:op POST /logs//kok:param ip in=header name=X-Forwarded-For; in=request name=RemoteAddrLog(ctx context.Context, ip net.IP) (errerror)
}
// The equivalent annotations =>// (using backslash `\` for line continuation)typeServiceinterface {
//kok:op POST /logs//kok:param ip in=header name=X-Forwarded-For; \// in=request name=RemoteAddrLog(ctx context.Context, ip net.IP) (errerror)
}
// HTTP request:// $ http POST /logs
Define the HTTP request body
Directive: //kok:body
Arguments: <field> or <manipulation> [; <manipulation2> [; ...]]
// This is the API documentation of User.//kok:oas docsPath=/api-docs//kok:oas title=User API//kok:oas version=1.0.0//kok:oas basePath=/v1//kok:oas tags=usertypeServiceinterface {
//kok:op POST /usersCreateUser(ctx context.Context, namestring, ageint) (errerror)
}
Motivation
Proposed annotation syntax
HTTP
Define the HTTP operation
Directive:
//kok:op
Arguments:
<method> <pattern>
Examples:
Define the HTTP request parameters
//kok:param
<argName> [<parameter> [; <parameter2> [; ...]]]
in=<in> name=<name> required=<required> type=<type> descr=<descr>
Bind request parameters to simple arguments:
Bind multiple request parameters to a struct according to tags:
Bind multiple query parameters to a struct with no tags:
Argument aggregation:
Define the HTTP request body
//kok:body
<field>
or<manipulation> [; <manipulation2> [; ...]]
<argName> name=<name> type=<type> descr=<descr>
Omitted:
Specified as a normal argument:
Specified as
-
:Define the success HTTP response
Directive:
//kok:success
Arguments:
statusCode=<statusCode> body=<body> manip=`<manipulation> [; <manipulation2> [; ...]]`
<argName> name=<name> type=<type> descr=<descr>
Examples:
Define the OAS metadata
Directive:
//kok:oas
Arguments:
<property>=<value>
Examples:
Define the annotation alias
Directive:
//kok:alias
Arguments:
<name>=`<value>`
Examples:
gRPC
//kok:grpc
request=<request> response=<response>
Omitted:
Specified:
The text was updated successfully, but these errors were encountered: