Java Code Examples for io.swagger.models.Model#getProperties()
The following examples show how to use
io.swagger.models.Model#getProperties() .
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: SwaggerUtils.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
public static Map<String, Property> getBodyProperties(Swagger swagger, Parameter parameter) { if (!(parameter instanceof BodyParameter)) { return null; } Model model = ((BodyParameter) parameter).getSchema(); if (model instanceof RefModel) { model = swagger.getDefinitions().get(((RefModel) model).getSimpleRef()); } if (model instanceof ModelImpl) { return model.getProperties(); } return null; }
Example 2
Source File: Knife4jController.java From yshopmall with Apache License 2.0 | 5 votes |
private void extend(Swagger swagger) { // 响应返回参数增强 for (Map.Entry<String, Model> entry : swagger.getDefinitions().entrySet()) { Model model = entry.getValue(); String key = entry.getKey(); if (key.contains("ApiResult") && !SwaggerUtil.getRealType(key).contains("ApiResult")) { Map<String, Property> props = model.getProperties(); Property dataProp = props.get("data"); Property newProp = SwaggerUtil.getNewProp(dataProp, SwaggerUtil.getRealType(key), swagger.getDefinitions()); props.put("data", newProp); } } }
Example 3
Source File: Swagger2Controller.java From yshopmall with Apache License 2.0 | 5 votes |
private Swagger extend(Swagger swagger) { // 响应返回参数增强 for (Map.Entry<String, Model> entry : swagger.getDefinitions().entrySet()) { Model model = entry.getValue(); String key = entry.getKey(); if (key.contains("ApiResult") && !SwaggerUtil.getRealType(key).contains("ApiResult")) { Map<String, Property> props = model.getProperties(); Property dataProp = props.get("data"); Property newProp = SwaggerUtil.getNewProp(dataProp, SwaggerUtil.getRealType(key), swagger.getDefinitions()); props.put("data", newProp); } } return swagger; }
Example 4
Source File: ModelDiff.java From swagger-diff with Apache License 2.0 | 5 votes |
private ModelDiff diff(Model leftInputModel, Model rightInputModel, String parentEl, Set<Model> visited) { // Stop recursing if both models are null // OR either model is already contained in the visiting history if ((null == leftInputModel && null == rightInputModel) || visited.contains(leftInputModel) || visited.contains(rightInputModel)) { return this; } Model leftModel = isModelReference(leftInputModel) ? findReferenceModel(leftInputModel, oldDedinitions) : leftInputModel; Model rightModel = isModelReference(rightInputModel) ? findReferenceModel(rightInputModel, newDedinitions) : rightInputModel; Map<String, Property> leftProperties = null == leftModel ? null : leftModel.getProperties(); Map<String, Property> rightProperties = null == rightModel ? null : rightModel.getProperties(); // Diff the properties MapKeyDiff<String, Property> propertyDiff = MapKeyDiff.diff(leftProperties, rightProperties); increased.addAll(convert2ElPropertys(propertyDiff.getIncreased(), parentEl)); missing.addAll(convert2ElPropertys(propertyDiff.getMissing(), parentEl)); // Recursively find the diff between properties List<String> sharedKey = propertyDiff.getSharedKey(); sharedKey.stream().forEach((key) -> { Property left = leftProperties.get(key); Property right = rightProperties.get(key); Model leftSubModel = findModel(left, oldDedinitions); Model rightSubModel = findModel(left, newDedinitions); if (leftSubModel != null || rightSubModel != null) { diff(leftSubModel, rightSubModel, buildElString(parentEl, key), copyAndAdd(visited, leftModel, rightModel)); } else if (left != null && right != null && !left.equals(right)) { // Add a changed ElProperty if not a Reference // Useless changed.add(addChangeMetadata(convert2ElProperty(key, parentEl, left), left, right)); } }); return this; }
Example 5
Source File: SchemaObjectResolver.java From assertj-swagger with Apache License 2.0 | 5 votes |
private Map<String, Property> resolveProperties(Model definition, Swagger owningSchema, Set<String> seenRefs) { Map<String, Property> result; // if the definition does not contain any property, then the model will return null instead of an empty map final Map<String, Property> definitionProperties = definition.getProperties() != null ? definition.getProperties() : Collections.emptyMap(); if (definition instanceof RefModel) { // Don't navigate ref-def cycles infinitely final RefModel refDef = (RefModel) definition; if (seenRefs.contains(refDef.getSimpleRef())) { return Collections.emptyMap(); } else { seenRefs.add(refDef.getSimpleRef()); } result = resolveProperties(findDefinition(owningSchema.getDefinitions(), refDef), owningSchema, seenRefs); } else if (definition instanceof ComposedModel) { Map<String, Property> allProperties = new HashMap<>(); if (definitionProperties != null) { allProperties.putAll(definitionProperties); } for (final Model childDefinition : ((ComposedModel) definition).getAllOf()) { allProperties.putAll(resolveProperties(childDefinition, owningSchema, seenRefs)); } result = allProperties; } else { result = definitionProperties; } return result; }
Example 6
Source File: SwaggerConverter.java From swagger-parser with Apache License 2.0 | 5 votes |
private void addProperties(Model v2Model, Schema schema) { if ((v2Model.getProperties() != null) && (v2Model.getProperties().size() > 0)) { Map<String, Property> properties = v2Model.getProperties(); properties.forEach((k, v) -> { schema.addProperties(k, convert(v)); }); } }
Example 7
Source File: JaxrsReaderTest.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
private Map<String, Property> getProperties(Map<String, Model> models, String className) { assertTrue(models.containsKey(className)); Model model = models.get(className); if (model instanceof ComposedModel) { ComposedModel composedResponse = (ComposedModel) model; return composedResponse.getChild().getProperties(); } else { return model.getProperties(); } }