Skip to content

Latest commit

 

History

History
274 lines (210 loc) · 13.7 KB

File metadata and controls

274 lines (210 loc) · 13.7 KB

CodeSamples

(CodeSamples)

Overview

REST APIs for retrieving Code Samples

Available Operations

GenerateCodeSamplePreview

This endpoint generates Code Sample previews from a file and configuration parameters.

Example Usage

package main

import(
	"context"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
	"os"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := speakeasyclientsdkgo.New(
        speakeasyclientsdkgo.WithSecurity(shared.Security{
            APIKey: speakeasyclientsdkgo.String("<YOUR_API_KEY_HERE>"),
        }),
    )

    content, fileErr := os.Open("example.file")
    if fileErr != nil {
        panic(fileErr)
    }


    res, err := s.CodeSamples.GenerateCodeSamplePreview(ctx, shared.CodeSampleSchemaInput{
        Language: "<value>",
        SchemaFile: shared.SchemaFile{
            Content: content,
            FileName: "example.file",
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.UsageSnippets != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request shared.CodeSampleSchemaInput ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.GenerateCodeSamplePreviewResponse, error

Errors

Error Type Status Code Content Type
sdkerrors.Error 4XX application/json
sdkerrors.Error 5XX application/json

GenerateCodeSamplePreviewAsync

This endpoint generates Code Sample previews from a file and configuration parameters, receiving an async JobID response for polling.

Example Usage

package main

import(
	"context"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
	"os"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := speakeasyclientsdkgo.New(
        speakeasyclientsdkgo.WithSecurity(shared.Security{
            APIKey: speakeasyclientsdkgo.String("<YOUR_API_KEY_HERE>"),
        }),
    )

    content, fileErr := os.Open("example.file")
    if fileErr != nil {
        panic(fileErr)
    }


    res, err := s.CodeSamples.GenerateCodeSamplePreviewAsync(ctx, shared.CodeSampleSchemaInput{
        Language: "<value>",
        SchemaFile: shared.SchemaFile{
            Content: content,
            FileName: "example.file",
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Object != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request shared.CodeSampleSchemaInput ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.GenerateCodeSamplePreviewAsyncResponse, error

Errors

Error Type Status Code Content Type
sdkerrors.Error 4XX application/json
sdkerrors.Error 5XX application/json

Get

Retrieve usage snippets from an OpenAPI document stored in the registry. Supports filtering by language and operation ID.

Example Usage

package main

import(
	"context"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/operations"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := speakeasyclientsdkgo.New(
        speakeasyclientsdkgo.WithSecurity(shared.Security{
            APIKey: speakeasyclientsdkgo.String("<YOUR_API_KEY_HERE>"),
        }),
    )

    res, err := s.CodeSamples.Get(ctx, operations.GetCodeSamplesRequest{
        Languages: []string{
            "python",
            "javascript",
        },
        MethodPaths: []operations.MethodPaths{
            operations.MethodPaths{
                Method: shared.HTTPMethodGet,
                Path: "/pets",
            },
        },
        OperationIds: []string{
            "getPets",
        },
        RegistryURL: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.UsageSnippets != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.GetCodeSamplesRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.GetCodeSamplesResponse, error

Errors

Error Type Status Code Content Type
sdkerrors.Error 4XX application/json
sdkerrors.SDKError 5XX */*

GetCodeSamplePreviewAsync

Poll for the result of an asynchronous Code Sample preview generation.

Example Usage

package main

import(
	"context"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/operations"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := speakeasyclientsdkgo.New(
        speakeasyclientsdkgo.WithSecurity(shared.Security{
            APIKey: speakeasyclientsdkgo.String("<YOUR_API_KEY_HERE>"),
        }),
    )

    res, err := s.CodeSamples.GetCodeSamplePreviewAsync(ctx, operations.GetCodeSamplePreviewAsyncRequest{
        JobID: "<id>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Object != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.GetCodeSamplePreviewAsyncRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.GetCodeSamplePreviewAsyncResponse, error

Errors

Error Type Status Code Content Type
sdkerrors.Error 4XX application/json
sdkerrors.Error 5XX application/json