docs: describe mutually exclusive create workspace template fields (#12834)

* docs: describe mutually exclusive create workspace template fields

Ideally we could do this in the OpenAPI spec, but there is no first
class "mutually exclusive" feature in OpenAPI. So in lieu of something
more complex, or changing our struct/validation, a description comment
should suffice.

* chore: Add description to code sample as well
This commit is contained in:
Steven Masley 2024-04-02 10:11:24 -05:00 committed by GitHub
parent 5137433123
commit b5b5c37d03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 0 deletions

2
coderd/apidoc/docs.go generated
View File

@ -2211,6 +2211,7 @@ const docTemplate = `{
"CoderSessionToken": []
}
],
"description": "Create a new workspace using a template. The request must\nspecify either the Template ID or the Template Version ID,\nnot both. If the Template ID is specified, the active version\nof the template will be used.",
"consumes": [
"application/json"
],
@ -9045,6 +9046,7 @@ const docTemplate = `{
}
},
"codersdk.CreateWorkspaceRequest": {
"description": "CreateWorkspaceRequest provides options for creating a new workspace. Only one of TemplateID or TemplateVersionID can be specified, not both. If TemplateID is specified, the active version of the template will be used.",
"type": "object",
"required": [
"name"

View File

@ -1932,6 +1932,7 @@
"CoderSessionToken": []
}
],
"description": "Create a new workspace using a template. The request must\nspecify either the Template ID or the Template Version ID,\nnot both. If the Template ID is specified, the active version\nof the template will be used.",
"consumes": ["application/json"],
"produces": ["application/json"],
"tags": ["Workspaces"],
@ -8052,6 +8053,7 @@
}
},
"codersdk.CreateWorkspaceRequest": {
"description": "CreateWorkspaceRequest provides options for creating a new workspace. Only one of TemplateID or TemplateVersionID can be specified, not both. If TemplateID is specified, the active version of the template will be used.",
"type": "object",
"required": ["name"],
"properties": {

View File

@ -332,6 +332,10 @@ func (api *API) workspaceByOwnerAndName(rw http.ResponseWriter, r *http.Request)
// Create a new workspace for the currently authenticated user.
//
// @Summary Create user workspace by organization
// @Description Create a new workspace using a template. The request must
// @Description specify either the Template ID or the Template Version ID,
// @Description not both. If the Template ID is specified, the active version
// @Description of the template will be used.
// @ID create-user-workspace-by-organization
// @Security CoderSessionToken
// @Accept json

View File

@ -138,6 +138,9 @@ type CreateTemplateRequest struct {
// CreateWorkspaceRequest provides options for creating a new workspace.
// Either TemplateID or TemplateVersionID must be specified. They cannot both be present.
// @Description CreateWorkspaceRequest provides options for creating a new workspace.
// @Description Only one of TemplateID or TemplateVersionID can be specified, not both.
// @Description If TemplateID is specified, the active version of the template will be used.
type CreateWorkspaceRequest struct {
// TemplateID specifies which template should be used for creating the workspace.
TemplateID uuid.UUID `json:"template_id,omitempty" validate:"required_without=TemplateVersionID,excluded_with=TemplateVersionID" format:"uuid"`

2
docs/api/schemas.md generated
View File

@ -1646,6 +1646,8 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
}
```
CreateWorkspaceRequest provides options for creating a new workspace. Only one of TemplateID or TemplateVersionID can be specified, not both. If TemplateID is specified, the active version of the template will be used.
### Properties
| Name | Type | Required | Restrictions | Description |

View File

@ -14,6 +14,11 @@ curl -X POST http://coder-server:8080/api/v2/organizations/{organization}/member
`POST /organizations/{organization}/members/{user}/workspaces`
Create a new workspace using a template. The request must
specify either the Template ID or the Template Version ID,
not both. If the Template ID is specified, the active version
of the template will be used.
> Body parameter
```json