is there a easy way to convert swagger / open api ...
# general
g
is there a easy way to convert swagger / open api spec into pulumi provider?
b
g
@billowy-army-68599 i had a quick look, do you have a readme on how to use that project? README is not clear on how to use it
b
i don’t i’m afraid, @clever-sunset-76585 wrote it, maybe he can help
c
@gorgeous-microphone-34056 there are three providers that I have generated so far with that. Tailscale is the latest one: https://github.com/cloudy-sky-software/pulumi-tailscale-native/blob/main/provider/pkg/gen/schema.go#L144-L155
g
im trying to see steps required for converting a swagger spec into provider
like a usage guide tbh
c
like a usage guide tbh
The lines I linked above is literally how you would use the library. That's the best I've got so far. Other than that, the instructions in the README for
pulschema
tell you how to prepare the OpenAPI spec for a successful conversion. You can also look at the tests in the providers I've generated thus far: https://github.com/search?q=topic%3Apulumi-provider+org%3Acloudy-sky-software+fork%3Atrue&type=repositories
g
not a golang developer 🙂 so trying to wrap my head around this. i will take a look
c
Ah gotcha. Some familiarity around how Pulumi providers are generated is also necessary to be honest and the best place to start for that is Pulumi's own https://github.com/pulumi/pulumi-provider-boilerplate which teaches you how to structure a provider. Note that converting the API spec to a Pulumi schema spec is only half the work. The other half is to model the HTTP requests necessary to make it work. As you'll notice in the providers that I generated, I use my own private library (
pulumi-provider-framework
) that does the HTTP offloading. When it comes to that you'll be on your own but since it's just HTTP requests you can use whatever strategy you'd like and shouldn't be blocked by not having access to that private lib.
I do have my own private GitHub repo template that uses
pulschema
and my private
pulumi-provider-framework
repo, which I am happy to share a ZIP file with you but it'll be useless to anyone without
pulumi-provider-framework
, which is why I've kept my template also private.
g
i will try to get familar with these repos
my goal -> i have an open api spec (v3) -> need to create a pulumi provider for this
c
Yeah honestly starting to understand how a Pulumi provider is built is the first thing I would recommend (the Pulumi boilerplate repo) before even attempting to convert anything because that'll teach you the problem
pulschema
is trying to solve.
g
gotcha that make sense
im assuming pulschema generates
provider/cmd
code at high level
c
pulschema
generates the
schema.json
file that you'll see referenced in the Pulumi provider boilerplate repo. If
pulschema
didn't exist, you'd have to manually author that JSON file which is what Pulumi uses to generate the language SDKs and docs.
g
make generate_schema
seems to be generating schema.json file which step are we using
pulschema
c
If you follow that codepath you'll end up in the lines of code I linked in my first message in this thread.
Also note that in the case of Tailscale, they don't have an OpenAPI spec file, so I needed to start with first generating an API spec file before I could even generate a Pulumi schema using
pulschema
. The API spec itself is generated using TypeSpec code in the
api
folder (not TypeScript). This is not something you'll have to worry about since you already have an OpenAPI spec. For a 1:1 comparison, perhaps the Render or the Scaleway Instances provider would be a closer match to what you might be dealing with.
g
got it, thank you
if its not too much to ask, can you confirm if this is the right approach 1. clone https://github.com/cloudy-sky-software/pulumi-render 2. install pulumictl 3. make updates to metadata like provider name etc 4. put custom.v1.Api.yml in root folder 5. run
make gen nodejs_sdk
c
Sure, you can try that. That should work since you'd only be generating the SDKs. But like I said before,
pulumi-provider-framework
is private, so you'll encounter issues if you try to build the provider binary since it'll look for that repo.
g
gotcha, can you share that as zip / binary as you mentioned before?
c
gotcha, can you share that as zip / binary as you mentioned before?
Oh I said I would give a ZIP of the private template, not the
pulumi-provider-framework
🙂 sorry for not being clear. I'd be happy to DM the template to you.
g
gotcha
DM works
c
Posting here from our private conversation for posterity: I suggest starting with the Pulumi boilerplate repo and understand that first before tackling
pulschema
. It's easier to bring
pulschema
into their template due to the private module
pulumi-provider-framework
dependency that I have with my template.
pulumi-provider-framework
is an HTTP client. As long as you have a Pulumi
schema.json
generating successfully, you can build your own HTTP client library that interacts with the REST API as shown in Pulumi's own examples. At some point in the future, I might decide to make
pulumi-provider-framework
public but I haven't had the time to think about it and not certain about it just yet.
128 Views