Java Code Examples for org.raml.v2.api.model.v10.datamodel.TypeDeclaration#required()
The following examples show how to use
org.raml.v2.api.model.v10.datamodel.TypeDeclaration#required() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnyTypeInterpreter.java From springmvc-raml-plugin with Apache License 2.0 | 6 votes |
@Override public RamlInterpretationResult interpret(RamlRoot document, TypeDeclaration type, JCodeModel builderModel, boolean property) { AnyTypeDeclaration anyTypeDeclaration = (AnyTypeDeclaration) type; RamlInterpretationResult result = new RamlInterpretationResult(type.required()); String objectName; if ("array".equalsIgnoreCase(anyTypeDeclaration.type())) { objectName = Object.class.getSimpleName(); } else { objectName = Void.class.getSimpleName(); } result.setResolvedClass(CodeModelHelper.findFirstClassBySimpleName(builderModel, objectName)); return result; }
Example 2
Source File: BoxWhenNotRequired.java From raml-java-tools with Apache License 2.0 | 5 votes |
@Override public TypeName typeName(ReferencePluginContext referencePluginContext, TypeDeclaration ramlType, TypeName currentSuggestion) { if (! ramlType.required()) { return currentSuggestion.box(); } else { return currentSuggestion; } }
Example 3
Source File: RamlTypeHelper.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
/** * Safely get required from a type with null checks * * @param type * The RAML TypeDeclaration to check * @return true if this parameter is required, false if optional */ public static boolean isRequired(TypeDeclaration type) { if (type == null || type.required() == null) { return true; } else { return type.required(); } }
Example 4
Source File: NumberTypeInterpreter.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
@Override public RamlInterpretationResult interpret(RamlRoot document, TypeDeclaration type, JCodeModel builderModel, boolean property) { RamlInterpretationResult result = new RamlInterpretationResult(type.required()); String resolvedType = String.class.getSimpleName(); typeCheck(type); if (type instanceof NumberTypeDeclaration) { NumberTypeDeclaration numberType = (NumberTypeDeclaration) type; String format = numberType.format(); RamlTypeValidations validations = result.getValidations(); validations.withMinMax(numberType.minimum(), numberType.maximum()); if (!StringUtils.hasText(format)) { // format not supplied. Defaulting to long if it's integer since // it's safer if (type instanceof IntegerTypeDeclaration) { resolvedType = Long.class.getSimpleName(); } else { resolvedType = Double.class.getSimpleName(); } } else { resolvedType = SchemaHelper.mapSimpleType(RamlParamType.NUMBER, format, type.type()).getSimpleName(); } } if (resolvedType.equals(Double.class.getSimpleName()) && Config.getPojoConfig().isUseBigDecimals()) { resolvedType = BigDecimal.class.getName(); } if (resolvedType.equals(Long.class.getSimpleName()) && Config.getPojoConfig().isUseBigIntegers()) { resolvedType = BigInteger.class.getName(); } result.setResolvedClass(CodeModelHelper.findFirstClassBySimpleName(builderModel, resolvedType)); return result; }
Example 5
Source File: DateTypeInterpreter.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
@Override public RamlInterpretationResult interpret(RamlRoot document, TypeDeclaration type, JCodeModel builderModel, boolean property) { RamlInterpretationResult result = new RamlInterpretationResult(type.required()); result.setResolvedClass(builderModel.ref(SchemaHelper.mapDateFormat(type.type()))); return result; }
Example 6
Source File: BooleanTypeInterpreter.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
@Override public RamlInterpretationResult interpret(RamlRoot document, TypeDeclaration type, JCodeModel builderModel, boolean property) { RamlInterpretationResult result = new RamlInterpretationResult(type.required()); result.setResolvedClass(CodeModelHelper.findFirstClassBySimpleName(builderModel, Boolean.class.getSimpleName())); return result; }
Example 7
Source File: StringTypeInterpreter.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
@Override public RamlInterpretationResult interpret(RamlRoot document, TypeDeclaration type, JCodeModel builderModel, boolean property) { RamlInterpretationResult result = new RamlInterpretationResult(type.required()); if (type instanceof StringTypeDeclaration) { StringTypeDeclaration stringType = (StringTypeDeclaration) type; // do stringy stuff - enums and stuff. RamlTypeValidations validations = result.getValidations(); validations.withPattern(stringType.pattern()); validations.withLenghts(stringType.minLength(), stringType.maxLength()); // Create and handle Enums here if (stringType.enumValues() != null && !stringType.enumValues().isEmpty()) { // We have an enum. we need to create it and set it String enumName = stringType.type(); if ("string".equalsIgnoreCase(enumName)) { enumName = stringType.name(); } if ("string".equalsIgnoreCase(enumName) || enumName.contains("/")) { // enumName is either a string or media type enumName = DEFAULT_ENUM_NAME; } EnumBuilder builder = new EnumBuilder(builderModel, enumName); builder.withEnums(stringType.enumValues(), String.class); result.setBuilder(builder); result.setCodeModel(builderModel); } } if (result.getBuilder() == null) { result.setResolvedClass(CodeModelHelper.findFirstClassBySimpleName(builderModel, "java.lang.String")); } return result; }
Example 8
Source File: FileTypeInterpreter.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
@Override public RamlInterpretationResult interpret(RamlRoot document, TypeDeclaration type, JCodeModel builderModel, boolean property) { RamlInterpretationResult result = new RamlInterpretationResult(type.required()); result.setResolvedClass(CodeModelHelper.findFirstClassBySimpleName(builderModel, Object.class.getSimpleName())); return result; }
Example 9
Source File: NullTypeInterpreter.java From springmvc-raml-plugin with Apache License 2.0 | 4 votes |
@Override public RamlInterpretationResult interpret(RamlRoot document, TypeDeclaration type, JCodeModel builderModel, boolean property) { RamlInterpretationResult result = new RamlInterpretationResult(type.required()); result.setResolvedClass(CodeModelHelper.findFirstClassBySimpleName(builderModel, Void.class.getSimpleName())); return result; }