github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/go/importer.go (about) 1 // Copyright 2016-2021, Pulumi Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package gen 16 17 import ( 18 "encoding/json" 19 20 "github.com/pulumi/pulumi/pkg/v3/codegen/schema" 21 ) 22 23 // GoPackageInfo holds information required to generate the Go SDK from a schema. 24 type GoPackageInfo struct { 25 // Base path for package imports 26 // 27 // github.com/pulumi/pulumi-kubernetes/sdk/go/kubernetes 28 ImportBasePath string `json:"importBasePath,omitempty"` 29 30 // Module path for go.mod 31 // 32 // go get github.com/pulumi/pulumi-aws-native/sdk/go/aws@v0.16.0 33 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ module path 34 // ~~~~~~ package path - can be any number of path parts 35 // ~~~~~~~ version 36 ModulePath string `json:"modulePath,omitempty"` 37 38 // Explicit package name, which may be different to the import path. 39 RootPackageName string `json:"rootPackageName,omitempty"` 40 41 // Map from module -> package name 42 // 43 // { "flowcontrol.apiserver.k8s.io/v1alpha1": "flowcontrol/v1alpha1" } 44 // 45 ModuleToPackage map[string]string `json:"moduleToPackage,omitempty"` 46 47 // Map from package name -> package alias 48 // 49 // { "github.com/pulumi/pulumi-kubernetes/sdk/go/kubernetes/flowcontrol/v1alpha1": "flowcontrolv1alpha1" } 50 // 51 PackageImportAliases map[string]string `json:"packageImportAliases,omitempty"` 52 53 // Generate container types (arrays, maps, pointer output types etc.) for each resource. 54 // These are typically used to support external references. 55 GenerateResourceContainerTypes bool `json:"generateResourceContainerTypes,omitempty"` 56 57 // The version of the Pulumi SDK used with this provider, e.g. 3. 58 // Used to generate doc links for pulumi builtin types. If omitted, the latest SDK version is used. 59 PulumiSDKVersion int `json:"pulumiSDKVersion,omitempty"` 60 61 // Feature flag to disable generating `$fnOutput` invoke 62 // function versions to save space. 63 DisableFunctionOutputVersions bool `json:"disableFunctionOutputVersions,omitempty"` 64 65 // Determines whether to make single-return-value methods return an output struct or the value. 66 LiftSingleValueMethodReturns bool `json:"liftSingleValueMethodReturns,omitempty"` 67 68 // Feature flag to disable generating input type registration. This is a 69 // space saving measure. 70 DisableInputTypeRegistrations bool `json:"disableInputTypeRegistrations,omitempty"` 71 72 // Feature flag to disable generating Pulumi object default functions. This is a 73 // space saving measure. 74 DisableObjectDefaults bool `json:"disableObjectDefaults,omitempty"` 75 76 // GenerateExtraInputTypes determines whether or not the code generator generates input (and output) types for 77 // all plain types, instead of for only types that are used as input/output types. 78 GenerateExtraInputTypes bool `json:"generateExtraInputTypes,omitempty"` 79 80 // omitExtraInputTypes determines whether the code generator generates input (and output) types 81 // for all plain types, instead of for only types that are used as input/output types. 82 OmitExtraInputTypes bool `json:"omitExtraInputTypes,omitempty"` 83 84 // Respect the Pkg.Version field for emitted code. 85 RespectSchemaVersion bool `json:"respectSchemaVersion,omitempty"` 86 87 // InternalDependencies are blank imports that are emitted in the SDK so that `go mod tidy` does not remove the 88 // associated module dependencies from the SDK's go.mod. 89 InternalDependencies []string `json:"internalDependencies,omitempty"` 90 } 91 92 // Importer implements schema.Language for Go. 93 var Importer schema.Language = importer(0) 94 95 type importer int 96 97 // ImportDefaultSpec decodes language-specific metadata associated with a DefaultValue. 98 func (importer) ImportDefaultSpec(def *schema.DefaultValue, raw json.RawMessage) (interface{}, error) { 99 return raw, nil 100 } 101 102 // ImportPropertySpec decodes language-specific metadata associated with a Property. 103 func (importer) ImportPropertySpec(property *schema.Property, raw json.RawMessage) (interface{}, error) { 104 return raw, nil 105 } 106 107 // ImportObjectTypeSpec decodes language-specific metadata associated with a ObjectType. 108 func (importer) ImportObjectTypeSpec(object *schema.ObjectType, raw json.RawMessage) (interface{}, error) { 109 return raw, nil 110 } 111 112 // ImportResourceSpec decodes language-specific metadata associated with a Resource. 113 func (importer) ImportResourceSpec(resource *schema.Resource, raw json.RawMessage) (interface{}, error) { 114 return raw, nil 115 } 116 117 // ImportFunctionSpec decodes language-specific metadata associated with a Function. 118 func (importer) ImportFunctionSpec(function *schema.Function, raw json.RawMessage) (interface{}, error) { 119 return raw, nil 120 } 121 122 // ImportPackageSpec decodes language-specific metadata associated with a Package. 123 func (importer) ImportPackageSpec(pkg *schema.Package, raw json.RawMessage) (interface{}, error) { 124 var info GoPackageInfo 125 if err := json.Unmarshal(raw, &info); err != nil { 126 return nil, err 127 } 128 return info, nil 129 }