io.swagger.models.properties.ObjectProperty Java Examples

The following examples show how to use io.swagger.models.properties.ObjectProperty. 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: ConverterMgr.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private static void initConverters() {
  // inner converters
  for (Class<? extends Property> propertyCls : PROPERTY_MAP.keySet()) {
    addInnerConverter(propertyCls);
  }

  converterMap.put(RefProperty.class, new RefPropertyConverter());
  converterMap.put(ArrayProperty.class, new ArrayPropertyConverter());
  converterMap.put(MapProperty.class, new MapPropertyConverter());
  converterMap.put(StringProperty.class, new StringPropertyConverter());
  converterMap.put(ObjectProperty.class, new ObjectPropertyConverter());

  converterMap.put(ModelImpl.class, new ModelImplConverter());
  converterMap.put(RefModel.class, new RefModelConverter());
  converterMap.put(ArrayModel.class, new ArrayModelConverter());
}
 
Example #2
Source File: SwaggerInventory.java    From swagger-parser with Apache License 2.0 6 votes vote down vote up
public void process(Property property) {
    this.properties.add(property);
    if(property instanceof ArrayProperty) {
        ArrayProperty p = (ArrayProperty)property;
        Property ap = p.getItems();
        this.process(ap);
    } else if(property instanceof MapProperty) {
        MapProperty p1 = (MapProperty)property;
    } else if(property instanceof ObjectProperty) {
        ObjectProperty p2 = (ObjectProperty)property;
        if(p2.getProperties() != null) {
            Iterator ap1 = p2.getProperties().keySet().iterator();

            while(ap1.hasNext()) {
                String name = (String)ap1.next();
                Property ip = (Property)p2.getProperties().get(name);
                this.process(ip);
            }
        }
    }

}
 
Example #3
Source File: SwaggerRefHelper.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
public static String getFromResponse(Operation oper, String responseCode) {
    Response response = oper.getResponses().get(responseCode);
    if(response == null) return null;

    Property prop = response.getSchema();

    if(prop instanceof ObjectProperty) {
        prop = ((ObjectProperty) prop).getProperties().get("output");
    }

    if(prop instanceof RefProperty) {
        return ((RefProperty)prop).getSimpleRef();
    }

    if(prop == null) return null;

    RefProperty schema = (RefProperty) prop;
    return schema.getSimpleRef();
}
 
Example #4
Source File: ComponentSchemaTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private Optional<Property> getFieldSchema(Field field, GenerationContext generationContext) {
	if (GeneratorUtils.shouldBeIgnored(field)) {
		return Optional.empty();
	}

	Class<?> typeSignature = field.getType();
	Annotation[] annotations = field.getAnnotations();

	Optional<Property> optionalProperty;
	if (typeSignature.isPrimitive()) {
		optionalProperty = createBaseTypeProperty(field, annotations);
	} else if (typeSignature.isArray()) {
		optionalProperty = createArrayTypeProperty(generationContext, typeSignature, annotations);
	} else if (StringUtils.equalsIgnoreCase(typeSignature.getName(), "java.lang.Object")) {
		ObjectProperty objectSchema = new ObjectProperty();
		objectSchema.setName(field.getName());
		return Optional.of(objectSchema);
	} else if (typeSignature.isAssignableFrom(List.class)) {
		if (field.getGenericType() instanceof ParameterizedType) {
			Class<?> listGenericParameter = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
			optionalProperty = Optional.of(parseArraySignature(listGenericParameter, generationContext, annotations));
		} else {
			optionalProperty = Optional.empty();
		}
	} else {
		optionalProperty = createClassRefProperty(generationContext, typeSignature, annotations);
	}
	optionalProperty.ifPresent(property -> property.setRequired(isRequired(annotations)));
	return optionalProperty;
}
 
Example #5
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private boolean isFile(Property property) {
	if (property instanceof ObjectProperty) {
		ObjectProperty objectProperty = (ObjectProperty) property;
		if (objectProperty.getProperties() != null && !objectProperty.getProperties().isEmpty()) {
			return objectProperty.getProperties().entrySet().iterator().next().getValue() instanceof FileProperty;
		}
	}
	return false;
}
 
Example #6
Source File: SwaggerUtil.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
/**
 * 获取Swagger支持的类型
 *
 * @return {@link Map<String,  AbstractProperty >}
 */
private static Map<String, AbstractProperty> getPropMap() {
    Map<String, AbstractProperty> map = new HashMap<>(8);
    map.put("integer", new IntegerProperty());
    map.put("int", new IntegerProperty());
    map.put("long", new LongProperty());
    map.put("string", new StringProperty());
    map.put("object", new ObjectProperty());
    map.put("array", new ArrayProperty());
    map.put("boolean", new BooleanProperty());
    map.put("date", new DateTimeProperty());
    return map;
}
 
Example #7
Source File: SwaggerUtils.java    From swagger-showdoc with Apache License 2.0 5 votes vote down vote up
private static void modelDocAddJdd(Swagger swagger, StringBuilder builder, AtomicReference<Model> backModel, Map<String, Property> properties){
    if(null != properties){
        properties.forEach((zd,property)->{

            modelDocAdd(swagger, builder, backModel, property);
            if(null != backModel.get()){
                modelDoc(swagger,builder,backModel.get());
            }

            if(property instanceof ObjectProperty){
                ObjectProperty objectProperty = (ObjectProperty)property;
                Map<String, Property> objectProperties = objectProperty.getProperties();
                modelDocAddJdd(swagger,builder,backModel,objectProperties);
            }

            if(property instanceof ArrayProperty){
                ArrayProperty arrayProperty = (ArrayProperty)property;
                Property items = arrayProperty.getItems();
                modelDocAdd(swagger, builder, backModel, items);

                if(null != backModel.get()){
                    modelDoc(swagger,builder,backModel.get());
                }
            }



        });
    }
}
 
Example #8
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static boolean isComplexProperty(Property property) {
  if (property instanceof RefProperty || property instanceof ObjectProperty || property instanceof MapProperty) {
    return true;
  }

  if (ArrayProperty.class.isInstance(property)) {
    return isComplexProperty(((ArrayProperty) property).getItems());
  }

  return false;
}
 
Example #9
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 #10
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 #11
Source File: SwaggerRefHelper.java    From yang2swagger with Eclipse Public License 1.0 5 votes vote down vote up
public static Stream<String> toUses(Property p) {
    if(p instanceof RefProperty) return Stream.of(((RefProperty)p).getSimpleRef());
    if(p instanceof ArrayProperty) return toUses(((ArrayProperty)p).getItems());

    if(p instanceof ObjectProperty) {
        return ((ObjectProperty)p).getProperties().values().stream()
                .flatMap(SwaggerRefHelper::toUses);
    }

    return Stream.empty();
}
 
Example #12
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param operation
 * @return
 */
private String getInterfaceReturnType(Operation operation) {
	String returnType = "void";

	Map<String, Response> responses = operation.getResponses();
	for (Map.Entry<String, Response> responsesEntry : responses.entrySet()) {
		String responseCode = responsesEntry.getKey();

		if (!(responseCode.equalsIgnoreCase("default") || Integer.parseInt(responseCode) >= 300)) {
			Property responseProperty = responsesEntry.getValue().getSchema();

			if (responseProperty instanceof RefProperty) {
				returnType = ((RefProperty) responseProperty).getSimpleRef();
			} else if (responseProperty instanceof ArrayProperty) {
				Property arrayResponseProperty = ((ArrayProperty) responseProperty).getItems();
				if (arrayResponseProperty instanceof RefProperty) {
					returnType = new StringBuilder().append(((RefProperty) arrayResponseProperty).getSimpleRef())
							.append("[]").toString();
				}
			} else if (responseProperty instanceof ObjectProperty) {
				returnType = new StringBuilder().append(toTitleCase(operation.getOperationId())).append("Generated")
						.toString();
			}
		}
	}

	return returnType;
}
 
Example #13
Source File: SwaggerDefinition.java    From Web-API with MIT License 5 votes vote down vote up
private static Response constructResponse(int status, String error) {
    Property statusProp = new IntegerProperty()
            .description("The status code of the error (also provided in the HTTP header)");
    statusProp.setExample(status);

    Property errorProp = new StringProperty()
            .description("The error message describing the error");
    errorProp.setExample((Object)error);

    return new Response()
            .description(error)
            .schema(new ObjectProperty()
                    .property("status", statusProp)
                    .property("error", errorProp));
}
 
Example #14
Source File: SOAPOperationBindingUtils.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * gets parameters from the soap operation and populates them in {@link WSDLSOAPOperation}
 *
 * @param soapOperations soap binding operations
 */
private static void populateSoapOperationParameters(Set<WSDLSOAPOperation> soapOperations) {

    String[] primitiveTypes = { "string", "byte", "short", "int", "long", "float", "double", "boolean" };
    List primitiveTypeList = Arrays.asList(primitiveTypes);
    if (soapOperations != null) {
        for (WSDLSOAPOperation operation : soapOperations) {
            String resourcePath;
            String operationName = operation.getName();
            operation.setSoapBindingOpName(operationName);
            operation.setHttpVerb(HTTPConstants.HTTP_METHOD_POST);
            if (operationName.toLowerCase().startsWith("get") && operation.getInputParameterModel() != null
                    && operation.getInputParameterModel().size() <= 1) {

                Map<String, Property> properties = null;
                if (operation.getInputParameterModel().size() > 0
                        && operation.getInputParameterModel().get(0) != null) {
                    properties = operation.getInputParameterModel().get(0).getProperties();
                }
                if (properties == null) {
                    operation.setHttpVerb(HTTPConstants.HTTP_METHOD_GET);
                } else if (properties.size() <= 1) {
                    for (String property : properties.keySet()) {
                        String type = properties.get(property).getType();
                        if (!(type.equals(ObjectProperty.TYPE) || type.equals(ArrayProperty.TYPE) || type
                                .equals(RefProperty.TYPE))) {
                            operation.setHttpVerb(HTTPConstants.HTTP_METHOD_GET);
                        }
                    }
                }
            }
            resourcePath = operationName;
            resourcePath =
                    resourcePath.substring(0, 1).toLowerCase() + resourcePath.substring(1, resourcePath.length());
            operation.setName(resourcePath);
            if (log.isDebugEnabled()) {
                log.debug("REST resource path for SOAP operation: " + operationName + " is: " + resourcePath);
            }

            List<WSDLOperationParam> params = operation.getParameters();
            if (log.isDebugEnabled() && params != null) {
                log.debug("SOAP operation: " + operationName + " has " + params.size() + " parameters");
            }
            if (params != null) {
                for (WSDLOperationParam param : params) {
                    if (param.getDataType() != null) {
                        String dataTypeWithNS = param.getDataType();
                        String dataType = dataTypeWithNS.substring(dataTypeWithNS.indexOf(":") + 1);
                        param.setDataType(dataType);
                        if (!primitiveTypeList.contains(dataType)) {
                            param.setComplexType(true);
                        }
                    }
                }
            }
        }
    } else {
        log.info("No SOAP operations found in the WSDL");
    }
}
 
Example #15
Source File: SwaggerUtils.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * This method will generate a sample request body for the request.
 *
 * @param method        Rest resource method.
 * @param operation     Swagger operation object.
 * @param parameterList list of parameters.
 */
private static void generateSampleRequestPayload(String method, Operation operation,
                                                 List<AxisResourceParameter> parameterList) {
    // GET method does not have a body
    if (!"GET".equals(method)) {
        BodyParameter bodyParameter = new BodyParameter();
        bodyParameter.description("Sample Payload");
        bodyParameter.name("payload");
        bodyParameter.setRequired(false);

        ModelImpl modelschema = new ModelImpl();
        modelschema.setType("object");
        Map<String, Property> propertyMap = new HashMap<>(1);
        ObjectProperty objectProperty = new ObjectProperty();
        objectProperty.name("payload");

        Map<String, Property> payloadProperties = new HashMap<>();
        for (AxisResourceParameter resourceParameter : parameterList) {
            switch (resourceParameter.getParameterDataType()) {
                case SwaggerProcessorConstants.INTEGER:
                    payloadProperties.put(resourceParameter.getParameterName(), new IntegerProperty());
                    break;
                case SwaggerProcessorConstants.NUMBER:
                    payloadProperties.put(resourceParameter.getParameterName(), new DoubleProperty());
                    break;
                case SwaggerProcessorConstants.BOOLEAN:
                    payloadProperties.put(resourceParameter.getParameterName(), new BooleanProperty());
                    break;
                default:
                    payloadProperties.put(resourceParameter.getParameterName(), new StringProperty());
                    break;
            }
        }

        objectProperty.setProperties(payloadProperties);
        propertyMap.put("payload", objectProperty);
        modelschema.setProperties(propertyMap);
        bodyParameter.setSchema(modelschema);
        operation.addParameter(bodyParameter);
    }
}
 
Example #16
Source File: WSDL11SOAPOperationExtractor.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Gets swagger output parameter model for a given soap operation
 *
 * @param bindingOperation soap operation
 * @return list of swagger models for the parameters
 * @throws APIMgtWSDLException
 */
private List<ModelImpl> getSoapOutputParameterModel(BindingOperation bindingOperation) throws APIMgtWSDLException {
    List<ModelImpl> outputParameterModelList = new ArrayList<>();
    Operation operation = bindingOperation.getOperation();
    if (operation != null) {
        Output output = operation.getOutput();
        if (output != null) {
            Message message = output.getMessage();
            if (message != null) {
                Map map = message.getParts();

                for (Object obj : map.entrySet()) {
                    Map.Entry entry = (Map.Entry) obj;
                    Part part = (Part) entry.getValue();
                    if (part != null) {
                        if (part.getElementName() != null) {
                            outputParameterModelList.add(parameterModelMap.get(part.getElementName()
                                    .getLocalPart()));
                        } else {
                            if (part.getTypeName() != null && parameterModelMap
                                    .containsKey(part.getTypeName().getLocalPart())) {
                                outputParameterModelList
                                        .add(parameterModelMap.get(part.getTypeName().getLocalPart()));
                            } else {
                                ModelImpl model = new ModelImpl();
                                model.setType(ObjectProperty.TYPE);
                                model.setName(message.getQName().getLocalPart());
                                if (getPropertyFromDataType(part.getTypeName().getLocalPart()) instanceof RefProperty) {
                                    RefProperty property = (RefProperty) getPropertyFromDataType(part.getTypeName()
                                            .getLocalPart());
                                    property.set$ref(SOAPToRESTConstants.Swagger.DEFINITIONS_ROOT +
                                            part.getTypeName().getLocalPart());
                                    model.addProperty(part.getName(), property);
                                } else {
                                    model.addProperty(part.getName(),
                                            getPropertyFromDataType(part.getTypeName().getLocalPart()));
                                }
                                parameterModelMap.put(model.getName(), model);
                                outputParameterModelList.add(model);
                            }
                        }
                    }
                }
            }
        }
    }
    return outputParameterModelList;
}
 
Example #17
Source File: PropertyAdapter.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isJavaLangObject() {
  return property instanceof ObjectProperty;
}
 
Example #18
Source File: ConverterMgrTest.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Test
public void should_support_object_property() {
  Property property = new ObjectProperty();
  assertThat(ConverterMgr.findJavaType(swagger, property).getRawClass())
      .isEqualTo(Object.class);
}
 
Example #19
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public static boolean isBean(Property property) {
  return property instanceof RefProperty || property instanceof ObjectProperty;
}