Java Code Examples for io.swagger.models.ModelImpl#getProperties()

The following examples show how to use io.swagger.models.ModelImpl#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: ExampleGenerator.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
private Object resolveModelToExample(String name, String mediaType, Model model, Set<String> processedModels) {
    if (processedModels.contains(name)) {
        return model.getExample();
    }
    if (model instanceof ModelImpl) {
        processedModels.add(name);
        ModelImpl impl = (ModelImpl) model;
        Map<String, Object> values = new HashMap<>();

        logger.debug("Resolving model '{}' to example", name);

        if (impl.getExample() != null) {
            logger.debug("Using example from spec: {}", impl.getExample());
            return impl.getExample();
        } else if (impl.getProperties() != null) {
            logger.debug("Creating example from model values");
            for (String propertyName : impl.getProperties().keySet()) {
                Property property = impl.getProperties().get(propertyName);
                values.put(propertyName, resolvePropertyToExample(propertyName, mediaType, property, processedModels));
            }
            impl.setExample(values);
        }
        return values;
    }
    return "";
}
 
Example 2
Source File: DefaultCodegen.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
protected void addProperties(Map<String, Property> properties,
                             List<String> required, Model model,
                             Map<String, Model> allDefinitions) {

    if (model instanceof ModelImpl) {
        ModelImpl mi = (ModelImpl) model;
        if (mi.getProperties() != null) {
            properties.putAll(mi.getProperties());
        }
        if (mi.getRequired() != null) {
            required.addAll(mi.getRequired());
        }
    } else if (model instanceof RefModel) {
        String interfaceRef = ((RefModel) model).getSimpleRef();
        Model interfaceModel = allDefinitions.get(interfaceRef);
        addProperties(properties, required, interfaceModel, allDefinitions);
    } else if (model instanceof ComposedModel) {
        for (Model component :((ComposedModel) model).getAllOf()) {
            addProperties(properties, required, component, allDefinitions);
        }
    }
}
 
Example 3
Source File: ExampleGenerator.java    From swurg with Apache License 2.0 6 votes vote down vote up
private Object resolveModelToExample(String name, String mediaType, Model model, Set<String> processedModels) {
    if (processedModels.contains(name)) {
        return model.getExample();
    }
    if (model instanceof ModelImpl) {
        processedModels.add(name);
        ModelImpl impl = (ModelImpl) model;
        Map<String, Object> values = new HashMap<>();

        logger.debug("Resolving model '{}' to example", name);

        if (impl.getExample() != null) {
            logger.debug("Using example from spec: {}", impl.getExample());
            return impl.getExample();
        } else if (impl.getProperties() != null) {
            logger.debug("Creating example from model values");
            for (String propertyName : impl.getProperties().keySet()) {
                Property property = impl.getProperties().get(propertyName);
                values.put(propertyName, resolvePropertyToExample(propertyName, mediaType, property, processedModels));
            }
            impl.setExample(values);
        }
        return values;
    }
    return "";
}
 
Example 4
Source File: TypeBuilder.java    From api-compiler with Apache License 2.0 6 votes vote down vote up
/**
 * Returns list of {@link com.google.protobuf.Field.Builder} created using the properties of a
 * {@link ModelImpl} object.
 */
private ImmutableList.Builder<Field> createFields(
    Service.Builder serviceBuilder, ModelImpl modelImpl) {
  ImmutableList.Builder<Field> fieldsBuilder = ImmutableList.builder();
  int count = 1;
  if (modelImpl.getProperties() != null) {
    for (String propertyName : modelImpl.getProperties().keySet()) {
      Property prop = modelImpl.getProperties().get(propertyName);
      TypeInfo typeInfo =
          ensureNamed(
              serviceBuilder,
              getTypeInfo(serviceBuilder, prop),
              NameConverter.propertyNameToMessageName(propertyName));
      fieldsBuilder.add(createField(propertyName, count++, typeInfo).build());
    }
  }
  return fieldsBuilder;
}
 
Example 5
Source File: WSDLSOAPOperationExtractorImplTestCase.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSwaggerModelForWSDLComplexTypeElement() throws Exception {
    for (WSDLSOAPOperation operation : operations) {
        List<ModelImpl> inputParameterModel = operation.getInputParameterModel();
        for (ModelImpl model : inputParameterModel) {
            Map<String, Property> properties = model.getProperties();
            for (String property : properties.keySet()) {
                Property currentProp = properties.get(property);
                if ("CheckPhoneNumber".equals(model.getName())) {
                    Assert.assertTrue("PhoneNumber".equals(currentProp.getName()) || "LicenseKey"
                            .equals(currentProp.getName()));
                    Assert.assertEquals("string", currentProp.getType());
                }
                if ("CheckPhoneNumbers".equals(model.getName())) {
                    Assert.assertTrue("PhoneNumbers".equals(currentProp.getName()) || "LicenseKey"
                            .equals(currentProp.getName()));
                    if ("PhoneNumbers".equals(currentProp.getName())) {
                        Assert.assertEquals("ref", currentProp.getType());
                    } else if ("LicenceKey".equals(currentProp.getName())) {
                        Assert.assertEquals("string", currentProp.getType());
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: SwaggerToProtoGenerator.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void convertDefinition(String modelName, ModelImpl model) {
  Map<String, Property> properties = model.getProperties();
  if (properties == null) {
    // it's a empty message
    properties = Collections.emptyMap();
  }

  createMessage(modelName, (Map<String, Object>) (Object) properties);
}
 
Example 7
Source File: BodyParameterAdapter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isJavaLangObject() {
  if (model instanceof ModelImpl) {
    ModelImpl modelImpl = (ModelImpl) model;
    return (ObjectProperty.TYPE.equals(modelImpl.getType())
        && modelImpl.getProperties() == null
        && modelImpl.getName() == null);
  }

  return false;
}
 
Example 8
Source File: ModelAdapter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isJavaLangObject() {
  if (model instanceof ModelImpl) {
    ModelImpl modelImpl = (ModelImpl) model;
    return Objects.equals(ObjectProperty.TYPE, modelImpl.getType())
        && modelImpl.getProperties() == null
        && modelImpl.getName() == null;
  }

  return false;
}
 
Example 9
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param model
 * @return
 */
private List<ClassMembers> getClassMembers(ModelImpl model, Map<String, Model> modelsMap) {
	LOGGER.entering(LOGGER.getName(), "getClassMembers-ModelImpl");

	List<ClassMembers> classMembers = new ArrayList<ClassMembers>();

	Map<String, Property> modelMembers = model.getProperties();
	if (modelMembers != null && !modelMembers.isEmpty()) {
		classMembers.addAll(convertModelPropertiesToClassMembers(modelMembers, model, modelsMap));
	} else {
		Property modelAdditionalProps = model.getAdditionalProperties();

		if (modelAdditionalProps instanceof RefProperty) {
			classMembers.add(getRefClassMembers((RefProperty) modelAdditionalProps));
		}

		if (modelAdditionalProps == null) {
			List<String> enumValues = model.getEnum();

			if (enumValues != null && !enumValues.isEmpty()) {
				classMembers.addAll(getEnum(enumValues));
			}
		}
	}

	LOGGER.exiting(LOGGER.getName(), "getClassMembers-ModelImpl");

	return classMembers;
}
 
Example 10
Source File: TypeBuilder.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the modelImpl is a wrapper of primitive type like string, Float etc; false
 * otherwise
 */
private boolean isPrimitiveTypeWrapper(ModelImpl modelImpl) {
  return (modelImpl.getProperties() == null && modelImpl.getAdditionalProperties() == null)
      && !Strings.isNullOrEmpty(modelImpl.getType())
      && !"object".equalsIgnoreCase(modelImpl.getType())
      && WellKnownTypeUtils.isPrimitiveType(modelImpl.getType());
}
 
Example 11
Source File: TypeBuilder.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
/** Returns true if the modelImpl has properties. */
private boolean hasProperties(ModelImpl modelImpl) {
  return modelImpl.getProperties() != null;
}