热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

io.swagger.v3.oas.models.media.MediaType.schema()方法的使用及代码示例

本文整理了Java中io.swagger.v3.oas.models.media.MediaType.schema()方法的一些代码示例,展示了MediaT

本文整理了Java中io.swagger.v3.oas.models.media.MediaType.schema()方法的一些代码示例,展示了MediaType.schema()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaType.schema()方法的具体详情如下:
包路径:io.swagger.v3.oas.models.media.MediaType
类名称:MediaType
方法名:schema

MediaType.schema介绍

暂无

代码示例

代码示例来源: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);

代码示例来源: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 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 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

.content(new Content()
.addMediaType("application/json", new MediaType()
.schema(new Schema().$ref("Person"))
.example("fun")));
.schema(new Schema().$ref("Error"))));
.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: 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: org.geoserver.community/gs-wfs3

private void declareGetResponseFormats(OpenAPI api, String path, Class binding) {
PathItem pi = api.getPaths().get(path);
Operation get = pi.getGet();
Content cOntent= get.getResponses().get("200").getContent();
List formats = DefaultWebFeatureService30.getAvailableFormats(binding);
// first remove the ones missing
Set missingFormats = new HashSet<>(content.keySet());
missingFormats.removeAll(formats);
missingFormats.forEach(f -> content.remove(f));
// then add the ones not already declared
Set extraFormats = new HashSet<>(formats);
extraFormats.removeAll(content.keySet());
for (String extraFormat : extraFormats) {
MediaType mediaType = new MediaType();
if (extraFormat.contains("yaml") && content.get("application/json") != null) {
// same schema as JSON
mediaType.schema(content.get("application/json").getSchema());
} else if (extraFormat.contains("text")) {
mediaType.schema(new StringSchema());
} else {
mediaType.schema(new BinarySchema());
}
content.addMediaType(extraFormat, mediaType);
}
}

代码示例来源:origin: io.swagger.parser.v3/swagger-parser-v2-converter

private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param, List consumes) {
RequestBody body = new RequestBody();
BodyParameter bp = (BodyParameter) param;
List 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: swagger-api/swagger-parser

private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param, List consumes) {
RequestBody body = new RequestBody();
BodyParameter bp = (BodyParameter) param;
List 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: org.openapitools.swagger.parser/swagger-parser-v2-converter

private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param, List consumes) {
RequestBody body = new RequestBody();
BodyParameter bp = (BodyParameter) param;
List 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: io.swagger.parser.v3/swagger-parser-v2-converter

content.addMediaType(type, new MediaType().schema(formSchema));

代码示例来源:origin: swagger-api/swagger-parser

content.addMediaType(type, new MediaType().schema(formSchema));

代码示例来源: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;
}

代码示例来源:origin: org.openapitools.swagger.parser/swagger-parser-v2-converter

content.addMediaType(type, new MediaType().schema(formSchema));

代码示例来源:origin: swagger-api/swagger-parser

content.addMediaType(type, mediaType.schema(schema));

代码示例来源:origin: org.openapitools.swagger.parser/swagger-parser-v2-converter

content.addMediaType(type, mediaType.schema(schema));

代码示例来源:origin: io.swagger.parser.v3/swagger-parser-v2-converter

content.addMediaType(type, mediaType.schema(schema));

代码示例来源:origin: org.apache.syncope.core/syncope-core-rest-cxf

javax.ws.rs.core.MediaType.APPLICATION_JSON, new MediaType().schema(new Schema()));
content.addMediaType(
RESTHeaders.APPLICATION_YAML, new MediaType().schema(new Schema()));
content.addMediaType(
javax.ws.rs.core.MediaType.APPLICATION_XML, new MediaType().schema(new Schema()));

推荐阅读
author-avatar
骨头少校_726
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有