本文整理汇总了Java中org.raml.model.MimeType类的典型用法代码示例。如果您正苦于以下问题:Java MimeType类的具体用法?Java MimeType怎么用?Java MimeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MimeType类属于org.raml.model包,在下文中一共展示了MimeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exampleResponse
import org.raml.model.MimeType; //导入依赖的package包/类
@Override
public EndpointRoute exampleResponse(HttpResponseStatus status, Object model, String description) {
Response response = new Response();
response.setDescription(description);
HashMap<String, MimeType> map = new HashMap<>();
response.setBody(map);
MimeType mimeType = new MimeType();
if (model instanceof RestModel) {
String json = JsonUtil.toJson(model);
mimeType.setExample(json);
mimeType.setSchema(JsonUtil.getJsonSchema(model.getClass()));
map.put("application/json", mimeType);
} else {
mimeType.setExample(model.toString());
map.put("text/plain", mimeType);
}
exampleResponses.put(status.code(), response);
exampleResponseClasses.put(status.code(), model.getClass());
return this;
}
示例2: apply
import org.raml.model.MimeType; //导入依赖的package包/类
@Override
public void apply(MimeType body, ResourceClassBuilder resourceClassBuilder) {
switch (byMimeType(body)) {
case FORM:
body.getFormParameters().forEach(resourceClassBuilder.applyFormParamsRule);
break;
case JSON:
resourceClassBuilder.getApiClass().withMethod(
bodyMethod()
.withSchema(body.getCompiledSchema())
.withExample(body.getExample())
.withReqName(resourceClassBuilder.getReq().name())
.withInputPathForJsonGen(resourceClassBuilder.getCodegenConfig().getInputPath().getParent())
.withOutputPathForJsonGen(resourceClassBuilder.getCodegenConfig().getOutputPath())
.withPackageForJsonGen(resourceClassBuilder.getCodegenConfig().getBaseObjectsPackage()
+ addedObjectPackage(body.getCompiledSchema().toString()))
.returns(resourceClassBuilder.getApiClass().name()));
break;
}
}
示例3: createModel
import org.raml.model.MimeType; //导入依赖的package包/类
@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;
}
示例4: getBodySchema
import org.raml.model.MimeType; //导入依赖的package包/类
private String getBodySchema(Map<String, MimeType> requestBody, String contentType) {
if (requestBody == null) {
return null;
}
final String[] split = contentType.split("/", 2);
if (split.length != 2) {
return null;
}
final String extensionReplacementRegexp = String.format("(?<=%s/)(.*\\+)(?=%s)",
Pattern.quote(split[0]),
Pattern.quote(split[1]));
return requestBody.entrySet().stream()
.filter(e -> e.getKey().replaceAll(extensionReplacementRegexp, "").equals(contentType))
.map(e -> e.getValue())
.map(e -> e.getSchema())
.findFirst().orElse(null);
}
示例5: getProperty
import org.raml.model.MimeType; //导入依赖的package包/类
@Override
public synchronized Object getProperty(Interpreter anInter, ST aSt,
Object anObject, Object aProperty, String aName)
throws STNoSuchPropertyException {
MimeType oBody=(MimeType)anObject;
if(aName.equals("isSpecific")) {
return !oBody.getType().equals("*/*");
}
if(aName.equals("name")) {
return StringUtils.replaceChars(oBody.getType(), "*/", "s_");
}
if(aName.equals("schemaEscape")) {
return StringEscapeUtils.escapeJava(oBody.getSchema());
}
if(aName.equals("exampleEscape")) {
return StringEscapeUtils.escapeJava(oBody.getExample());
}
if(aName.equals("exampleEscapeJS")) {
return StringEscapeUtils.escapeEcmaScript(oBody.getExample());
}
return super.getProperty(anInter, aSt, anObject, aProperty, aName);
}
示例6: testConvertMimeType
import org.raml.model.MimeType; //导入依赖的package包/类
@Test
public void testConvertMimeType() {
mimeType.setExample("mimeTypeExample");
mimeType.setSchema("mimeTypeSchema");
mimeType.setType("String");
List<FormParameter> formParameters = new ArrayList<>();
FormParameter formParam = new FormParameter();
formParam.setDisplayName("testFormParam");
Map<String, List<FormParameter>> formParameterMap = new HashMap<>();
formParameterMap.put("testFormParameterMap", formParameters);
mimeType.setFormParameters(formParameterMap);
ch.alv.components.web.api.config.MimeType result = converter.convertMimeType(mimeType);
assertEquals(mimeType.getExample(), result.getExample());
assertEquals(mimeType.getFormParameters().size(), result.getFormParameters().size());
assertEquals(mimeType.getSchema(), result.getSchema());
assertEquals("String", result.getType());
assertNull(converter.convertMimeType(null));
}
示例7: testConvertResponse
import org.raml.model.MimeType; //导入依赖的package包/类
@Test
public void testConvertResponse() {
Response source = new Response();
source.setDescription("responseDescription");
Map<String, Header> headers = new HashMap<>();
headers.put("testHeader", new Header());
Map<String, MimeType> body = new HashMap<>();
body.put("testBody", new MimeType());
source.setHeaders(headers);
source.setBody(body);
ch.alv.components.web.api.config.Response result = converter.convertResponse(source);
assertEquals(source.getDescription(), result.getDescription());
assertEquals(source.getBody().size(), result.getBody().size());
assertEquals(source.getHeaders().size(), result.getHeaders().size());
assertNull(converter.convertResponse(null));
}
示例8: findBestMatches
import org.raml.model.MimeType; //导入依赖的package包/类
private static List<Map.Entry<MediaType, MimeType>> findBestMatches(Map<MediaType, MimeType> types, MediaType targetType) {
final List<Map.Entry<MediaType, MimeType>> bestMatches = new ArrayList<>();
for (final Map.Entry<MediaType, MimeType> entry : types.entrySet()) {
final int similarity = targetType.similarity(entry.getKey());
if (bestMatches.isEmpty()) {
if (similarity > 0) {
bestMatches.add(entry);
}
} else {
final int bestSimilarity = targetType.similarity(bestMatches.get(0).getKey());
if (similarity > bestSimilarity) {
bestMatches.clear();
bestMatches.add(entry);
} else if (similarity == bestSimilarity) {
bestMatches.add(entry);
}
}
}
return bestMatches;
}
示例9: exampleRequest
import org.raml.model.MimeType; //导入依赖的package包/类
@Override
public EndpointRoute exampleRequest(String bodyText) {
HashMap<String, MimeType> bodyMap = new HashMap<>();
MimeType mimeType = new MimeType();
mimeType.setExample(bodyText);
bodyMap.put("text/plain", mimeType);
this.exampleRequestMap = bodyMap;
return this;
}
示例10: cleanupMethodModels
import org.raml.model.MimeType; //导入依赖的package包/类
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()))));
}
}
}
}
示例11: setUp
import org.raml.model.MimeType; //导入依赖的package包/类
@Before
public void setUp() {
Map<String, MimeType> contentTypes = getContentTypes();
when(response.getBody()).thenReturn(contentTypes);
when(expectation.getResponse()).thenReturn(Optional.of(response));
when(expectation.getUri()).thenReturn("/hello/John/greetings");
when(expectation.getMethod()).thenReturn("PUT");
when(expectation.getResponseStatusCode()).thenReturn(200);
when(expectation.getResponseContentType()).thenReturn(MediaType.APPLICATION_JSON_TYPE);
when(expectation.hasValidAction()).thenReturn(true);
when(expectation.hasValidResponse()).thenReturn(true);
}
示例12: setUp
import org.raml.model.MimeType; //导入依赖的package包/类
@Before
public void setUp() {
Map<String, MimeType> contentTypes = getContentTypes();
when(action.getBody()).thenReturn(contentTypes);
when(expectation.getAction()).thenReturn(Optional.of(action));
when(expectation.getUri()).thenReturn("/hello/John/greetings");
when(expectation.getMethod()).thenReturn("PUT");
}
示例13: shouldValidateSchemaAndEntityAsCorrect
import org.raml.model.MimeType; //导入依赖的package包/类
@Test
public void shouldValidateSchemaAndEntityAsCorrect() throws IOException {
String schema = fixture("apispecs-test/schemas/greeting-response.json");
String response = fixture("apispecs-test/examples/greeting-response.json");
MimeType mimeType = mock(MimeType.class);
when(mimeType.getSchema()).thenReturn(schema);
ValidationErrors errors = new JsonBodySpecification("Response Body", mimeType).validate(response);
assertThat(errors.isInError()).isFalse();
}
示例14: shouldValidSchemaAndEntityAsInError
import org.raml.model.MimeType; //导入依赖的package包/类
@Test
public void shouldValidSchemaAndEntityAsInError() throws IOException {
String schema = fixture("apispecs-test/schemas/greeting-request.json");
String request = "{\"notes\":\"I am a note.\"}";
MimeType mimeType = mock(MimeType.class);
when(mimeType.getSchema()).thenReturn(schema);
ValidationErrors errors = new JsonBodySpecification("request", mimeType).validate(request);
assertThat(errors.isInError()).isTrue();
assertThat(errors.getMessages())
.hasSize(1)
.contains("[ request ] [ body ] object has missing required properties ([\"greeting\"])");
}
示例15: extractBody
import org.raml.model.MimeType; //导入依赖的package包/类
Map<String, MimeType> extractBody(Map<String, RamlMimeType> ramlBody) {
Map<String, MimeType> body = new LinkedHashMap<>(ramlBody.size());
for(String key: ramlBody.keySet()) {
body.put(key, extractMimeType(ramlBody.get(key)));
}
return body;
}