private static Map<String, Property> getPropertiesForComposedModel(ComposedModel model, Map<String, Model> definitions) { //TODO: Unused method, make sure this is never used and then remove it. Map<String, Property> combinedProperties; if (model.getParent() instanceof RefModel) { Map<String, Property> parentProperties = definitions.get(((RefModel) model.getParent()).getSimpleRef()).getProperties(); if (parentProperties == null) { return null; } else { combinedProperties = new LinkedHashMap<>(parentProperties); } } else { combinedProperties = new LinkedHashMap<>(model.getParent().getProperties()); } Map<String, Property> childProperties; if (model.getChild() instanceof RefModel) { childProperties = definitions.get(((RefModel) model.getChild()).getSimpleRef()).getProperties(); } else { childProperties = model.getChild().getProperties(); } if (childProperties != null) { combinedProperties.putAll(childProperties); } return combinedProperties; }
example = exampleMapForProperties(model.getProperties(), definitions, definitionDocumentResolver, markupDocBuilder, refStack);
types.put(type, object); Map<String, Object> example = new LinkedHashMap<>(); Optional.ofNullable(model.getProperties()) .ifPresent(properties -> properties.forEach((name, property) -> { if (property instanceof RefProperty) {
private List<Parameter> expandParameter(Map<String, Model> models, RouteParameter it, Supplier<SerializableParameter> factory, String typeName, String prefix, boolean optional) { List<Parameter> parameters = new ArrayList<>(); Model model = models.get(typeName); Map<String, Property> properties = model.getProperties(); Optional.ofNullable(properties).ifPresent(props -> props.values().stream() .flatMap(p -> { SerializableParameter result = complement(p, it, factory.get()); String name = prefix + p.getName(); if (p instanceof RefProperty) { return expandParameter(models, it, factory, ((RefProperty) p).getSimpleRef(), name + ".", optional).stream(); } else { result.setName(name); boolean required; if (optional) { required = false; } else { required = p.getRequired(); } String desc = Strings.emptyToNull(p.getDescription()); result.setRequired(required); result.setDescription(desc); return Stream.of(result); } }) .forEach(parameters::add) ); return parameters; }
/** * Mostly for kotlin null safe operator and immutable properties. * * @param type Target type. * @param model Model. * @return Input model. */ private Model doModel(Type type, Model model) { Map<String, Property> properties = model.getProperties(); if (properties != null) { BeanDescription desc = Json.mapper().getSerializationConfig() .introspect(Json.mapper().constructType(type)); for (BeanPropertyDefinition beanProperty : desc.findProperties()) { Property property = properties.get(beanProperty.getName()); if (property != null) { property.setRequired(beanProperty.isRequired()); } } } return model; }
example = schema.getExample(); if (example == null) { example = exampleMapForProperties(schema.getProperties(), definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
@Test public void testPropertiesTableComponent() throws URISyntaxException { //Given Path file = Paths.get(PropertiesTableComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); Swagger swagger = converter.getContext().getSwagger(); Model petModel = swagger.getDefinitions().get("Pet"); Swagger2MarkupConverter.Context context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); List<ObjectType> localDefinitions = new ArrayList<>(); //When markupDocBuilder = new PropertiesTableComponent(context, new DefinitionDocumentResolverFromDefinition(context)) .apply(markupDocBuilder, PropertiesTableComponent.parameters(petModel.getProperties(), "Pet", localDefinitions)); markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8); //Then Path expectedFile = getExpectedFile(COMPONENT_NAME); DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME)); } }
return new EnumType(modelImpl.getTitle(), modelImpl.getEnum()); else if (modelImpl.getProperties() != null) { ObjectType objectType = new ObjectType(modelImpl.getTitle(), model.getProperties());
private LinkedHashMap<String, AbstractSerializableParameter<?>> getFlattenParams(Model paramModel) { LinkedHashMap<String, AbstractSerializableParameter<?>> flattenParamMap = new LinkedHashMap<>(); // traversal the properties of current paramModel // create simple parameters, nesting object param is ignored for (Entry<String, Property> propertyEntry : paramModel.getProperties().entrySet()) { if (ParamUtils.isComplexProperty(propertyEntry.getValue())) { throw new Error( "A nesting complex field is found in the query object and this is not supported, field name = [" + propertyEntry.getKey() + "]. Please remove this field or tag @JsonIgnore on it."); } AbstractSerializableParameter<?> newParameter = createSimpleParam(propertyEntry); flattenParamMap.put(propertyEntry.getKey(), newParameter); } return flattenParamMap; }
/** * Remove property from {@link Model} for provided {@link ApiModelProperty}. * @param apiModelPropertyAnnotation annotation * @param model model with properties */ private void processProperty(ApiModelProperty apiModelPropertyAnnotation, Model model) { if (apiModelPropertyAnnotation == null) { return; } String apiModelPropertyAccess = apiModelPropertyAnnotation.access(); String apiModelPropertyName = apiModelPropertyAnnotation.name(); // If the @ApiModelProperty is not populated with both #name and #access, skip it if (apiModelPropertyAccess.isEmpty() || apiModelPropertyName.isEmpty()) { return; } // Check to see if the value of @ApiModelProperty#access is one to exclude. // If so, remove it from the previously-calculated model. if (apiModelPropertyAccessExclusions.contains(apiModelPropertyAccess)) { model.getProperties().remove(apiModelPropertyName); } }
@Override public Model getUPDATEModel(Representation rep) { Model model = getCREATEModel(rep); model.getProperties().remove("property"); return model; }
@Override public void model(Model model) { model.setProperties(fillMap(model.getProperties())); if (model instanceof ModelImpl) { } }
@Override public Model getGETModel(Representation rep) { Model model = super.getGETModel(rep); model.getProperties().remove("memberIds"); return model; }
private static void defineElementPropertiesOf(final Element parent, final Model model, final Swagger swagger, final Map<String, SchemaPrefixAndElement> moreSchemas) { final Map<String, Property> properties = model.getProperties(); for (final Entry<String, Property> propertyEntry : properties.entrySet()) { final String propertyName = propertyEntry.getKey(); final Property property = propertyEntry.getValue(); if (XmlSchemaHelper.isElement(property)) { defineElementProperty(propertyName, property, parent, swagger, moreSchemas); } } }
private static void defineElementPropertiesOf(final Element parent, final Model model, final Swagger swagger, final Map<String, SchemaPrefixAndElement> moreSchemas) { final Map<String, Property> properties = model.getProperties(); for (final Entry<String, Property> propertyEntry : properties.entrySet()) { final String propertyName = propertyEntry.getKey(); final Property property = propertyEntry.getValue(); if (isElement(property)) { defineElementProperty(propertyName, property, parent, swagger, moreSchemas); } } }
@Override public void visit(String name, RefProperty property) { parents.add(property); Model model = swagger.getDefinitions().get(property.getSimpleRef()); walkProperties(swagger, parents, model.getProperties(), fqn(namePrefix, name), nis(nisPrefix, name, false), pa); parents.remove(property); } };
private static boolean schemaIsNotSpecified(final Model schema) { if (schema == null) { return true; } if (schema instanceof ArrayModel) { return ((ArrayModel) schema).getItems() == null; } final Map<String, Property> properties = schema.getProperties(); final boolean noProperties = properties == null || properties.isEmpty(); final boolean noReference = schema.getReference() == null; return noProperties && noReference; }
@Override public Model getCREATEModel(Representation rep) { Model model = super.getCREATEModel(rep); model.getProperties().get("familyName").setRequired(false); return model; } }
private static boolean schemaIsNotSpecified(final Model schema) { if (schema == null) { return true; } if (schema instanceof ArrayModel) { return ((ArrayModel) schema).getItems() == null; } final Map<String, Property> properties = schema.getProperties(); final boolean noProperties = properties == null || properties.isEmpty(); final boolean noReference = schema.getReference() == null; return noProperties && noReference; }
private static boolean schemaIsNotSpecified(final Model schema) { if (schema == null) { return true; } if (schema instanceof ArrayModel) { return ((ArrayModel) schema).getItems() == null; } final Map<String, Property> properties = schema.getProperties(); final boolean noProperties = properties == null || properties.isEmpty(); final boolean noReference = schema.getReference() == null; return noProperties && noReference; }