Skip to content
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

Add OpenAPI entry-point for the go-provider-sdk #74

Closed
wants to merge 13 commits into from

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Dec 22, 2022

Add a new provider entry-point to allow consuming OpenAPI schemas.

Defining a provider currently looks like this:

package main

import (
	_ "embed"

	schema "github.com/getkin/kin-openapi/openapi3"
	p "github.com/pulumi/pulumi-go-provider"
	s "github.com/pulumi/pulumi-go-provider/middleware/schema"
	"github.com/pulumi/pulumi-go-provider/openapi"
	"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

//go:embed test-api/openapi.json
var TODOSchemaBytes []byte

func main() {
	doc, err := schema.NewLoader().LoadFromData(TODOSchemaBytes)
	contract.AssertNoError(err)
	m := openapi.New(doc)

	resources := []openapi.Resource{{
		Token:  "todo:index:Todo",
		Create: m.NewOperation(doc.Paths["/todos"].Post),
		Read:   m.NewOperation(doc.Paths["/todos/{todoId}"].Get),
		Update: m.NewOperation(doc.Paths["/todos/{todoId}"].Patch),
		Delete: m.NewOperation(doc.Paths["/todos/{todoId}"].Delete),

		Mappings: openapi.Mappings{
			openapi.MapCreate("id").To(openapi.MapAll("todoId")),
		},
	}}
	err = p.RunProvider("todo", "0.1.0", openapi.Provider(openapi.Options{
		Metadata: s.Metadata{
			Description: "A example provider of a todo app",
			DisplayName: "Todo",
			Homepage:    "https://h88namdrg9.execute-api.us-west-2.amazonaws.com/stage/",
			Publisher:   "The Demo Gods",
		},
		Resources: resources,
	}))
	if err != nil {
		panic(err)
	}
}

@iwahbe iwahbe self-assigned this Dec 22, 2022
@iwahbe iwahbe marked this pull request as draft December 24, 2022 11:55
@iwahbe
Copy link
Member Author

iwahbe commented Apr 17, 2024

Closing in favor of #213.

@iwahbe iwahbe closed this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant