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