Skip to content

Commit

Permalink
Merge #11137
Browse files Browse the repository at this point in the history
11137: Higher fidelity schema [un]marshaling r=iwahbe a=iwahbe

This PR improves the fidelity with which we convert between `schema.PackageInfoSpec` and `schema.Package`.

Co-authored-by: Ian Wahbe <ian@wahbe.com>
  • Loading branch information
bors[bot] and iwahbe committed Oct 25, 2022
2 parents 9b0c5fc + 4532225 commit b3e41d0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
28 changes: 15 additions & 13 deletions pkg/codegen/schema/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,21 @@ func newBinder(info PackageInfoSpec, spec specSource, loader Loader,
}

pkg := &Package{
moduleFormat: moduleFormatRegexp,
Name: info.Name,
DisplayName: info.DisplayName,
Version: version,
Description: info.Description,
Keywords: info.Keywords,
Homepage: info.Homepage,
License: info.License,
Attribution: info.Attribution,
Repository: info.Repository,
PluginDownloadURL: info.PluginDownloadURL,
Publisher: info.Publisher,
Language: language,
moduleFormat: moduleFormatRegexp,
Name: info.Name,
DisplayName: info.DisplayName,
Version: version,
Description: info.Description,
Keywords: info.Keywords,
Homepage: info.Homepage,
License: info.License,
Attribution: info.Attribution,
Repository: info.Repository,
PluginDownloadURL: info.PluginDownloadURL,
Publisher: info.Publisher,
AllowedPackageNames: info.AllowedPackageNames,
LogoURL: info.LogoURL,
Language: language,
}

// We want to use the same loader instance for all referenced packages, so only instantiate the loader if the
Expand Down
39 changes: 25 additions & 14 deletions pkg/codegen/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ type Package struct {
PluginDownloadURL string
// Publisher is the name of the person or organization that authored and published the package.
Publisher string
// A list of allowed package name in addition to the Name property.
AllowedPackageNames []string

// Types is the list of non-resource types defined by the package.
Types []Type
Expand Down Expand Up @@ -938,21 +940,30 @@ func (pkg *Package) MarshalSpec() (spec *PackageSpec, err error) {
}

spec = &PackageSpec{
Name: pkg.Name,
Version: version,
Description: pkg.Description,
Keywords: pkg.Keywords,
Homepage: pkg.Homepage,
License: pkg.License,
Attribution: pkg.Attribution,
Repository: pkg.Repository,
LogoURL: pkg.LogoURL,
PluginDownloadURL: pkg.PluginDownloadURL,
Meta: metadata,
Types: map[string]ComplexTypeSpec{},
Resources: map[string]ResourceSpec{},
Functions: map[string]FunctionSpec{},
Name: pkg.Name,
Version: version,
DisplayName: pkg.DisplayName,
Publisher: pkg.Publisher,
Description: pkg.Description,
Keywords: pkg.Keywords,
Homepage: pkg.Homepage,
License: pkg.License,
Attribution: pkg.Attribution,
Repository: pkg.Repository,
LogoURL: pkg.LogoURL,
PluginDownloadURL: pkg.PluginDownloadURL,
Meta: metadata,
Types: map[string]ComplexTypeSpec{},
Resources: map[string]ResourceSpec{},
Functions: map[string]FunctionSpec{},
AllowedPackageNames: pkg.AllowedPackageNames,
}

lang, err := marshalLanguage(pkg.Language)
if err != nil {
return nil, fmt.Errorf("marshaling package language: %w", err)
}
spec.Language = lang

spec.Config.Required, spec.Config.Variables, err = pkg.marshalProperties(pkg.Config, true)
if err != nil {
Expand Down

0 comments on commit b3e41d0

Please sign in to comment.