-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use lookup maps for transformation request/response body and path par…
…ams (#205) * Upgrade pulschema to the latest * Update all other packages as well and fix errors * Handle request body transformation from SDK names to API names * Handle request/response body transformation using lookup maps
- Loading branch information
1 parent
4d371fe
commit 150212b
Showing
11 changed files
with
770 additions
and
3,245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package rest | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
|
||
"github.com/getkin/kin-openapi/openapi3" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" | ||
|
||
pschema "github.com/pulumi/pulumi/pkg/v3/codegen/schema" | ||
|
||
openapigen "github.com/cloudy-sky-software/pulschema/pkg" | ||
) | ||
|
||
var packageName = "generic" | ||
|
||
func genericPulumiSchema(openapiDoc *openapi3.T) (pschema.PackageSpec, openapigen.ProviderMetadata, openapi3.T) { | ||
pkg := pschema.PackageSpec{ | ||
Name: packageName, | ||
Description: "A Pulumi package for creating and managing Generic Provider resources.", | ||
DisplayName: "Generic", | ||
License: "Apache-2.0", | ||
Keywords: []string{ | ||
"pulumi", | ||
packageName, | ||
"category/cloud", | ||
"kind/native", | ||
}, | ||
Homepage: "https://cloudysky.software", | ||
Publisher: "Cloudy Sky Software", | ||
Repository: "https://github.com/cloudy-sky-software/pulumi-fake-native", | ||
|
||
Config: pschema.ConfigSpec{ | ||
Variables: map[string]pschema.PropertySpec{ | ||
"apiKey": { | ||
Description: "The API key", | ||
TypeSpec: pschema.TypeSpec{Type: "string"}, | ||
Language: map[string]pschema.RawMessage{ | ||
"csharp": rawMessage(map[string]interface{}{ | ||
"name": "ApiKey", | ||
}), | ||
}, | ||
Secret: true, | ||
}, | ||
}, | ||
}, | ||
|
||
Provider: pschema.ResourceSpec{ | ||
ObjectTypeSpec: pschema.ObjectTypeSpec{ | ||
Description: "The provider type for the Generic package.", | ||
Type: "object", | ||
}, | ||
InputProperties: map[string]pschema.PropertySpec{ | ||
"apiKey": { | ||
DefaultInfo: &pschema.DefaultSpec{ | ||
Environment: []string{ | ||
"FAKE_APIKEY", | ||
}, | ||
}, | ||
Description: "The API key.", | ||
TypeSpec: pschema.TypeSpec{Type: "string"}, | ||
Language: map[string]pschema.RawMessage{ | ||
"csharp": rawMessage(map[string]interface{}{ | ||
"name": "ApiKey", | ||
}), | ||
}, | ||
Secret: true, | ||
}, | ||
}, | ||
}, | ||
|
||
PluginDownloadURL: "github://api.github.com/cloudy-sky-software/pulumi-fake-native", | ||
Types: map[string]pschema.ComplexTypeSpec{}, | ||
Resources: map[string]pschema.ResourceSpec{}, | ||
Functions: map[string]pschema.FunctionSpec{}, | ||
Language: map[string]pschema.RawMessage{}, | ||
} | ||
|
||
csharpNamespaces := map[string]string{ | ||
"": "Provider", | ||
} | ||
|
||
openAPICtx := &openapigen.OpenAPIContext{ | ||
Doc: *openapiDoc, | ||
Pkg: &pkg, | ||
} | ||
|
||
providerMetadata, updatedOpenAPIDoc, err := openAPICtx.GatherResourcesFromAPI(csharpNamespaces) | ||
if err != nil { | ||
contract.Failf("generating resources from OpenAPI spec: %v", err) | ||
} | ||
|
||
metadata := openapigen.ProviderMetadata{ | ||
ResourceCRUDMap: providerMetadata.ResourceCRUDMap, | ||
AutoNameMap: providerMetadata.AutoNameMap, | ||
SDKToAPINameMap: providerMetadata.SDKToAPINameMap, | ||
APIToSDKNameMap: providerMetadata.APIToSDKNameMap, | ||
PathParamNameMap: providerMetadata.PathParamNameMap, | ||
} | ||
|
||
return pkg, metadata, updatedOpenAPIDoc | ||
} | ||
|
||
func rawMessage(v interface{}) pschema.RawMessage { | ||
var out bytes.Buffer | ||
encoder := json.NewEncoder(&out) | ||
encoder.SetEscapeHTML(false) | ||
err := encoder.Encode(v) | ||
contract.Assert(err == nil) | ||
return out.Bytes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.