diff --git a/back-end/hub-codegen/src/main/java/io/apicurio/hub/api/codegen/JaxRsEnumRule.java b/back-end/hub-codegen/src/main/java/io/apicurio/hub/api/codegen/JaxRsEnumRule.java new file mode 100644 index 000000000..28732e01b --- /dev/null +++ b/back-end/hub-codegen/src/main/java/io/apicurio/hub/api/codegen/JaxRsEnumRule.java @@ -0,0 +1,326 @@ +/* + * Copyright 2019 Red Hat + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.apicurio.hub.api.codegen; + + +import static org.apache.commons.lang3.StringUtils.capitalize; +import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.jsonschema2pojo.rules.PrimitiveTypes.isPrimitive; +import static org.jsonschema2pojo.util.TypeUtil.resolveType; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.jsonschema2pojo.Schema; +import org.jsonschema2pojo.exception.ClassAlreadyExistsException; +import org.jsonschema2pojo.exception.GenerationException; +import org.jsonschema2pojo.rules.Rule; +import org.jsonschema2pojo.rules.RuleFactory; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.sun.codemodel.ClassType; +import com.sun.codemodel.JBlock; +import com.sun.codemodel.JClass; +import com.sun.codemodel.JClassAlreadyExistsException; +import com.sun.codemodel.JClassContainer; +import com.sun.codemodel.JConditional; +import com.sun.codemodel.JDefinedClass; +import com.sun.codemodel.JEnumConstant; +import com.sun.codemodel.JExpr; +import com.sun.codemodel.JExpression; +import com.sun.codemodel.JFieldVar; +import com.sun.codemodel.JForEach; +import com.sun.codemodel.JInvocation; +import com.sun.codemodel.JMethod; +import com.sun.codemodel.JMod; +import com.sun.codemodel.JType; +import com.sun.codemodel.JVar; + +/** + * @author eric.wittmann@gmail.com + */ +public class JaxRsEnumRule implements Rule { + + private static final String VALUE_FIELD_NAME = "value"; + + private final RuleFactory ruleFactory; + + protected JaxRsEnumRule(RuleFactory ruleFactory) { + this.ruleFactory = ruleFactory; + } + + /** + * Applies this schema rule to take the required code generation steps. + *

+ * A Java {@link Enum} is created, with constants for each of the enum + * values present in the schema. The enum name is derived from the nodeName, + * and the enum type itself is created as an inner class of the owning type. + * In the rare case that no owning type exists (the enum is the root of the + * schema), then the enum becomes a public class in its own right. + *

+ * The actual JSON value for each enum constant is held in a property called + * "value" in the generated type. A static factory method + * fromValue(String) is added to the generated enum, and the + * methods are annotated to allow Jackson to marshal/unmarshal values + * correctly. + * + * @param nodeName + * the name of the property which is an "enum" + * @param node + * the enum node + * @param container + * the class container (class or package) to which this enum + * should be added + * @return the newly generated Java type that was created to represent the + * given enum + * @see org.jsonschema2pojo.rules.Rule#apply(java.lang.String, com.fasterxml.jackson.databind.JsonNode, com.fasterxml.jackson.databind.JsonNode, java.lang.Object, org.jsonschema2pojo.Schema) + */ + @Override + public JType apply(String nodeName, JsonNode node, JsonNode parent, JClassContainer container, + Schema schema) { + + JDefinedClass _enum; + try { + _enum = createEnum(node, nodeName, container); + } catch (ClassAlreadyExistsException e) { + return e.getExistingClass(); + } + + schema.setJavaTypeIfEmpty(_enum); + + if (node.has("javaInterfaces")) { + addInterfaces(_enum, node.get("javaInterfaces")); + } + + // copy our node; remove the javaType as it will throw off the TypeRule for our case + ObjectNode typeNode = (ObjectNode)node.deepCopy(); + typeNode.remove("javaType"); + + // If type is specified on the enum, get a type rule for it. Otherwise, we're a string. + // (This is different from the default of Object, which is why we don't do this for every case.) + JType backingType = node.has("type") ? + ruleFactory.getTypeRule().apply(nodeName, typeNode, parent, container, schema) : + container.owner().ref(String.class); + + JFieldVar valueField = addValueField(_enum, backingType); + + // override toString only if we have a sensible string to return + if(isString(backingType)){ + addToString(_enum, valueField); + } + + addValueMethod(_enum, valueField); + + addEnumConstants(node.path("enum"), _enum, node.path("javaEnumNames"), backingType); + addFactoryMethod(_enum, backingType); + + return _enum; + } + + private JDefinedClass createEnum(JsonNode node, String nodeName, JClassContainer container) throws ClassAlreadyExistsException { + + int modifiers = container.isPackage() ? JMod.PUBLIC : JMod.PUBLIC; + + try { + if (node.has("javaType")) { + String fqn = node.get("javaType").asText(); + + if (isPrimitive(fqn, container.owner())) { + throw new GenerationException("Primitive type '" + fqn + "' cannot be used as an enum."); + } + + try { + Class existingClass = Thread.currentThread().getContextClassLoader().loadClass(fqn); + throw new ClassAlreadyExistsException(container.owner().ref(existingClass)); + } catch (ClassNotFoundException e) { + return container.owner()._class(fqn, ClassType.ENUM); + } + } else { + try { + return container._class(modifiers, getEnumName(nodeName, node, container), ClassType.ENUM); + } catch (JClassAlreadyExistsException e) { + throw new GenerationException(e); + } + } + } catch (JClassAlreadyExistsException e) { + throw new ClassAlreadyExistsException(e.getExistingClass()); + } + } + + private void addFactoryMethod(JDefinedClass _enum, JType backingType) { + JFieldVar quickLookupMap = addQuickLookupMap(_enum, backingType); + + JMethod fromValue = _enum.method(JMod.PUBLIC | JMod.STATIC, _enum, "fromValue"); + JVar valueParam = fromValue.param(backingType, "value"); + + JBlock body = fromValue.body(); + JVar constant = body.decl(_enum, "constant"); + constant.init(quickLookupMap.invoke("get").arg(valueParam)); + + JConditional _if = body._if(constant.eq(JExpr._null())); + + JInvocation illegalArgumentException = JExpr._new(_enum.owner().ref(IllegalArgumentException.class)); + JExpression expr = valueParam; + + // if string no need to add "" + if(!isString(backingType)){ + expr = expr.plus(JExpr.lit("")); + } + + illegalArgumentException.arg(expr); + _if._then()._throw(illegalArgumentException); + _if._else()._return(constant); + + ruleFactory.getAnnotator().enumCreatorMethod(_enum, fromValue); + } + + private JFieldVar addQuickLookupMap(JDefinedClass _enum, JType backingType) { + + JClass lookupType = _enum.owner().ref(Map.class).narrow(backingType.boxify(), _enum); + JFieldVar lookupMap = _enum.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, lookupType, "CONSTANTS"); + + JClass lookupImplType = _enum.owner().ref(HashMap.class).narrow(backingType.boxify(), _enum); + lookupMap.init(JExpr._new(lookupImplType)); + + JForEach forEach = _enum.init().forEach(_enum, "c", JExpr.invoke("values")); + JInvocation put = forEach.body().invoke(lookupMap, "put"); + put.arg(forEach.var().ref("value")); + put.arg(forEach.var()); + + return lookupMap; + } + + private JFieldVar addValueField(JDefinedClass _enum, JType type) { + JFieldVar valueField = _enum.field(JMod.PRIVATE | JMod.FINAL, type, VALUE_FIELD_NAME); + + JMethod constructor = _enum.constructor(JMod.PRIVATE); + JVar valueParam = constructor.param(type, VALUE_FIELD_NAME); + JBlock body = constructor.body(); + body.assign(JExpr._this().ref(valueField), valueParam); + + return valueField; + } + + private void addToString(JDefinedClass _enum, JFieldVar valueField) { + JMethod toString = _enum.method(JMod.PUBLIC, String.class, "toString"); + JBlock body = toString.body(); + + JExpression toReturn = JExpr._this().ref(valueField); + if(!isString(valueField.type())){ + toReturn = toReturn.plus(JExpr.lit("")); + } + + body._return(toReturn); + + toString.annotate(Override.class); + } + + private void addValueMethod(JDefinedClass _enum, JFieldVar valueField) { + JMethod fromValue = _enum.method(JMod.PUBLIC, valueField.type(), "value"); + + JBlock body = fromValue.body(); + body._return(JExpr._this().ref(valueField)); + + ruleFactory.getAnnotator().enumValueMethod(_enum, fromValue); + } + + private boolean isString(JType type){ + return type.fullName().equals(String.class.getName()); + } + + private void addEnumConstants(JsonNode node, JDefinedClass _enum, JsonNode customNames, JType type) { + Collection existingConstantNames = new ArrayList(); + for (int i = 0; i < node.size(); i++) { + JsonNode value = node.path(i); + + if (!value.isNull()) { + String constantName = getConstantName(value.asText(), customNames.path(i).asText()); + constantName = makeUnique(constantName, existingConstantNames); + existingConstantNames.add(constantName); + + JEnumConstant constant = _enum.enumConstant(constantName); + + String typeName = type.unboxify().fullName(); + if(typeName.equals("int")){ // integer + constant.arg(JExpr.lit(value.intValue())); + } else if(typeName.equals("long")){ // integer-as-long + constant.arg(JExpr.lit(value.longValue())); + } else if(typeName.equals("double")){ // number + constant.arg(JExpr.lit(value.doubleValue())); + } else if(typeName.equals("boolean")){ // boolean + constant.arg(JExpr.lit(value.booleanValue())); + } else { // string, null, array, object? + // only string should really be valid here... TODO throw error? + constant.arg(JExpr.lit(value.asText())); + } + ruleFactory.getAnnotator().enumConstant(_enum, constant, value.asText()); + } + } + } + + private String getEnumName(String nodeName, JsonNode node, JClassContainer container) { + String fieldName = ruleFactory.getNameHelper().getFieldName(nodeName, node); + String className = ruleFactory.getNameHelper().replaceIllegalCharacters(capitalize(fieldName)); + String normalizedName = ruleFactory.getNameHelper().normalizeName(className); + + Collection existingClassNames = new ArrayList(); + for (Iterator classes = container.classes(); classes.hasNext();) { + existingClassNames.add(classes.next().name()); + } + return makeUnique(normalizedName, existingClassNames); + } + + private String makeUnique(String name, Collection existingNames) { + boolean found = false; + for (String existingName : existingNames) { + if (name.equalsIgnoreCase(existingName)) { + found = true; + break; + } + } + if (found) { + name = makeUnique(name + "_", existingNames); + } + return name; + } + + protected String getConstantName(String nodeName, String customName) { + if (isNotBlank(customName)) { + return customName; + } + + if (isEmpty(nodeName)) { + nodeName = "__EMPTY__"; + } else if (Character.isDigit(nodeName.charAt(0))) { + nodeName = "_" + nodeName; + } + + return nodeName; + } + + private void addInterfaces(JDefinedClass jclass, JsonNode javaInterfaces) { + for (JsonNode i : javaInterfaces) { + jclass._implements(resolveType(jclass._package(), i.asText())); + } + } + +} \ No newline at end of file diff --git a/back-end/hub-codegen/src/main/java/io/apicurio/hub/api/codegen/OpenApi2JaxRs.java b/back-end/hub-codegen/src/main/java/io/apicurio/hub/api/codegen/OpenApi2JaxRs.java index 53b653523..6d0884d5a 100644 --- a/back-end/hub-codegen/src/main/java/io/apicurio/hub/api/codegen/OpenApi2JaxRs.java +++ b/back-end/hub-codegen/src/main/java/io/apicurio/hub/api/codegen/OpenApi2JaxRs.java @@ -35,6 +35,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; +import org.jsonschema2pojo.Annotator; import org.jsonschema2pojo.DefaultGenerationConfig; import org.jsonschema2pojo.GenerationConfig; import org.jsonschema2pojo.Jackson2Annotator; @@ -42,6 +43,7 @@ import org.jsonschema2pojo.SchemaGenerator; import org.jsonschema2pojo.SchemaMapper; import org.jsonschema2pojo.SchemaStore; +import org.jsonschema2pojo.rules.Rule; import org.jsonschema2pojo.rules.RuleFactory; import com.fasterxml.jackson.databind.ObjectMapper; @@ -54,6 +56,7 @@ import com.squareup.javapoet.TypeName; import com.squareup.javapoet.TypeSpec; import com.squareup.javapoet.TypeSpec.Builder; +import com.sun.codemodel.JClassContainer; import com.sun.codemodel.JCodeModel; import com.sun.codemodel.JType; @@ -363,7 +366,7 @@ private String generateJavaInterface(CodegenJavaInterface _interface) { for (CodegenJavaArgument cgArgument : cgMethod.getArguments()) { TypeName defaultParamType = ClassName.OBJECT; if (cgArgument.getIn().equals("body")) { - defaultParamType = ClassName.get("javax.ws.rs.core", "Request"); + defaultParamType = ClassName.get("java.io", "InputStream"); } TypeName paramType = generateTypeName(cgArgument.getCollection(), cgArgument.getType(), cgArgument.getFormat(), cgArgument.getRequired(), defaultParamType); @@ -546,7 +549,7 @@ public boolean isIncludeToString() { }; SchemaMapper schemaMapper = new SchemaMapper( - new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore() { + new JaxRsRuleFactory(config, new Jackson2Annotator(config), new SchemaStore() { @Override public Schema create(Schema parent, String path, String refFragmentPathDelimiters) { String beanClassname = schemaRefToFQCN(path); @@ -658,6 +661,24 @@ public JaxRsProjectSettings getSettings() { public void setUpdateOnly(boolean updateOnly) { this.updateOnly = updateOnly; } + + public static class JaxRsRuleFactory extends RuleFactory { + + /** + * Constructor. + */ + public JaxRsRuleFactory(GenerationConfig generationConfig, Annotator annotator, SchemaStore schemaStore) { + super(generationConfig, annotator, schemaStore); + } + + /** + * @see org.jsonschema2pojo.rules.RuleFactory#getEnumRule() + */ + @Override + public Rule getEnumRule() { + return new JaxRsEnumRule(this); + } + } /** * Represents some basic meta information about the project being generated. diff --git a/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-gatewayApi-full/generated-api/src/main/java/org/example/api/beans/Api.java b/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-gatewayApi-full/generated-api/src/main/java/org/example/api/beans/Api.java index 6529415a4..cadb26047 100644 --- a/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-gatewayApi-full/generated-api/src/main/java/org/example/api/beans/Api.java +++ b/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-gatewayApi-full/generated-api/src/main/java/org/example/api/beans/Api.java @@ -321,8 +321,8 @@ public void setApiPolicies(List apiPolicies) { public enum EndpointContentType { - JSON("json"), - XML("xml"); + json("json"), + xml("xml"); private final String value; private final static Map CONSTANTS = new HashMap(); @@ -360,8 +360,8 @@ public static Api.EndpointContentType fromValue(String value) { public enum EndpointType { - REST("rest"), - SOAP("soap"); + rest("rest"), + soap("soap"); private final String value; private final static Map CONSTANTS = new HashMap(); diff --git a/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-registryApi-full/generated-api/src/main/java/org/example/api/ArtifactsResource.java b/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-registryApi-full/generated-api/src/main/java/org/example/api/ArtifactsResource.java index c5e489eba..e8beaf6cb 100644 --- a/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-registryApi-full/generated-api/src/main/java/org/example/api/ArtifactsResource.java +++ b/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-registryApi-full/generated-api/src/main/java/org/example/api/ArtifactsResource.java @@ -1,5 +1,6 @@ package org.example.api; +import java.io.InputStream; import java.lang.Integer; import java.lang.Long; import java.lang.String; @@ -13,7 +14,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.core.Request; import org.example.api.beans.ArtifactMetaData; import org.example.api.beans.ArtifactType; import org.example.api.beans.EditableMetaData; @@ -59,7 +59,7 @@ public interface ArtifactsResource { @Consumes({"application/json", "application/x-yaml"}) ArtifactMetaData createArtifact( @HeaderParam("X-Registry-ArtifactType") ArtifactType xRegistryArtifactType, - @HeaderParam("X-Registry-ArtifactId") String xRegistryArtifactId, Request data); + @HeaderParam("X-Registry-ArtifactId") String xRegistryArtifactId, InputStream data); /** * Returns the latest version of the artifact in its raw form. The `Content-Type` of the @@ -92,7 +92,7 @@ ArtifactMetaData createArtifact( @PUT @Produces("application/json") @Consumes({"application/json", "application/x-yaml"}) - ArtifactMetaData updateArtifact(@PathParam("artifactId") String artifactId, Request data); + ArtifactMetaData updateArtifact(@PathParam("artifactId") String artifactId, InputStream data); /** * Deletes an artifact completely, resulting in all versions of the artifact also being @@ -284,7 +284,7 @@ void deleteArtifactRule(@PathParam("rule") String rule, @Produces("application/json") @Consumes({"application/json", "application/x-yaml"}) VersionMetaData createArtifactVersion(@PathParam("artifactId") String artifactId, - @HeaderParam("X-Registry-ArtifactType") ArtifactType xRegistryArtifactType, Request data); + @HeaderParam("X-Registry-ArtifactType") ArtifactType xRegistryArtifactType, InputStream data); /** * Retrieves a single version of the artifact content. Both the `artifactId` and the diff --git a/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-registryApi-full/generated-api/src/main/java/org/example/api/beans/ArtifactType.java b/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-registryApi-full/generated-api/src/main/java/org/example/api/beans/ArtifactType.java index 52873d747..ef39f2ee5 100644 --- a/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-registryApi-full/generated-api/src/main/java/org/example/api/beans/ArtifactType.java +++ b/back-end/hub-codegen/src/test/resources/OpenApi2JaxRsTest/_expected-registryApi-full/generated-api/src/main/java/org/example/api/beans/ArtifactType.java @@ -8,11 +8,11 @@ public enum ArtifactType { - AVRO("avro"), - PROTOBUFF("protobuff"), - JSON("json"), - OPENAPI("openapi"), - ASYNCAPI("asyncapi"); + avro("avro"), + protobuff("protobuff"), + json("json"), + openapi("openapi"), + asyncapi("asyncapi"); private final String value; private final static Map CONSTANTS = new HashMap(); diff --git a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApi-full/generated-api/src/main/java/org/example/api/beans/Api.java b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApi-full/generated-api/src/main/java/org/example/api/beans/Api.java index 6529415a4..cadb26047 100644 --- a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApi-full/generated-api/src/main/java/org/example/api/beans/Api.java +++ b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApi-full/generated-api/src/main/java/org/example/api/beans/Api.java @@ -321,8 +321,8 @@ public void setApiPolicies(List apiPolicies) { public enum EndpointContentType { - JSON("json"), - XML("xml"); + json("json"), + xml("xml"); private final String value; private final static Map CONSTANTS = new HashMap(); @@ -360,8 +360,8 @@ public static Api.EndpointContentType fromValue(String value) { public enum EndpointType { - REST("rest"), - SOAP("soap"); + rest("rest"), + soap("soap"); private final String value; private final static Map CONSTANTS = new HashMap(); diff --git a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/Apis.java b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/Apis.java index f409b21dc..e5812b12f 100644 --- a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/Apis.java +++ b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/Apis.java @@ -1,8 +1,8 @@ package io.openapi.simple; +import java.io.InputStream; import javax.ws.rs.PUT; import javax.ws.rs.Path; -import javax.ws.rs.core.Request; /** * A JAX-RS interface. An implementation of this interface must be provided. @@ -13,5 +13,5 @@ public interface Apis { * Publish an API and make it immediately available on the gateway. */ @PUT - void publishAnAPI(Request body); + void publishAnAPI(InputStream body); } diff --git a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/Clients.java b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/Clients.java index b3fdc7355..eb3820e9b 100644 --- a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/Clients.java +++ b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/Clients.java @@ -1,8 +1,8 @@ package io.openapi.simple; +import java.io.InputStream; import javax.ws.rs.PUT; import javax.ws.rs.Path; -import javax.ws.rs.core.Request; /** * A JAX-RS interface. An implementation of this interface must be provided. @@ -13,5 +13,5 @@ public interface Clients { * Register a Client and make it immediately available on the gateway. */ @PUT - void registerAClient(Request body); + void registerAClient(InputStream body); } diff --git a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/beans/Api.java b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/beans/Api.java index 727a7f179..7fe8776d5 100644 --- a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/beans/Api.java +++ b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-gatewayApiNoTypes/simple-api/src/main/java/io/openapi/simple/beans/Api.java @@ -321,8 +321,8 @@ public void setApiPolicies(List apiPolicies) { public enum EndpointContentType { - JSON("json"), - XML("xml"); + json("json"), + xml("xml"); private final String value; private final static Map CONSTANTS = new HashMap(); @@ -360,8 +360,8 @@ public static Api.EndpointContentType fromValue(String value) { public enum EndpointType { - REST("rest"), - SOAP("soap"); + rest("rest"), + soap("soap"); private final String value; private final static Map CONSTANTS = new HashMap(); diff --git a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-rda/src/main/java/org/example/api/TemplatesResource.java b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-rda/src/main/java/org/example/api/TemplatesResource.java index ea21cdb94..d32304270 100644 --- a/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-rda/src/main/java/org/example/api/TemplatesResource.java +++ b/back-end/hub-codegen/src/test/resources/OpenApi2ThorntailTest/_expected-rda/src/main/java/org/example/api/TemplatesResource.java @@ -1,5 +1,6 @@ package org.example.api; +import java.io.InputStream; import java.lang.String; import java.util.List; import javax.ws.rs.Consumes; @@ -10,7 +11,6 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Request; import javax.ws.rs.core.Response; /** @@ -29,7 +29,7 @@ public interface TemplatesResource { @Path("es/metadata") @POST @Consumes("application/json") - void generatedMethod2(Request data); + void generatedMethod2(InputStream data); /** * Search template metadata and return a list of matching template metadata @@ -55,7 +55,7 @@ Response thisIsTheSearchEndpointUseAGETRequestAlongWithParametersToSearchForMeta @Path("es/metadata/{id}") @PUT @Consumes("application/json") - void generatedMethod4(Request data); + void generatedMethod4(InputStream data); /** * Delete the metadata for a single template by id