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

[crd-generator] Fix float support #4581

Merged
merged 1 commit into from Nov 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -32,6 +32,7 @@

import static io.sundr.model.utils.Types.BOOLEAN_REF;
import static io.sundr.model.utils.Types.DOUBLE_REF;
import static io.sundr.model.utils.Types.FLOAT_REF;
import static io.sundr.model.utils.Types.INT_REF;
import static io.sundr.model.utils.Types.LONG_REF;
import static io.sundr.model.utils.Types.STRING_REF;
Expand Down Expand Up @@ -70,6 +71,7 @@ public abstract class AbstractJsonSchema<T, B> {

protected static final TypeRef P_INT_REF = new PrimitiveRefBuilder().withName("int").build();
protected static final TypeRef P_LONG_REF = new PrimitiveRefBuilder().withName("long").build();
protected static final TypeRef P_FLOAT_REF = new PrimitiveRefBuilder().withName("float").build();
protected static final TypeRef P_DOUBLE_REF = new PrimitiveRefBuilder().withName("double").build();
protected static final TypeRef P_BOOLEAN_REF = new PrimitiveRefBuilder().withName(BOOLEAN_MARKER)
.build();
Expand Down Expand Up @@ -101,6 +103,8 @@ public abstract class AbstractJsonSchema<T, B> {
COMMON_MAPPINGS.put(P_INT_REF, INTEGER_MARKER);
COMMON_MAPPINGS.put(LONG_REF, INTEGER_MARKER);
COMMON_MAPPINGS.put(P_LONG_REF, INTEGER_MARKER);
COMMON_MAPPINGS.put(FLOAT_REF, NUMBER_MARKER);
COMMON_MAPPINGS.put(P_FLOAT_REF, NUMBER_MARKER);
COMMON_MAPPINGS.put(DOUBLE_REF, NUMBER_MARKER);
COMMON_MAPPINGS.put(P_DOUBLE_REF, NUMBER_MARKER);
COMMON_MAPPINGS.put(BOOLEAN_REF, BOOLEAN_MARKER);
Expand Down
Expand Up @@ -38,6 +38,26 @@ public void setMyLong(long myLong) {
this.myLong = myLong;
}

private double myDouble;

public double getMyDouble() {
return myDouble;
}

public void setMyDouble(long myDouble) {
this.myDouble = myDouble;
}

private float myFloat;

public float getMyFloat() {
return myFloat;
}

public void setMyFloat(long myFloat) {
this.myFloat = myFloat;
}

@JsonIgnore
public Class<?> clazz;
}
Expand Up @@ -69,6 +69,8 @@ void shouldCreateJsonSchemaFromClass() {
Map<String, JSONSchemaProps> spec = properties.get("spec").getProperties();
assertEquals("integer", spec.get("myInt").getType());
assertEquals("integer", spec.get("myLong").getType());
assertEquals("number", spec.get("myDouble").getType());
assertEquals("number", spec.get("myFloat").getType());
Map<String, JSONSchemaProps> status = properties.get("status").getProperties();
assertEquals("string", status.get("message").getType());
}
Expand Down