当前位置: 首页>>代码示例>>Java>>正文


Java MimeType类代码示例

本文整理汇总了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;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:24,代码来源:EndpointImpl.java

示例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;
    }

}
 
开发者ID:qameta,项目名称:rarc,代码行数:22,代码来源:BodyRule.java

示例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;
}
 
开发者ID:awslabs,项目名称:aws-apigateway-importer,代码行数:20,代码来源:ApiGatewaySdkRamlApiImporter.java

示例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);
}
 
开发者ID:hubrick,项目名称:raml-maven-plugin,代码行数:21,代码来源:AbstractSpringWebMojo.java

示例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);
}
 
开发者ID:pagesjaunes,项目名称:raml-codegen,代码行数:23,代码来源:MimeTypeAdaptator.java

示例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));
}
 
开发者ID:alv-ch,项目名称:alv-ch-java,代码行数:22,代码来源:RamlConverterTest.java

示例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));
}
 
开发者ID:alv-ch,项目名称:alv-ch-java,代码行数:19,代码来源:RamlConverterTest.java

示例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;
}
 
开发者ID:nidi3,项目名称:raml-tester,代码行数:21,代码来源:MediaTypeMatch.java

示例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;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:10,代码来源:EndpointImpl.java

示例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()))));
            }
        }
    }
}
 
开发者ID:awslabs,项目名称:aws-apigateway-importer,代码行数:12,代码来源:ApiGatewaySdkRamlApiImporter.java

示例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);
}
 
开发者ID:ozwolf-software,项目名称:raml-mock-server,代码行数:13,代码来源:ResponseBodyValidatorTest.java

示例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");
}
 
开发者ID:ozwolf-software,项目名称:raml-mock-server,代码行数:9,代码来源:RequestBodyValidatorTest.java

示例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();
}
 
开发者ID:ozwolf-software,项目名称:raml-mock-server,代码行数:13,代码来源:JsonBodySpecificationTest.java

示例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\"])");
}
 
开发者ID:ozwolf-software,项目名称:raml-mock-server,代码行数:16,代码来源:JsonBodySpecificationTest.java

示例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;
}
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:8,代码来源:RJP08V1RamlModelFactory.java


注:本文中的org.raml.model.MimeType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。