本文整理了Java中io.swagger.v3.oas.models.media.MediaType.<init>()
方法的一些代码示例,展示了MediaType.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaType.<init>()
方法的具体详情如下:
包路径:io.swagger.v3.oas.models.media.MediaType
类名称:MediaType
方法名:<init>
暂无
代码示例来源:origin: swagger-api/swagger-core
private void setMediaTypeToContent(Schema schema, Content content, String value) {
MediaType mediaTypeObject = new MediaType();
mediaTypeObject.setSchema(schema);
content.addMediaType(value, mediaTypeObject);
}
代码示例来源:origin: swagger-api/swagger-core
MediaType mediaType = new MediaType();
if (components != null) {
getSchema(annotationContent, components, jsonViewAnnotation).ifPresent(mediaType::setSchema);
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should serialize a ref BodyParameter")
public void serializeRefBodyParameter() {
final Schema model = new Schema().$ref("#/definitions/Cat");
final RequestBody p = new RequestBody()
.content(new Content().addMediaType("*/*",
new MediaType().schema(model)));
final String json = "{\"content\":{\"*/*\":{\"schema\":{\"$ref\":\"#/definitions/Cat\"}}}}";
SerializationMatchers.assertEqualsToJson(p, json);
}
代码示例来源:origin: swagger-api/swagger-core
Schema returnTypeSchema = resolvedSchema.schema;
Content content = new Content();
MediaType mediaType = new MediaType().schema(returnTypeSchema);
AnnotationsUtils.applyTypes(classProduces == null ? new String[0] : classProduces.value(),
methodProduces == null ? new String[0] : methodProduces.value(), content, mediaType);
MediaType mediaType = new MediaType();
AnnotationsUtils.applyTypes(classProduces == null ? new String[0] : classProduces.value(),
methodProduces == null ? new String[0] : methodProduces.value(), content, mediaType);
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should serialize a BodyParameter")
public void serializeBodyParameter() {
final Schema model = new Schema()
.title("Cat")
.addProperties("name", new StringSchema());
final RequestBody p = new RequestBody()
.content(new Content().addMediaType("*/*",
new MediaType().schema(model)));
final String json = "{\"content\":{\"*/*\":{\"schema\":{\"title\":\"Cat\",\"properties\":{\"name\":{\"type\":\"string\"}}}}}}";
SerializationMatchers.assertEqualsToJson(p, json);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should serialize an array BodyParameter")
public void serializeArrayBodyParameter() {
final Schema model = new ArraySchema().items(new Schema().$ref("#/definitions/Cat"));
final RequestBody p = new RequestBody()
.content(new Content().addMediaType("*/*",
new MediaType().schema(model)));
final String json = "{\"content\":{\"*/*\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Cat\"}}}}}";
SerializationMatchers.assertEqualsToJson(p, json);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should create a response")
public void createResponse() throws IOException {
final ApiResponse response = new ApiResponse()
.content(new Content()
.addMediaType("application/json", new MediaType()
.addExamples("test", new Example().value("{\"name\":\"Fred\",\"id\":123456\"}"))));
final String json = "{\n" +
" \"content\" : {\n" +
" \"application/json\" : {\n" +
" \"examples\" : {\n" +
" \"test\" : {\n" +
" \"value\" : \"{\\\"name\\\":\\\"Fred\\\",\\\"id\\\":123456\\\"}\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
SerializationMatchers.assertEqualsToJson(response, json);
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should serialize a BodyParameter to yaml")
public void serializeBodyParameterToYaml() {
final Schema model = new Schema()
.title("Cat")
.addProperties("name", new StringSchema());
final RequestBody p = new RequestBody()
.content(new Content().addMediaType("*/*",
new MediaType().schema(model)));
final String yaml = "---\n" +
"content:\n" +
" '*/*':\n" +
" schema:\n" +
" title: Cat\n" +
" properties:\n" +
" name:\n" +
" type: string";
SerializationMatchers.assertEqualsToYaml(p, yaml);
}
代码示例来源:origin: swagger-api/swagger-core
.description("pets returned")
.content(new Content()
.addMediaType("application/json", new MediaType()
.schema(new Schema().$ref("Person"))
.example("fun")));
.addMediaType("application/json", new MediaType()
.schema(new Schema().$ref("Error"))));
.requestBody(new RequestBody()
.description("the pet to add")
.content(new Content().addMediaType("*/*", new MediaType()
.schema(new Schema().$ref("Person")))));
代码示例来源:origin: swagger-api/swagger-core
.content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Person"))));
.content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Error"))));
代码示例来源:origin: noboomu/proteus
private void setMediaTypeToContent(Schema schema, Content content, String value)
{
MediaType mediaTypeObject = new MediaType();
mediaTypeObject.setSchema(schema);
content.addMediaType(value, mediaTypeObject);
}
代码示例来源:origin: com.atlassian.swagger/atlassian-swagger-doclet
private static void setMediaTypeToContent(Schema schema, Content content, String value) {
MediaType mediaTypeObject = new MediaType();
mediaTypeObject.setSchema(schema);
content.addMediaType(value, mediaTypeObject);
}
代码示例来源:origin: io.swagger.core.v3/swagger-jaxrs2
private void setMediaTypeToContent(Schema schema, Content content, String value) {
MediaType mediaTypeObject = new MediaType();
mediaTypeObject.setSchema(schema);
content.addMediaType(value, mediaTypeObject);
}
代码示例来源:origin: swagger-api/swagger-parser
private Content convertExamples(final Map examples, final Content content) {
if (examples != null) {
examples.forEach((k, v) -> {
MediaType mT = content.get(k);
if (mT == null) {
mT = new MediaType();
content.addMediaType(k.toString(), mT);
}
mT.setExample(v);
});
}
return content;
}
代码示例来源:origin: org.openapitools.swagger.parser/swagger-parser-v2-converter
private Content convertExamples(final Map examples, final Content content) {
if (examples != null) {
examples.forEach((k, v) -> {
MediaType mT = content.get(k);
if (mT == null) {
mT = new MediaType();
content.addMediaType(k.toString(), mT);
}
mT.setExample(v);
});
}
return content;
}
代码示例来源:origin: io.swagger.parser.v3/swagger-parser-v2-converter
private Content convertExamples(final Map examples, final Content content) {
if (examples != null) {
examples.forEach((k, v) -> {
MediaType mT = content.get(k);
if (mT == null) {
mT = new MediaType();
content.addMediaType(k.toString(), mT);
}
mT.setExample(v);
});
}
return content;
}
代码示例来源:origin: ppdai-incubator/raptor
/**
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#media-type-object
*
* @param protoType
* @return
*/
protected MediaType getMediaType(ProtoType protoType) {
MediaType mediaType = new MediaType();
mediaType.schema(getSchema(protoType));
// mediaType.encoding();
// mediaType.
return mediaType;
}
代码示例来源:origin: com.atlassian.swagger/atlassian-swagger-doclet
private void setMediaTypeToContent(Content content, String mediaTypeName, String jsonExample, boolean overrideExistingExample) {
MediaType mediaType = content.get(mediaTypeName);
if (mediaType == null) {
mediaType = new MediaType();
content.addMediaType(mediaTypeName, mediaType);
}
if (mediaType.getExample() == null || overrideExistingExample) {
mediaType.example(jsonExample);
}
}
代码示例来源:origin: io.swagger.parser.v3/swagger-parser-v2-converter
private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param, List<String> consumes) {
RequestBody body = new RequestBody();
BodyParameter bp = (BodyParameter) param;
List<String> mediaTypes = new ArrayList<>(globalConsumes);
if (consumes != null && consumes.size() > 0) {
mediaTypes.clear();
mediaTypes.addAll(consumes);
}
if (mediaTypes.size() == 0) {
mediaTypes.add("*/*");
}
if (StringUtils.isNotBlank(param.getDescription())) {
body.description(param.getDescription());
}
body.required(param.getRequired());
Content content = new Content();
for (String type : mediaTypes) {
content.addMediaType(type,
new MediaType().schema(
convert(bp.getSchema())));
if (StringUtils.isNotBlank(bp.getDescription())) {
body.setDescription(bp.getDescription());
}
}
convertExamples(((BodyParameter) param).getExamples(), content);
body.content(content);
return body;
}
代码示例来源:origin: com.atlassian.swagger/atlassian-swagger-doclet
private Content readAsContent(ParseContext parseCtx, Type responseClass) {
if (responseClass == null) {
return null;
}
OpenAPI openAPI = parseCtx.openAPI();
Content content = new Content();
MediaType mediaType = new MediaType();
ResolvedSchema resolvedSchema = modelConverters().resolveAsResolvedSchema(new AnnotatedType(responseClass).resolveAsRef(true));
mediaType.schema(resolvedSchema.schema);
content.addMediaType(MediaTypeConstants.DEFAULT_JSON_BODY_TYPE, mediaType);
resolvedSchema.referencedSchemas.forEach((name, schema) -> {
openAPI.schema(name, schema);
});
return content;
}
内容来源于网络,如有侵权,请联系作者删除!