Skip to content

Commit

Permalink
[crd-generator] Fix float support
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP authored and manusa committed Nov 23, 2022
1 parent 40b48b5 commit 66ca558
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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 @@ -100,6 +102,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

0 comments on commit 66ca558

Please sign in to comment.