capital.scalable.restdocs.snippet.StandardTableSnippet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-auto-restdocs-core Show documentation
Show all versions of spring-auto-restdocs-core Show documentation
Spring Auto REST Docs is an extension to Spring REST Docs
/*-
* #%L
* Spring Auto REST Docs Core
* %%
* Copyright (C) 2015 - 2018 Scalable Capital GmbH
* %%
* 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.
* #L%
*/
package capital.scalable.restdocs.snippet;
import static capital.scalable.restdocs.OperationAttributeHelper.determineTemplateFormatting;
import static capital.scalable.restdocs.OperationAttributeHelper.getHandlerMethod;
import static capital.scalable.restdocs.constraints.ConstraintReader.CONSTRAINTS_ATTRIBUTE;
import static capital.scalable.restdocs.constraints.ConstraintReader.DEFAULT_VALUE_ATTRIBUTE;
import static capital.scalable.restdocs.constraints.ConstraintReader.DEPRECATED_ATTRIBUTE;
import static capital.scalable.restdocs.constraints.ConstraintReader.OPTIONAL_ATTRIBUTE;
import static capital.scalable.restdocs.i18n.SnippetTranslationResolver.translate;
import static capital.scalable.restdocs.javadoc.JavadocUtil.convertFromJavadoc;
import static capital.scalable.restdocs.util.FormatUtil.addDot;
import static capital.scalable.restdocs.util.FormatUtil.join;
import static org.apache.commons.lang3.StringUtils.capitalize;
import static org.apache.commons.lang3.StringUtils.trimToEmpty;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import capital.scalable.restdocs.util.TemplateFormatting;
import org.apache.commons.lang3.StringUtils;
import org.springframework.restdocs.operation.Operation;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.snippet.TemplatedSnippet;
import org.springframework.web.method.HandlerMethod;
public abstract class StandardTableSnippet extends TemplatedSnippet {
protected StandardTableSnippet(String snippetName, Map attributes) {
super(snippetName, attributes);
}
@Override
protected Map createModel(Operation operation) {
HandlerMethod handlerMethod = getHandlerMethod(operation);
Map model = defaultModel();
if (handlerMethod == null) {
return model;
}
Collection fieldDescriptors =
createFieldDescriptors(operation, handlerMethod);
TemplateFormatting templateFormatting = determineTemplateFormatting(operation);
return createModel(handlerMethod, model, fieldDescriptors, templateFormatting);
}
protected abstract Collection createFieldDescriptors(Operation operation,
HandlerMethod handlerMethod);
protected abstract String[] getTranslationKeys();
protected void enrichModel(Map model, HandlerMethod handlerMethod) {
// can be used to add additional fields
}
private Map createModel(HandlerMethod handlerMethod, Map model,
Collection fieldDescriptors, TemplateFormatting templateFormatting) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy