Java Code Examples for io.swagger.models.parameters.BodyParameter#getSchema()
The following examples show how to use
io.swagger.models.parameters.BodyParameter#getSchema() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractOperationGenerator.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
private void mergeBodyParameter(BodyParameter bodyParameter, BodyParameter fromBodyParameter) { if (fromBodyParameter.getExamples() != null) { bodyParameter.setExamples(fromBodyParameter.getExamples()); } if (fromBodyParameter.getRequired()) { bodyParameter.setRequired(true); } if (StringUtils.isNotEmpty(fromBodyParameter.getDescription())) { bodyParameter.setDescription(fromBodyParameter.getDescription()); } if (StringUtils.isNotEmpty(fromBodyParameter.getAccess())) { bodyParameter.setAccess(fromBodyParameter.getAccess()); } if (fromBodyParameter.getSchema() != null) { bodyParameter.setSchema(fromBodyParameter.getSchema()); } }
Example 2
Source File: RestOperationMeta.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
/** * EdgeService cannot recognize the map type form body whose value type is String, * so there should be this additional setting. * @param parameter the swagger information of the parameter * @param type the resolved param type * @return the corrected param type */ private Type correctFormBodyType(Parameter parameter, Type type) { if (null != type || !(parameter instanceof BodyParameter)) { return type; } final BodyParameter bodyParameter = (BodyParameter) parameter; if (!(bodyParameter.getSchema() instanceof ModelImpl)) { return type; } final Property additionalProperties = ((ModelImpl) bodyParameter.getSchema()).getAdditionalProperties(); if (additionalProperties instanceof StringProperty) { type = RestObjectMapperFactory.getRestObjectMapper().getTypeFactory() .constructMapType(Map.class, String.class, String.class); } return type; }
Example 3
Source File: BodyParameterExtractor.java From vertx-swagger with Apache License 2.0 | 6 votes |
@Override public Object extract(String name, Parameter parameter, RoutingContext context) { BodyParameter bodyParam = (BodyParameter) parameter; if ("".equals(context.getBodyAsString())) { if (bodyParam.getRequired()) throw new IllegalArgumentException("Missing required parameter: " + name); else return null; } try { if(bodyParam.getSchema() instanceof ArrayModel) { return context.getBodyAsJsonArray(); } else { return context.getBodyAsJson(); } } catch (DecodeException e) { return context.getBodyAsString(); } }
Example 4
Source File: JaxrsReader.java From swagger-maven-plugin with Apache License 2.0 | 6 votes |
private Parameter replaceArrayModelForOctetStream(Operation operation, Parameter parameter) { if (parameter instanceof BodyParameter && operation.getConsumes() != null && operation.getConsumes().contains("application/octet-stream")) { BodyParameter bodyParam = (BodyParameter) parameter; Model schema = bodyParam.getSchema(); if (schema instanceof ArrayModel) { ArrayModel arrayModel = (ArrayModel) schema; Property items = arrayModel.getItems(); if (items != null && items.getFormat() == "byte" && items.getType() == "string") { ModelImpl model = new ModelImpl(); model.setFormat("byte"); model.setType("string"); bodyParam.setSchema(model); } } } return parameter; }
Example 5
Source File: RustServerCodegen.java From TypeScript-Microservices with MIT License | 5 votes |
@Override public CodegenParameter fromParameter(Parameter param, Set<String> imports) { CodegenParameter parameter = super.fromParameter(param, imports); if(param instanceof BodyParameter) { BodyParameter bp = (BodyParameter) param; Model model = bp.getSchema(); if (model instanceof RefModel) { String name = ((RefModel) model).getSimpleRef(); name = toModelName(name); // We need to be able to look up the model in the model definitions later. parameter.vendorExtensions.put("uppercase_data_type", name.toUpperCase()); name = "models::" + getTypeDeclaration(name); parameter.baseType = name; parameter.dataType = name; String refName = ((RefModel) model).get$ref(); if (refName.indexOf("#/definitions/") == 0) { refName = refName.substring("#/definitions/".length()); } parameter.vendorExtensions.put("refName", refName); } else if (model instanceof ModelImpl) { parameter.vendorExtensions.put("refName", ((ModelImpl) model).getName()); } } return parameter; }
Example 6
Source File: SwaggerUtils.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
public static ModelImpl getModelImpl(Swagger swagger, BodyParameter bodyParameter) { Model model = bodyParameter.getSchema(); if (model instanceof ModelImpl) { return (ModelImpl) model; } if (!(model instanceof RefModel)) { return null; } String simpleRef = ((RefModel) model).getSimpleRef(); Model targetModel = swagger.getDefinitions().get(simpleRef); return targetModel instanceof ModelImpl ? (ModelImpl) targetModel : null; }
Example 7
Source File: ReplaceDefinitionsProcessor.java From yang2swagger with Eclipse Public License 1.0 | 5 votes |
private void fixParameter(Parameter p, Map<String, String> replacements) { if(!(p instanceof BodyParameter)) return; BodyParameter bp = (BodyParameter) p; if(!(bp.getSchema() instanceof RefModel)) return; RefModel ref = (RefModel) bp.getSchema(); if(replacements.containsKey(ref.getSimpleRef())) { String replacement = replacements.get(ref.getSimpleRef()); bp.setDescription(bp.getDescription().replace(ref.getSimpleRef(), replacement)); bp.setSchema(new RefModel(replacement)); } }
Example 8
Source File: ApiGatewaySdkSwaggerApiImporter.java From aws-apigateway-importer with Apache License 2.0 | 5 votes |
private Optional<String> getInputModel(BodyParameter p) { io.swagger.models.Model model = p.getSchema(); if (model instanceof RefModel) { String modelName = ((RefModel) model).getSimpleRef(); // assumption: complex ref? return Optional.of(modelName); } return Optional.empty(); }
Example 9
Source File: SwaggerInventory.java From swagger-parser with Apache License 2.0 | 5 votes |
public void process(Parameter parameter) { this.parameters.add(parameter); if(parameter instanceof BodyParameter) { BodyParameter p = (BodyParameter)parameter; if(p.getSchema() != null) { Model model = p.getSchema(); if(model != null) { this.process(model); } } } }
Example 10
Source File: BodyParameterAdapter.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
public BodyParameterAdapter(BodyParameter parameter) { this.model = parameter.getSchema(); }
Example 11
Source File: PayloadWrapperProcessor.java From yang2swagger with Eclipse Public License 1.0 | 4 votes |
private void wrap(String propertyName, BodyParameter param) { RefModel m = (RefModel) param.getSchema(); String wrapperName = wrap(propertyName, m.getSimpleRef()); param.setSchema(new RefModel(wrapperName)); }
Example 12
Source File: MappingConverterImplTest.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 4 votes |
@Test public void testMtoParameters_Multiple() { List<Parameter> params = converter.mToParameters("", mapping( field("id", $(intv()).in("path").desc("id").$$), field("data", $(mapping( field("id", $(intv()).desc("id").$$), field("name", $(text(required())).desc("name").$$) )).in("body").$$) )); assertEquals(params.size(), 2); /// assertTrue(params.get(0) instanceof PathParameter); PathParameter p1 = (PathParameter) params.get(0); assertEquals(p1.getType(), "integer"); assertEquals(p1.getFormat(), "int32"); assertEquals(p1.getDescription(), "id"); assertEquals(p1.getRequired(), true); /// assertTrue(params.get(1) instanceof BodyParameter); BodyParameter p2 = (BodyParameter) params.get(1); ModelImpl model = (ModelImpl) p2.getSchema(); assertEquals(model.getType(), "object"); assertEquals(model.getRequired(), Arrays.asList("name")); assertTrue(model.getProperties() != null); assertEquals(model.getProperties().size(), 2); assertTrue(model.getProperties().get("id") instanceof IntegerProperty); assertTrue(model.getProperties().get("name") instanceof StringProperty); /// 'in' is required!!! try { List<Parameter> params1 = converter.mToParameters("", mapping( field("id", $(intv()).desc("id").$$), field("data", $(mapping( field("id", $(intv()).desc("id").$$), field("name", $(text(required())).desc("name").$$) )).in("body").$$) )); assertEquals(false, "shouldn't happen"); } catch (Exception e) { assertEquals(e.getMessage(), "in is required!!!"); } }