public static boolean existSchemalessBody(Map<String, MimeType> bodies) { for (final MimeType mimeType : bodies.values()) { if (mimeType.getSchema() == null) { return true; } } return false; }
private String buildSchemaKey(final MimeType mimeType) { return Names.getShortMimeType(mimeType) + "@" + mimeType.getSchema().hashCode(); }
/** * TODO naive to check whether we have inlined schema. */ private static boolean isInlinedJsonSchema(final Map<String, MimeType> body) { return body != null && // body.get(MediaType.JSON.getCode()) != null && // StringUtils.isNotBlank(body.get(MediaType.JSON.getCode()).getSchema()) && // body.get(MediaType.JSON.getCode()).getSchema().contains("{") && body.get(MediaType.JSON.getCode()).getSchema() .contains("}"); }
private String buildSchemaKey(final MimeType mimeType) { return Names.getShortMimeType(mimeType) + "@" + mimeType.getSchema().hashCode(); }
private String getSchemaContent(final Map<String, MimeType> body) { return body.get(MediaType.JSON.getCode()).getSchema(); }
@Nullable private String createModel(RestApi api, String mime, MimeType mimeType) { final String schema = mimeType.getSchema(); if (schema != null) { if (schema.matches("\\w+")) { return schema; } final String modelName = generateModelName(); models.add(modelName); createModel(api, modelName, null, schema, mime); return modelName; } return null; }
private void cleanupMethodModels(Method method, Map<String, MimeType> body) { if (method.getRequestModels() != null) { for (Map.Entry<String, String> entry : method.getRequestModels().entrySet()) { if (!body.containsKey(entry.getKey()) || body.get(entry.getKey()).getSchema() == null) { LOG.info(format("Removing model %s from method %s", entry.getKey(), method.getHttpMethod())); method.updateMethod(createPatchDocument(createRemoveOperation("/requestModels/" + escapeOperationString(entry.getKey())))); } } } }
private void loadSchema(MimeType mime) { final String schema = mime.getSchema(); if (schema == null) { return; } final String refSchema = raml.getConsolidatedSchemas().get(schema); final String schemaToUse = refSchema == null ? schema : refSchema; final String type = mime.getType(); final int pos = type.indexOf(';'); final String simpleType = pos < 0 ? type : type.substring(0, pos); if (simpleType.equals("application/json") || simpleType.endsWith("+json")) { try { loadJsonSchema(loc, schemaToUse); } catch (IOException e) { throw new RuntimeException(e); } } }
private void collectXmlSchemaFiles(MimeType mimeType, Map<String, File> schemaFiles) throws IOException { if (!isCompatibleWith(mimeType, APPLICATION_XML, TEXT_XML)) { return; } final String schemaNameOrContent = mimeType.getSchema(); if (isBlank(schemaNameOrContent)) { return; } final String buildSchemaKey = buildSchemaKey(mimeType); final Entry<File, String> schemaNameAndFile = context.getSchemaFile(schemaNameOrContent); schemaFiles.put(buildSchemaKey, schemaNameAndFile.getKey()); } }
private Collection<String> getUniqueResponseSchema(final Action action) { final Set<String> responseSchemas = new HashSet<>(); for (final Map.Entry<String, Response> responseEntry : action.getResponses().entrySet()) { // consider only successful responses if (!TransformUtils.isErrorResponse(responseEntry.getKey()) && responseEntry.getValue().getBody() != null) { for (final MimeType mimeType : responseEntry.getValue().getBody().values()) { if (mimeType != null) { responseSchemas.add(mimeType.getSchema()); } } } } return responseSchemas; }
private void checkFormParameters(Action action, Values values, MimeType mimeType) { if (mimeType.getSchema() != null) { requestViolations.add("schema.superfluous", locator); } @SuppressWarnings("unchecked") final Map<String, List<? extends AbstractParam>> formParameters = (Map) mimeType.getFormParameters(); if (formParameters == null || formParameters.isEmpty()) { requestViolations.add("formParameters.missing", locator); } else { checkFormParametersValues(action, mimeType, values, formParameters); } }
private JClass getSchemaClass(final MimeType mimeType) throws IOException final String schemaNameOrContent = mimeType.getSchema(); if (isBlank(schemaNameOrContent))
private JClass getSchemaClass(final MimeType mimeType) throws IOException final String schemaNameOrContent = mimeType.getSchema(); if (isBlank(schemaNameOrContent))
@Override public Parameter transform(final Context context, final MimeType source, final TransformationContext ctx) { if (StringUtils.isNotBlank(source.getSchema())) { final Dto argumentType; final JType type = ctx.getStore().getRamlMappingForSchema(source.getSchema()); if (type instanceof JDefinedClass) { argumentType = singleDtoTransformer.transform(context, (JDefinedClass) type, ctx.getNamespace()); } else if (type instanceof JClass) { argumentType = arrayDtoTransformer.transform(context, (JClass) type, ctx.getNamespace()); } else { argumentType = null; } return Parameter.builder()// .name("The schema " + source.getSchema())// .parameterType(ParameterType.BODY)// .qualifier(source.getSchema())// .example(source.getExample())// .type(argumentType)// .build(); } return null; }
ramlInRepresentationWithMediaType = new MimeType(); ramlInRepresentationWithMediaType.setSchema(ramlInRepresentation .getSchema()); try { ramlInRepresentationWithMediaType
ramlInRepresentationWithMediaType = new MimeType(); ramlInRepresentationWithMediaType.setSchema(ramlInRepresentation .getSchema()); try { ramlInRepresentationWithMediaType
ramlInRepresentationWithMediaType = new MimeType(); ramlInRepresentationWithMediaType.setSchema(ramlInRepresentation .getSchema()); try { ramlInRepresentationWithMediaType
public void exampleSchema(MimeType mimeType) { if (has(Validation.EXAMPLE)) { final String schema = mimeType.getSchema(); final String example = mimeType.getExample(); final SchemaValidator validator = findSchemaValidator(schemaValidators, MediaType.valueOf(mimeType.getType())); if (schema != null && example != null && validator != null) { validator.validate(new NamedReader(example, new Message("example").toString()), resolveSchema(raml, schema), violations, new Message("schema.example.mismatch", locator, example)); } } }
private void checkSchema(RamlViolations violations, byte[] body, MediaTypeMatch typeMatch) { final String schema = typeMatch.getMatchingMime().getSchema(); if (schema == null) { return; } final SchemaValidator validator = findSchemaValidator(config.schemaValidators, typeMatch.getTargetType()); if (validator == null) { violations.add("schemaValidator.missing", locator, typeMatch.getTargetType()); return; } if (body == null || body.length == 0) { violations.add("body.empty", locator, typeMatch.getTargetType()); return; } final String charset = typeMatch.getTargetCharset(); try { final String content = new String(body, charset); validator.validate(new NamedReader(content, new Message("body").toString()), resolveSchema(config.raml, schema), violations, new Message("schema.body.mismatch", locator, content)); } catch (UnsupportedEncodingException e) { violations.add("charset.invalid", charset); } }