Skip to content

Add Deploy file definition. #4

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

Merged
merged 2 commits into from
May 21, 2016
Merged
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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: validate generate

generate:
swagger generate client -A netlify -f swagger.yml -t go -c plumbing

validate:
swagger validate swagger.yml
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ This repository contains Netlify's API definition in the [Open API format](https

It's still a work in progress and we welcome feedback and contributions.

## Validation
## Installation

We use [go-swagger](https://github.com/go-swagger/go-swagger) to validate our spec against the 2.0 spec of Open API.

Follow the installation instruction in that repository. You can run this command to validate the spec:
To download the toolchain follow the installation instructions in that repository. You'll need to have Go installed.

swagger validate -f swagger.yml
## Spec validation

You can run this command to validate the spec:

make validate

## Code generation

Currently, we're generating client code for Go, but we're planning on releasing libraries in any language that can generate code from the spec.

You can use this command to generate the Go client:

swagger generate client -t go -f swagger.yml
make generate

## License

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package plumbing

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
Expand All @@ -9,40 +9,40 @@ import (

strfmt "github.com/go-openapi/strfmt"

"github.com/netlify/swagger-api-client/go/client/operations"
"github.com/netlify/swagger-api-client/go/plumbing/operations"
)

// Default netlify API definition HTTP client.
// Default netlify HTTP client.
var Default = NewHTTPClient(nil)

// NewHTTPClient creates a new netlify API definition HTTP client.
func NewHTTPClient(formats strfmt.Registry) *NetlifyAPIDefinition {
// NewHTTPClient creates a new netlify HTTP client.
func NewHTTPClient(formats strfmt.Registry) *Netlify {
if formats == nil {
formats = strfmt.Default
}
transport := httptransport.New("localhost", "/api/v1", []string{"https"})
return New(transport, formats)
}

// New creates a new netlify API definition client
func New(transport runtime.ClientTransport, formats strfmt.Registry) *NetlifyAPIDefinition {
cli := new(NetlifyAPIDefinition)
// New creates a new netlify client
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Netlify {
cli := new(Netlify)
cli.Transport = transport

cli.Operations = operations.New(transport, formats)

return cli
}

// NetlifyAPIDefinition is a client for netlify API definition
type NetlifyAPIDefinition struct {
// Netlify is a client for netlify
type Netlify struct {
Operations *operations.Client

Transport runtime.ClientTransport
}

// SetTransport changes the transport on the client and all its subresources
func (c *NetlifyAPIDefinition) SetTransport(transport runtime.ClientTransport) {
func (c *Netlify) SetTransport(transport runtime.ClientTransport) {
c.Transport = transport

c.Operations.SetTransport(transport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,32 @@ func (a *Client) UpdateSiteSnippet(params *UpdateSiteSnippetParams, authInfo run
return result.(*UpdateSiteSnippetNoContent), nil
}

/*
UploadDeployFile upload deploy file API
*/
func (a *Client) UploadDeployFile(params *UploadDeployFileParams, authInfo runtime.ClientAuthInfoWriter) (*UploadDeployFileNoContent, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewUploadDeployFileParams()
}

result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "uploadDeployFile",
Method: "PUT",
PathPattern: "/sites/{site_id}/deploys/{deploy_id}/files/{file_path}",
ProducesMediaTypes: []string{"application/io.swagger.netlify.v1+json"},
ConsumesMediaTypes: []string{"application/io.swagger.netlify.v1+json"},
Schemes: []string{"https"},
Params: params,
Reader: &UploadDeployFileReader{formats: a.formats},
AuthInfo: authInfo,
})
if err != nil {
return nil, err
}
return result.(*UploadDeployFileNoContent), nil
}

// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
Expand Down
89 changes: 89 additions & 0 deletions go/plumbing/operations/upload_deploy_file_parameters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package operations

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
"io"

"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"

strfmt "github.com/go-openapi/strfmt"
)

// NewUploadDeployFileParams creates a new UploadDeployFileParams object
// with the default values initialized.
func NewUploadDeployFileParams() *UploadDeployFileParams {
var ()
return &UploadDeployFileParams{}
}

/*UploadDeployFileParams contains all the parameters to send to the API endpoint
for the upload deploy file operation typically these are written to a http.Request
*/
type UploadDeployFileParams struct {

/*DeployID*/
DeployID string
/*FileBody*/
FileBody io.ReadCloser
/*FilePath*/
FilePath string
/*SiteID*/
SiteID string
}

// WithDeployID adds the deployId to the upload deploy file params
func (o *UploadDeployFileParams) WithDeployID(DeployID string) *UploadDeployFileParams {
o.DeployID = DeployID
return o
}

// WithFileBody adds the fileBody to the upload deploy file params
func (o *UploadDeployFileParams) WithFileBody(FileBody io.ReadCloser) *UploadDeployFileParams {
o.FileBody = FileBody
return o
}

// WithFilePath adds the filePath to the upload deploy file params
func (o *UploadDeployFileParams) WithFilePath(FilePath string) *UploadDeployFileParams {
o.FilePath = FilePath
return o
}

// WithSiteID adds the siteId to the upload deploy file params
func (o *UploadDeployFileParams) WithSiteID(SiteID string) *UploadDeployFileParams {
o.SiteID = SiteID
return o
}

// WriteToRequest writes these params to a swagger request
func (o *UploadDeployFileParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {

var res []error

// path param deploy_id
if err := r.SetPathParam("deploy_id", o.DeployID); err != nil {
return err
}

if err := r.SetBodyParam(o.FileBody); err != nil {
return err
}

// path param file_path
if err := r.SetPathParam("file_path", o.FilePath); err != nil {
return err
}

// path param site_id
if err := r.SetPathParam("site_id", o.SiteID); err != nil {
return err
}

if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
99 changes: 99 additions & 0 deletions go/plumbing/operations/upload_deploy_file_responses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package operations

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
"fmt"
"io"

"github.com/go-openapi/runtime"

strfmt "github.com/go-openapi/strfmt"

"github.com/netlify/swagger-api-client/go/models"
)

// UploadDeployFileReader is a Reader for the UploadDeployFile structure.
type UploadDeployFileReader struct {
formats strfmt.Registry
}

// ReadResponse reads a server response into the recieved o.
func (o *UploadDeployFileReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {

case 204:
result := NewUploadDeployFileNoContent()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil

default:
result := NewUploadDeployFileDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
}
}

// NewUploadDeployFileNoContent creates a UploadDeployFileNoContent with default headers values
func NewUploadDeployFileNoContent() *UploadDeployFileNoContent {
return &UploadDeployFileNoContent{}
}

/*UploadDeployFileNoContent handles this case with default header values.

No content
*/
type UploadDeployFileNoContent struct {
}

func (o *UploadDeployFileNoContent) Error() string {
return fmt.Sprintf("[PUT /sites/{site_id}/deploys/{deploy_id}/files/{file_path}][%d] uploadDeployFileNoContent ", 204)
}

func (o *UploadDeployFileNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

return nil
}

// NewUploadDeployFileDefault creates a UploadDeployFileDefault with default headers values
func NewUploadDeployFileDefault(code int) *UploadDeployFileDefault {
return &UploadDeployFileDefault{
_statusCode: code,
}
}

/*UploadDeployFileDefault handles this case with default header values.

error
*/
type UploadDeployFileDefault struct {
_statusCode int

Payload *models.Error
}

// Code gets the status code for the upload deploy file default response
func (o *UploadDeployFileDefault) Code() int {
return o._statusCode
}

func (o *UploadDeployFileDefault) Error() string {
return fmt.Sprintf("[PUT /sites/{site_id}/deploys/{deploy_id}/files/{file_path}][%d] uploadDeployFile default %+v", o._statusCode, o.Payload)
}

func (o *UploadDeployFileDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

o.Payload = new(models.Error)

// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}

return nil
}
31 changes: 30 additions & 1 deletion swagger.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
swagger: '2.0'
info:
version: 0.1.0
title: Netlify API definition
title: Netlify's API definition
securityDefinitions:
netlify_auth:
type: oauth2
Expand Down Expand Up @@ -388,6 +388,35 @@ paths:
description: error
schema:
$ref: "#/definitions/error"
/sites/{site_id}/deploys/{deploy_id}/files/{file_path}:
put:
operationId: uploadDeployFile
parameters:
- name: site_id
type: string
in: path
required: true
- name: deploy_id
type: string
in: path
required: true
- name: file_path
type: string
in: path
required: true
- name: file_body
in: body
schema:
type: string
format: binary
required: true
responses:
'204':
description: No content
default:
description: error
schema:
$ref: "#/definitions/error"
/forms:
get:
operationId: listForms
Expand Down