From d67f7c99265c5f20c8af75039af4b6d16b83fa66 Mon Sep 17 00:00:00 2001 From: Lukas Schmierer Date: Mon, 4 Oct 2021 13:11:55 +0200 Subject: [PATCH] print correct type in json format comment --- .../fhir/r4/utils/GraphQLSchemaGenerator.java | 16 ++++++++++++++-- .../fhir/r5/utils/GraphQLSchemaGenerator.java | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/GraphQLSchemaGenerator.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/GraphQLSchemaGenerator.java index 9abf0d8db..f48f5f25a 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/GraphQLSchemaGenerator.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/GraphQLSchemaGenerator.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -65,6 +66,12 @@ public class GraphQLSchemaGenerator { public enum FHIROperationType {READ, SEARCH, CREATE, UPDATE, DELETE}; private static final String INNER_TYPE_NAME = "gql.type.name"; + private static final Set JSON_NUMBER_TYPES = new HashSet() {{ + add("decimal"); + add("positiveInt"); + add("unsignedInt"); + }}; + IWorkerContext context; public GraphQLSchemaGenerator(IWorkerContext context) { @@ -411,7 +418,7 @@ public class GraphQLSchemaGenerator { if (gqlName.equals(name)) { writer.write("scalar "); writer.write(name); - writer.write(" # JSON Format: String"); + writer.write(" # JSON Format: string"); } else { writer.write("# Search Param "); writer.write(name); @@ -426,7 +433,12 @@ public class GraphQLSchemaGenerator { if (!ed.getType().isEmpty() && ed.getType().get(0).getCodeElement().hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type")) return ed.getType().get(0).getCodeElement().getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type"); } - return "??"; + // all primitives but JSON_NUMBER_TYPES are represented as JSON strings + if (JSON_NUMBER_TYPES.contains(sd.getName())) { + return "number"; + } else { + return "string"; + } } private String getGqlname(String name) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java index aab760dec..8338c78bd 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java @@ -42,6 +42,7 @@ import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; +import java.util.HashSet; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,7 +51,6 @@ import java.util.Set; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.context.IWorkerContext; -import org.hl7.fhir.r5.model.Constants; import org.hl7.fhir.r5.model.ElementDefinition; import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent; import org.hl7.fhir.r5.model.Enumerations.SearchParamType; @@ -65,6 +65,12 @@ public class GraphQLSchemaGenerator { public enum FHIROperationType {READ, SEARCH, CREATE, UPDATE, DELETE}; private static final String INNER_TYPE_NAME = "gql.type.name"; + private static final Set JSON_NUMBER_TYPES = new HashSet() {{ + add("decimal"); + add("positiveInt"); + add("unsignedInt"); + }}; + IWorkerContext context; private ProfileUtilities profileUtilities; private String version; @@ -415,7 +421,7 @@ public class GraphQLSchemaGenerator { if (gqlName.equals(name)) { writer.write("scalar "); writer.write(name); - writer.write(" # JSON Format: String"); + writer.write(" # JSON Format: string"); } else { writer.write("# Search Param "); writer.write(name); @@ -430,7 +436,12 @@ public class GraphQLSchemaGenerator { if (!ed.getType().isEmpty() && ed.getType().get(0).getCodeElement().hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type")) return ed.getType().get(0).getCodeElement().getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type"); } - return "??"; + // all primitives but JSON_NUMBER_TYPES are represented as JSON strings + if (JSON_NUMBER_TYPES.contains(sd.getName())) { + return "number"; + } else { + return "string"; + } } private String getGqlname(String name) {