本文整理汇总了Java中org.springframework.restdocs.operation.Operation类的典型用法代码示例。如果您正苦于以下问题:Java Operation类的具体用法?Java Operation怎么用?Java Operation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Operation类属于org.springframework.restdocs.operation包,在下文中一共展示了Operation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getOutputFile
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
private File getOutputFile(Operation operation, String filename) {
Object context = operation.getAttributes().get(RestDocumentationContext.class.getName());
try {
//use reflection here because of binary incompatibility between spring-restdocs 1 and 2
//RestDocumentationContext changed from a class to an interface
//if our code should work against both versions we need to avoid compiling against a version directly
//see https://github.com/ePages-de/restdocs-raml/issues/7
//we can remove the use of reflection when we drop support for spring-restdocs 1
Method getOutputDirectory = context.getClass().getDeclaredMethod("getOutputDirectory");
getOutputDirectory.setAccessible(true);
File outputFile = (File) getOutputDirectory.invoke(context);
return new File(outputFile, operation.getName() + "/" + filename);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
return null;
}
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:17,代码来源:RamlResourceSnippet.java
示例2: generateModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
public Map<String, Object> generateModel(Operation operation, RamlResourceSnippetParameters parameters) {
final OperationRequest request = operation.getRequest();
if (!StringUtils.isEmpty(request.getContentAsString())) {
Map<String, Object> model = new HashMap<>();
model.put("requestBodyFileName", getRequestFileName(operation.getName()));
model.put("requestBodyPresent", true);
model.put("contentTypeRequest", request.getHeaders().getContentType().getType() + "/" + request.getHeaders().getContentType().getSubtype());
if (!parameters.getRequestFields().isEmpty()) {
validateRequestFieldsAndInferTypeInformation(operation, parameters);
model.put("requestFieldsPresent", true);
if (shouldGenerateRequestSchemaFile(operation, parameters)) {
model.put("requestSchemaFileName", getRequestSchemaFileName(operation.getName()));
}
}
return model;
}
return emptyMap();
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:20,代码来源:RequestHandler.java
示例3: generateModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
public Map<String, Object> generateModel(Operation operation, RamlResourceSnippetParameters parameters) {
final OperationResponse response = operation.getResponse();
if (!StringUtils.isEmpty(response.getContentAsString())) {
Map<String, Object> model = new HashMap<>();
model.put("responseBodyFileName", getResponseFileName(operation.getName()));
model.put("responseBodyPresent", true);
model.put("contentTypeResponse", response.getHeaders().getContentType().getType() + "/" + response.getHeaders().getContentType().getSubtype());
if (!parameters.getResponseFields().isEmpty()) {
validateResponseFieldsAndInferTypeInformation(operation, parameters);
model.put("responseFieldsPresent", true);
if (shouldGenerateResponseSchemaFile(operation, parameters)) {
model.put("responseSchemaFileName", getResponseSchemaFileName(operation.getName()));
}
}
return model;
}
return emptyMap();
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:19,代码来源:ResponseHandler.java
示例4: build
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
public Operation build() {
if (this.attributes.get(TemplateEngine.class.getName()) == null) {
Map<String, Object> templateContext = new HashMap<>();
templateContext.put("tableCellContent",
new AsciidoctorTableCellContentLambda());
this.attributes.put(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
new StandardTemplateResourceResolver(this.templateFormat),
Mustache.compiler().escapeHTML(false), templateContext));
}
RestDocumentationContext context = createContext();
this.attributes.put(RestDocumentationContext.class.getName(), context);
this.attributes.put(WriterResolver.class.getName(),
new StandardWriterResolver(
new RestDocumentationContextPlaceholderResolverFactory(), "UTF-8",
this.templateFormat));
return new StandardOperation(this.name,
(this.requestBuilder == null
? new OperationRequestBuilder("http://localhost/").buildRequest()
: this.requestBuilder.buildRequest()),
this.responseBuilder == null
? new OperationResponseBuilder().buildResponse()
: this.responseBuilder.buildResponse(),
this.attributes);
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:26,代码来源:OperationBuilder.java
示例5: createModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
protected Map<Object, Object> createModel(Operation operation) {
OperationResponse response = operation.getResponse();
Maps.Builder<Object, Object> requestBuilder = Maps.builder()
.put("method", operation.getRequest().getMethod())
.put("urlPath", operation.getRequest().getUri().getRawPath());
Maps.Builder<Object, Object> responseBuilder = Maps.builder()
.put("status", response.getStatus().value()).put("headers", responseHeaders(response))
.put("body", responseBody(response));
Map<Object, Object> queryParams = queryParams(operation);
if (!queryParams.isEmpty()) {
requestBuilder.put("queryParameters", queryParams);
}
Map<Object, Object> headers = requestHeaders(operation.getRequest());
if (!headers.isEmpty()) {
requestBuilder.put("headers", headers);
}
return Maps.builder().put("request", requestBuilder.build()).put("response", responseBuilder.build())
.build();
}
开发者ID:ePages-de,项目名称:restdocs-wiremock,代码行数:25,代码来源:WireMockJsonSnippet.java
示例6: build
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
public Operation build() {
if (this.attributes.get(TemplateEngine.class.getName()) == null) {
Map<String, Object> templateContext = new HashMap<>();
templateContext.put("tableCellContent",
new AsciidoctorTableCellContentLambda());
this.attributes.put(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
new StandardTemplateResourceResolver(this.templateFormat),
Mustache.compiler().escapeHTML(false), templateContext));
}
RestDocumentationContext context = createContext();
this.attributes.put(RestDocumentationContext.class.getName(), context);
this.attributes.put(WriterResolver.class.getName(),
new StandardWriterResolver(
new RestDocumentationContextPlaceholderResolverFactory(), "UTF-8",
this.templateFormat));
return new StandardOperation(this.name,
(this.requestBuilder == null
? new OperationRequestBuilder("http://localhost/").buildRequest()
: this.requestBuilder.buildRequest()),
this.responseBuilder.buildResponse(), this.attributes);
}
开发者ID:ePages-de,项目名称:restdocs-wiremock,代码行数:23,代码来源:OperationBuilder.java
示例7: createFieldDescriptors
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
protected List<FieldDescriptor> createFieldDescriptors(Operation operation,
HandlerMethod handlerMethod) {
JavadocReader javadocReader = getJavadocReader(operation);
ConstraintReader constraintReader = getConstraintReader(operation);
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
for (MethodParameter param : handlerMethod.getMethodParameters()) {
A annot = getAnnotation(param);
if (annot != null) {
addFieldDescriptor(handlerMethod, javadocReader, constraintReader, fieldDescriptors,
param, annot);
}
}
if (shouldFailOnUndocumentedParams()) {
assertAllDocumented(fieldDescriptors, translate(getHeaderKey()).toLowerCase());
}
return fieldDescriptors;
}
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:22,代码来源:AbstractParameterSnippet.java
示例8: createModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
protected Map<String, Object> createModel(Operation operation) {
Map<String, Object> model = defaultModel(operation);
HandlerMethod handlerMethod = getHandlerMethod(operation);
if (handlerMethod == null) {
return model;
}
JavadocReader javadocReader = getJavadocReader(operation);
String title = resolveTitle(handlerMethod, javadocReader);
model.put("title", title);
model.put("sections", createSections(operation));
createSections(operation);
return model;
}
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:20,代码来源:SectionSnippet.java
示例9: createSections
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
private List<Section> createSections(Operation operation) {
List<Section> sections = new ArrayList<>();
for (String sectionName : sectionNames) {
SectionSupport section = getSectionSnippet(operation, sectionName);
if (section != null) {
if (!skipEmpty || section.hasContent(operation)) {
sections.add(
new Section(section.getFileName(), translate(section.getHeaderKey())));
}
} else {
log.warn("Section snippet '" + sectionName + "' is configured to be " +
"included in the section but no such snippet is present in configuration");
}
}
return sections;
}
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:17,代码来源:SectionSnippet.java
示例10: createModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
protected Map<String, Object> createModel(Operation operation) {
HandlerMethod handlerMethod = getHandlerMethod(operation);
Map<String, Object> model = defaultModel();
if (handlerMethod == null) {
return model;
}
JavadocReader javadocReader = getJavadocReader(operation);
String methodComment = resolveComment(handlerMethod, javadocReader);
String seeTagComment = resolveSeeTag(handlerMethod, javadocReader);
String deprecatedComment = resolveDeprecated(handlerMethod, javadocReader);
String completeComment = join("<p>", deprecatedComment, methodComment, seeTagComment);
String description = convertFromJavadoc(completeComment,
determineTemplateFormatting(operation));
model.put("description", description);
return model;
}
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:20,代码来源:DescriptionSnippet.java
示例11: createFieldDescriptors
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
protected Collection<FieldDescriptor> createFieldDescriptors(Operation operation,
HandlerMethod handlerMethod) {
ObjectMapper objectMapper = getObjectMapper(operation);
JavadocReader javadocReader = getJavadocReader(operation);
ConstraintReader constraintReader = getConstraintReader(operation);
Map<String, FieldDescriptor> fieldDescriptors = new LinkedHashMap<>();
Type type = getType(handlerMethod);
if (type != null) {
try {
resolveFieldDescriptors(fieldDescriptors, type, objectMapper,
javadocReader, constraintReader);
} catch (JsonMappingException e) {
throw new JacksonFieldProcessingException("Error while parsing fields", e);
}
}
if (shouldFailOnUndocumentedFields()) {
assertAllDocumented(fieldDescriptors.values(), translate(getHeaderKey()).toLowerCase());
}
return fieldDescriptors.values();
}
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:25,代码来源:AbstractJacksonFieldSnippet.java
示例12: createModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
protected Map<String, Object> createModel(Operation operation) {
try {
Object object = objectMapper.readValue(
operation.getResponse().getContentAsString(), Object.class);
Object field = fieldProcessor.extract(JsonFieldPath.compile(path), object);
if (field instanceof List && index != null) {
field = ((List<?>) field).get(index);
}
return Collections.singletonMap("value",
objectMapper.writeValueAsString(field));
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
开发者ID:spring-io,项目名称:initializr,代码行数:17,代码来源:ResponseFieldSnippet.java
示例13: createModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
protected Map<String, Object> createModel(Operation operation) {
Map<String, Object> model = new HashMap<>();
model.put("method", operation.getRequest().getMethod().name().toLowerCase());
model.put("description", parameters.getDescription() == null ? operation.getName() : parameters.getDescription());
model.put("resource", getUriPath(operation));
model.put("status", operation.getResponse().getStatus().value());
model.putAll(handlerChain.process(operation, parameters));
return model;
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:13,代码来源:RamlResourceSnippet.java
示例14: documentSnippet
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
private void documentSnippet(Operation operation) throws IOException {
WriterResolver writerResolver = new StandardWriterResolver(new RestDocumentationContextPlaceholderResolverFactory(), DEFAULT_SNIPPET_ENCODING, new RamlTemplateFormat());
try (Writer writer = writerResolver.resolve(operation.getName(), SNIPPET_NAME,
(RestDocumentationContext) operation.getAttributes().get(RestDocumentationContext.class.getName()))) {
Map<String, Object> model = createModel(operation);
TemplateEngine templateEngine = new MustacheTemplateEngine(new StandardTemplateResourceResolver(new RamlTemplateFormat()));
writer.append(templateEngine.compileTemplate(SNIPPET_NAME).render(model));
}
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:11,代码来源:RamlResourceSnippet.java
示例15: storeFile
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
private void storeFile(Operation operation, String filename, String content) {
File output = getOutputFile(operation, filename);
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(output.toPath()))) {
writer.append(content);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:9,代码来源:RamlResourceSnippet.java
示例16: getUriPath
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
private String getUriPath(Operation operation) {
String urlTemplate = (String) operation.getAttributes().get(ATTRIBUTE_NAME_URL_TEMPLATE);
if (StringUtils.isEmpty(urlTemplate)) {
throw new MissingUrlTemplateException();
}
return UriComponentsBuilder.fromUriString(urlTemplate).build().getPath();
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:8,代码来源:RamlResourceSnippet.java
示例17: extractTraits
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
public List<String> extractTraits(Operation operation, RamlResourceSnippetParameters parameters) {
if (parameters.isPrivateResource()) {
return singletonList("private");
}
return emptyList();
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:9,代码来源:PrivateResourceTraitExtractor.java
示例18: generateModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
public Map<String, Object> generateModel(Operation operation, RamlResourceSnippetParameters parameters) {
List<ParameterDescriptorWithRamlType> requestParameters = parameters.getRequestParameters();
if (!requestParameters.isEmpty()) {
new RequestParameterSnippetWrapper(requestParameters).validateRequestParameters(operation);
Map<String, Object> model = new HashMap<>();
model.put("requestParametersPresent", true);
model.put("requestParameters", mapParameterDescriptorsToModel(requestParameters));
return model;
}
return emptyMap();
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:13,代码来源:RequestParameterHandler.java
示例19: generateModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
public Map<String, Object> generateModel(Operation operation, RamlResourceSnippetParameters parameters) {
List<String> traitsToApply = traitExtractors.stream()
.flatMap(t -> t.extractTraits(operation, parameters).stream())
.collect(toList());
if (!traitsToApply.isEmpty()) {
return singletonMap("traits", "[ " + String.join(",", traitsToApply.stream().map(s -> String.format("\"%s\"", s)).collect(toList())) + " ]");
}
return emptyMap();
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:13,代码来源:TraitExtractorChain.java
示例20: generateModel
import org.springframework.restdocs.operation.Operation; //导入依赖的package包/类
@Override
public Map<String, Object> generateModel(Operation operation, RamlResourceSnippetParameters parameters) {
List<ParameterDescriptorWithRamlType> pathParameters = parameters.getPathParameters();
if (!pathParameters.isEmpty()) {
new PathParametersSnippetWrapper(pathParameters).validatePathParameters(operation);
Map<String, Object> model = new HashMap<>();
model.put("pathParametersPresent", true);
model.put("pathParameters", mapParameterDescriptorsToModel(pathParameters));
return model;
}
return emptyMap();
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:13,代码来源:PathParameterHandler.java
注:本文中的org.springframework.restdocs.operation.Operation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论