List of usage examples for org.springframework.restdocs.payload FieldDescriptor getType
public final Object getType()
From source file:org.springframework.restdocs.payload.JsonContentHandler.java
@Override public Object determineFieldType(FieldDescriptor fieldDescriptor) { if (fieldDescriptor.getType() == null) { return this.fieldTypeResolver.resolveFieldType(fieldDescriptor.getPath(), readContent()); }//from www .j a v a2 s . c o m if (!(fieldDescriptor.getType() instanceof JsonFieldType)) { return fieldDescriptor.getType(); } JsonFieldType descriptorFieldType = (JsonFieldType) fieldDescriptor.getType(); try { JsonFieldType actualFieldType = this.fieldTypeResolver.resolveFieldType(fieldDescriptor.getPath(), readContent()); if (descriptorFieldType == JsonFieldType.VARIES || descriptorFieldType == actualFieldType) { return descriptorFieldType; } throw new FieldTypesDoNotMatchException(fieldDescriptor, actualFieldType); } catch (FieldDoesNotExistException ex) { return fieldDescriptor.getType(); } }
From source file:capital.scalable.restdocs.jackson.ExtendedFieldDescriptor.java
public ExtendedFieldDescriptor(FieldDescriptor descriptor) { this.path = descriptor.getPath(); this.type = descriptor.getType(); this.optionals = (List<String>) descriptor.getAttributes().get(OPTIONAL_ATTRIBUTE); this.description = descriptor.getDescription(); this.constraints = (List<String>) descriptor.getAttributes().get(CONSTRAINTS_ATTRIBUTE); }
From source file:org.springframework.restdocs.payload.FieldSnippetResultHandler.java
@Override protected void handle(MvcResult result, DocumentationWriter writer) throws IOException { this.fieldValidator.validate(getPayloadReader(result), this.fieldDescriptors); final Map<String, Object> payload = extractPayload(result); List<String> missingFields = new ArrayList<String>(); for (FieldDescriptor fieldDescriptor : this.fieldDescriptors) { if (!fieldDescriptor.isOptional()) { Object field = this.fieldExtractor.extractField(fieldDescriptor.getPath(), payload); if (field == null) { missingFields.add(fieldDescriptor.getPath()); }/* w ww .jav a 2 s . co m*/ } } writer.table(new TableAction() { @Override public void perform(TableWriter tableWriter) throws IOException { tableWriter.headers("Path", "Type", "Description"); for (Entry<String, FieldDescriptor> entry : FieldSnippetResultHandler.this.descriptorsByPath .entrySet()) { FieldDescriptor descriptor = entry.getValue(); FieldType type = descriptor.getType() != null ? descriptor.getType() : FieldSnippetResultHandler.this.fieldTypeResolver .resolveFieldType(descriptor.getPath(), payload); tableWriter.row(entry.getKey().toString(), type.toString(), entry.getValue().getDescription()); } } }); }
From source file:capital.scalable.restdocs.snippet.StandardTableSnippet.java
protected Map<String, Object> createModelForDescriptor(FieldDescriptor descriptor, String lineBreak) { String path = descriptor.getPath(); String type = toString(descriptor.getType()); String description = convertFromJavadoc(toString(descriptor.getDescription()), lineBreak); List<String> optionalMessages = (List<String>) descriptor.getAttributes().get(OPTIONAL_ATTRIBUTE); String optional = "" + join(optionalMessages, lineBreak); List<String> constraints = (List<String>) descriptor.getAttributes().get(CONSTRAINTS_ATTRIBUTE); description = joinAndFormat(lineBreak, description, constraints); Map<String, Object> model = new HashMap<>(); model.put("path", path); model.put("type", type); model.put("optional", optional); model.put("description", description); return model; }