Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema types for component schema generation #1667

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pulumi.provider.internal.schema;

public final class BuiltinTypeSpec {
public static final String STRING = "string";
public static final String INTEGER = "integer";
public static final String NUMBER = "number";
public static final String BOOLEAN = "boolean";
public static final String OBJECT = "object";

private BuiltinTypeSpec() {} // Prevent instantiation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pulumi.provider.internal.schema;


import java.util.Map;
import java.util.Set;

public class ComplexTypeSpec extends ObjectTypeSpec {
private ComplexTypeSpec(
String type,
Map<String, PropertySpec> properties,
Set<String> required
) {
super(type, properties, required);
}

public static ComplexTypeSpec of(String type) {
return new ComplexTypeSpec(type, null, null);
}

public static ComplexTypeSpec ofObject(
Map<String, PropertySpec> properties,
Set<String> required
) {
return new ComplexTypeSpec("object", properties, required);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.pulumi.provider.internal.schema;

import com.google.gson.annotations.SerializedName;

import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

public class ObjectTypeSpec {
@SerializedName("type")
private String type;

@SerializedName("properties")
private Map<String, PropertySpec> properties;

@SerializedName("required")
private Set<String> required;

protected ObjectTypeSpec(
String type,
Map<String, PropertySpec> properties,
Set<String> required
) {
this.type = type;
this.properties = properties;
this.required = new TreeSet<>(required);
}

public String getType() {
return type;
}

public Map<String, PropertySpec> getProperties() {
return properties;
}

public Set<String> getRequired() {
return required;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ObjectTypeSpec that = (ObjectTypeSpec) o;
return Objects.equals(type, that.type) &&
Objects.equals(properties, that.properties) &&
Objects.equals(required, that.required);
}

@Override
public int hashCode() {
return Objects.hash(type, properties, required);
}

@Override
public String toString() {
return "ObjectTypeSpec{" +
"type='" + type + '\'' +
", properties=" + properties +
", required=" + required +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.pulumi.provider.internal.schema;

import com.google.gson.annotations.SerializedName;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class PackageSpec {
@SerializedName("name")
private String name;

@SerializedName("displayName")
private String displayName;

@SerializedName("version")
private String version;

@SerializedName("resources")
private Map<String, ResourceSpec> resources = new HashMap<>();

@SerializedName("types")
private Map<String, ComplexTypeSpec> types = new HashMap<>();

@SerializedName("language")
private Map<String, Map<String, Object>> language = new HashMap<>();

public PackageSpec setName(String name) {
this.name = name;
return this;
}

public PackageSpec setDisplayName(String displayName) {
this.displayName = displayName;
return this;
}

public PackageSpec setVersion(String version) {
this.version = version;
return this;
}

public PackageSpec setResources(Map<String, ResourceSpec> resources) {
this.resources = resources;
return this;
}

public PackageSpec setTypes(Map<String, ComplexTypeSpec> types) {
this.types = types;
return this;
}

public PackageSpec setLanguage(Map<String, Map<String, Object>> language) {
this.language = language;
return this;
}

public String getName() {
return name;
}

public String getDisplayName() {
return displayName;
}

public String getVersion() {
return version;
}

public Map<String, ResourceSpec> getResources() {
return resources;
}

public Map<String, ComplexTypeSpec> getTypes() {
return types;
}

public Map<String, Map<String, Object>> getLanguage() {
return language;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PackageSpec that = (PackageSpec) o;
return Objects.equals(name, that.name) &&
Objects.equals(displayName, that.displayName) &&
Objects.equals(version, that.version) &&
Objects.equals(resources, that.resources) &&
Objects.equals(types, that.types) &&
Objects.equals(language, that.language);
}

@Override
public int hashCode() {
return Objects.hash(name, displayName, version, resources, types, language);
}

@Override
public String toString() {
return "PackageSpec{" +
"name='" + name + '\'' +
", displayName='" + displayName + '\'' +
", version='" + version + '\'' +
", resources=" + resources +
", types=" + types +
", language=" + language +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.pulumi.provider.internal.schema;

public class PropertySpec extends TypeSpec {
public PropertySpec(String type, String ref, Boolean plain, TypeSpec items, TypeSpec additionalProperties) {
super(type, ref, plain, items, additionalProperties);
}

public static PropertySpec ofBuiltin(String type) {
return ofBuiltin(type, null);
}

public static PropertySpec ofBuiltin(String type, Boolean plain) {
return new PropertySpec(type, null, plain, null, null);
}

public static PropertySpec ofRef(String ref) {
return ofRef(ref, null);
}

public static PropertySpec ofRef(String ref, Boolean plain) {
return new PropertySpec(null, ref, plain, null, null);
}

public static PropertySpec ofArray(TypeSpec items) {
return new PropertySpec("array", null, null, items, null);
}

public static PropertySpec ofDict(TypeSpec additionalProperties) {
return new PropertySpec("object", null, null, null, additionalProperties);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return super.equals(o);
}

@Override
public int hashCode() {
return super.hashCode();
}

@Override
public String toString() {
return "PropertySpec" + super.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.pulumi.provider.internal.schema;

import com.google.gson.annotations.SerializedName;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

public class ResourceSpec extends ObjectTypeSpec {
@SerializedName("isComponent")
private boolean isComponent;

@SerializedName("inputProperties")
private Map<String, PropertySpec> inputProperties;

@SerializedName("requiredInputs")
private Set<String> requiredInputs;

public ResourceSpec(
Map<String, PropertySpec> inputProperties,
Set<String> requiredInputs,
Map<String, PropertySpec> properties,
Set<String> required) {
super("object", properties, required);
this.isComponent = true;
this.inputProperties = inputProperties;
this.requiredInputs = new TreeSet<>(requiredInputs);
}

public Map<String, PropertySpec> getInputProperties() {
return inputProperties;
}

public Set<String> getRequiredInputs() {
return requiredInputs;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceSpec that = (ResourceSpec) o;
return Objects.equals(inputProperties, that.inputProperties) &&
Objects.equals(getProperties(), that.getProperties()) &&
Objects.equals(getRequired(), that.getRequired()) &&
Objects.equals(requiredInputs, that.requiredInputs);
}

@Override
public int hashCode() {
return Objects.hash(inputProperties, getProperties(), getRequired(), requiredInputs);
}

@Override
public String toString() {
return "ResourceSpec{" +
"inputProperties=" + inputProperties +
", properties=" + getProperties() +
", required=" + getRequired() +
", requiredInputs=" + requiredInputs +
'}';
}
}
Loading
Loading