2024-02-08 03:48:59 -06:00
|
|
|
// Copyright (c) The OpenTofu Authors
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
2023-05-02 10:33:06 -05:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-02-25 15:32:47 -06:00
|
|
|
package jsonprovider
|
|
|
|
|
|
|
|
import (
|
2023-09-20 06:35:35 -05:00
|
|
|
"github.com/opentofu/opentofu/internal/providers"
|
2019-02-25 15:32:47 -06:00
|
|
|
)
|
|
|
|
|
2023-01-09 03:48:23 -06:00
|
|
|
type Schema struct {
|
2019-02-25 15:32:47 -06:00
|
|
|
Version uint64 `json:"version"`
|
2023-01-09 03:48:23 -06:00
|
|
|
Block *Block `json:"block,omitempty"`
|
2019-02-25 15:32:47 -06:00
|
|
|
}
|
|
|
|
|
2024-09-09 06:51:39 -05:00
|
|
|
// marshalSchema is a convenience wrapper around marshalBlock. Schema version
|
2019-02-25 15:32:47 -06:00
|
|
|
// should be set by the caller.
|
2023-07-05 17:06:07 -05:00
|
|
|
func marshalSchema(schema providers.Schema) *Schema {
|
|
|
|
if schema.Block == nil {
|
2023-01-09 03:48:23 -06:00
|
|
|
return &Schema{}
|
2019-02-25 15:32:47 -06:00
|
|
|
}
|
|
|
|
|
2023-01-09 03:48:23 -06:00
|
|
|
var ret Schema
|
2023-07-05 17:06:07 -05:00
|
|
|
ret.Block = marshalBlock(schema.Block)
|
|
|
|
ret.Version = uint64(schema.Version)
|
2019-02-25 15:32:47 -06:00
|
|
|
|
|
|
|
return &ret
|
|
|
|
}
|
|
|
|
|
2023-07-05 17:06:07 -05:00
|
|
|
func marshalSchemas(schemas map[string]providers.Schema) map[string]*Schema {
|
|
|
|
if schemas == nil {
|
2023-01-09 03:48:23 -06:00
|
|
|
return map[string]*Schema{}
|
2019-02-25 15:32:47 -06:00
|
|
|
}
|
2023-07-05 17:06:07 -05:00
|
|
|
ret := make(map[string]*Schema, len(schemas))
|
|
|
|
for k, v := range schemas {
|
2019-02-25 15:32:47 -06:00
|
|
|
ret[k] = marshalSchema(v)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|