io.swagger.models.ModelImpl Java Examples

The following examples show how to use io.swagger.models.ModelImpl. 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: JaxrsReader.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
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 #2
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 #3
Source File: SwaggerToWordExample.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
private List<TextRenderData> fomartSchemaModel(Model schemaModel) {
    List<TextRenderData> schema = new ArrayList<>();
    if (null == schemaModel) return schema;
    // if array
    if (schemaModel instanceof ArrayModel) {
        Property items = ((ArrayModel) schemaModel).getItems();
        schema.add(new TextRenderData("<"));
        schema.addAll(formatProperty(items));
        schema.add(new TextRenderData(">"));
        schema.add(new TextRenderData(((ArrayModel) schemaModel).getType()));
    } else
        // if ref
        if (schemaModel instanceof RefModel) {
            String ref = ((RefModel) schemaModel).get$ref().substring("#/definitions/".length());
            schema.add(new HyperLinkTextRenderData(ref, "anchor:" + ref));
        } else if (schemaModel instanceof ModelImpl) {
            schema.add(new TextRenderData(((ModelImpl) schemaModel).getType()));
        }
    // ComposedModel
    return schema;
}
 
Example #4
Source File: WSDLSOAPOperationExtractorImplTestCase.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSwaggerModelForCompositeComplexType() throws Exception {
    APIMWSDLReader wsdlReader = new APIMWSDLReader(
            Thread.currentThread().getContextClassLoader().getResource("wsdls/sample-service.wsdl")
                    .toExternalForm());
    byte[] wsdlContent = wsdlReader.getWSDL();
    WSDL11SOAPOperationExtractor processor = SOAPOperationBindingUtils.getWSDL11SOAPOperationExtractor(wsdlContent,
            wsdlReader);
    Map<String, ModelImpl> parameterModelMap = processor.getWsdlInfo().getParameterModelMap();
    Assert.assertNotNull(parameterModelMap);
    Assert.assertTrue("wsdl complex types has not been properly parsed",
            parameterModelMap.size() == 12);
    //composite complex type
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest"));
    Assert.assertEquals(7, parameterModelMap.get("ItemSearchRequest").getProperties().size());
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks"));
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks"));
    Assert.assertEquals(ArrayProperty.TYPE,
            parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks").getType());
    Assert.assertNotNull(((ArrayProperty) parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks"))
            .getItems());
}
 
Example #5
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 #6
Source File: OperationsTransformer.java    From spring-openapi with MIT License 6 votes vote down vote up
private io.swagger.models.parameters.Parameter createRequestBody(Method method, String userDefinedContentType) {
	ParameterNamePair requestBodyParameter = getRequestBody(method);

	if (requestBodyParameter == null) {
		return null;
	}
	if (GeneratorUtils.shouldBeIgnored(requestBodyParameter.getParameter())) {
		logger.info("Ignoring parameter {}", requestBodyParameter.getName());
		return null;
	}

	ModelImpl content = new ModelImpl();
	Property property = createMediaType(
			requestBodyParameter.getParameter().getType(),
			requestBodyParameter.getName(),
			singletonList(getGenericParam(requestBodyParameter.getParameter()))
	);
	content.addProperty(resolveContentType(userDefinedContentType, requestBodyParameter.getParameter()), property);

	OpenApiV2GeneratorConfig config = openApiV2GeneratorConfig.get();
	return config.getCompatibilityMode() == CompatibilityMode.NSWAG && !isFile(property)
			? createNswagRequestBody(requestBodyParameter, property)
			: createStandardRequestBody(method, requestBodyParameter, content, property);
}
 
Example #7
Source File: ComponentSchemaTransformer.java    From spring-openapi with MIT License 6 votes vote down vote up
private Model traverseAndAddProperties(ModelImpl schema, GenerationContext generationContext, Class<?> superclass, Class<?> clazz) {
	if (!isInPackagesToBeScanned(superclass, generationContext)) {
		// adding properties from parent classes is present due to swagger ui bug, after using different ui
		// this becomes relevant only for third party packages
		getClassProperties(superclass, generationContext).forEach(schema::addProperty);
		if (superclass.getSuperclass() != null && !"java.lang".equals(superclass.getSuperclass().getPackage().getName())) {
			return traverseAndAddProperties(schema, generationContext, superclass.getSuperclass(), superclass);
		}
		return schema;
	} else {
		RefModel parentClassSchema = new RefModel();
		parentClassSchema.set$ref(CommonConstants.COMPONENT_REF_PREFIX + superclass.getSimpleName());

		ComposedModel composedSchema = new ComposedModel();
		composedSchema.setAllOf(Arrays.asList(parentClassSchema, schema));
		InheritanceInfo inheritanceInfo = generationContext.getInheritanceMap().get(superclass.getName());
		if (inheritanceInfo != null) {
			String discriminatorName = inheritanceInfo.getDiscriminatorClassMap().get(clazz.getName());
			composedSchema.setVendorExtension("x-discriminator-value", discriminatorName);
			composedSchema.setVendorExtension("x-ms-discriminator-value", discriminatorName);
		}
		return composedSchema;
	}
}
 
Example #8
Source File: ComponentSchemaTransformer.java    From spring-openapi with MIT License 6 votes vote down vote up
public Model transformSimpleSchema(Class<?> clazz, GenerationContext generationContext) {
	if (clazz.isEnum()) {
		return createEnumModel(clazz.getEnumConstants());
	}

	ModelImpl schema = new ModelImpl();
	schema.setType("object");
	getClassProperties(clazz, generationContext).forEach(schema::addProperty);

	if (generationContext.getInheritanceMap().containsKey(clazz.getName())) {
		InheritanceInfo inheritanceInfo = generationContext.getInheritanceMap().get(clazz.getName());
		schema.setDiscriminator(inheritanceInfo.getDiscriminatorFieldName());
	}
	if (clazz.getSuperclass() != null) {
		return traverseAndAddProperties(schema, generationContext, clazz.getSuperclass(), clazz);
	}
	return schema;
}
 
Example #9
Source File: WSDLSOAPOperationExtractorImplTestCase.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSwaggerModelForSimpleType() throws Exception {
    APIMWSDLReader wsdlReader = new APIMWSDLReader(
            Thread.currentThread().getContextClassLoader().getResource("wsdls/sample-service.wsdl")
                    .toExternalForm());
    byte[] wsdlContent = wsdlReader.getWSDL();
    WSDL11SOAPOperationExtractor processor = SOAPOperationBindingUtils.getWSDL11SOAPOperationExtractor(wsdlContent,
            wsdlReader);
    Map<String, ModelImpl> parameterModelMap = processor.getWsdlInfo().getParameterModelMap();
    Assert.assertNotNull(parameterModelMap);
    //get simple type
    Assert.assertNotNull(parameterModelMap.get("Condition"));
    Assert.assertEquals("string", parameterModelMap.get("Condition").getType());
    //get simple type inside complex type
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Availability"));
    Assert.assertEquals("string",
            parameterModelMap.get("ItemSearchRequest").getProperties().get("Availability").getType());
}
 
Example #10
Source File: SwaggerHandlerImplTest.java    From spring-cloud-huawei with Apache License 2.0 6 votes vote down vote up
private void init() {
  mockMap.put("xxxx", apiListing);
  mockDoc = new Documentation("xx", "/xx", null, mockMap,
      null, Collections.emptySet(), Collections.emptySet(), null, Collections.emptySet(), Collections.emptyList());
  mockSwagger = new Swagger();
  mockSwagger.setInfo(new Info());
  Map<String, Model> defMap = new HashMap<>();
  defMap.put("xx", new ModelImpl());
  mockSwagger.setDefinitions(defMap);
  Map<String, Path> pathMap = new HashMap<>();
  pathMap.put("xx", new Path());
  mockSwagger.setPaths(pathMap);
  new Expectations() {
    {
      documentationCache.documentationByGroup(anyString);
      result = mockDoc;

      DefinitionCache.getClassNameBySchema(anyString);
      result = "app";

      mapper.mapDocumentation((Documentation) any);
      result = mockSwagger;
    }
  };
}
 
Example #11
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param modelObject
 * @param modelsMap
 * @return
 */
private List<ClassMembers> getClassMembers(Model modelObject, Map<String, Model> modelsMap) {
	LOGGER.entering(LOGGER.getName(), "getClassMembers");

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

	if (modelObject instanceof ModelImpl) {
		classMembers = getClassMembers((ModelImpl) modelObject, modelsMap);
	} else if (modelObject instanceof ComposedModel) {
		classMembers = getClassMembers((ComposedModel) modelObject, modelsMap);
	} else if (modelObject instanceof ArrayModel) {
		classMembers = getClassMembers((ArrayModel) modelObject, modelsMap);
	}

	LOGGER.exiting(LOGGER.getName(), "getClassMembers");
	return classMembers;
}
 
Example #12
Source File: DefaultCodegen.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
/**
 * Recursively look for a discriminator in the interface tree
 */
private boolean isDiscriminatorInInterfaceTree(ComposedModel model, Map<String, Model> allDefinitions) {
    if (model == null || allDefinitions == null)
        return false;

    Model child = model.getChild();
    if (child instanceof ModelImpl && ((ModelImpl) child).getDiscriminator() != null) {
        return true;
    }
    for (RefModel _interface : model.getInterfaces()) {
        Model interfaceModel = allDefinitions.get(_interface.getSimpleRef());
        if (interfaceModel instanceof ModelImpl && ((ModelImpl) interfaceModel).getDiscriminator() != null) {
            return true;
        }
        if (interfaceModel instanceof ComposedModel) {

            return isDiscriminatorInInterfaceTree((ComposedModel) interfaceModel, allDefinitions);
        }
    }
    return false;
}
 
Example #13
Source File: DataProviders.java    From binder-swagger-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected DataProvider collectRefProperty(Swagger swagger, RefProperty schema, boolean clean) {
    Model model = swagger.getDefinitions() != null ? swagger.getDefinitions().get(schema.getSimpleRef()) : null;
    if (model == null) throw new IllegalArgumentException("CAN'T find model for " + schema.getSimpleRef());

    if (model instanceof ArrayModel) {
        DataProvider itemProvider = collect(swagger, ((ArrayModel) model).getItems(), clean);
        return new ListDataProvider(itemProvider, schema.getSimpleRef());
    } else if (model instanceof ModelImpl) {
        Map<String, DataProvider> fields =
            (model.getProperties() != null ? model.getProperties() : Collections.<String, Property>emptyMap()).entrySet().stream()
                .map(e -> entry(e.getKey(), collect(swagger, e.getValue(), clean)))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

        return new ObjectDataProvider(fields, schema.getSimpleRef());
    }

    throw new IllegalArgumentException("Unsupported model type: " + model.getClass());
}
 
Example #14
Source File: DocumentationDrivenValidator.java    From assertj-swagger with Apache License 2.0 6 votes vote down vote up
private void validateModel(Model actualDefinition, Model expectedDefinition, String message) {
    if (isAssertionEnabled(SwaggerAssertionType.MODELS)) {
        if (expectedDefinition instanceof ModelImpl) {
            // TODO Validate ModelImpl
            softAssertions.assertThat(actualDefinition).as(message).isExactlyInstanceOf(ModelImpl.class);
        } else if (expectedDefinition instanceof RefModel) {
            // TODO Validate RefModel
            softAssertions.assertThat(actualDefinition).as(message).isExactlyInstanceOf(RefModel.class);
        } else if (expectedDefinition instanceof ArrayModel) {
            ArrayModel arrayModel = (ArrayModel) expectedDefinition;
            // TODO Validate ArrayModel
            softAssertions.assertThat(actualDefinition).as(message).isExactlyInstanceOf(ArrayModel.class);
        } else if (expectedDefinition instanceof ComposedModel) {
            ComposedModel composedModel = (ComposedModel) expectedDefinition;
            softAssertions.assertThat(actualDefinition).as(message).isInstanceOfAny(ComposedModel.class, ModelImpl.class);
        } else {
            // TODO Validate all model types
            softAssertions.assertThat(actualDefinition).isExactlyInstanceOf(expectedDefinition.getClass());
        }
    }
}
 
Example #15
Source File: DefaultCodegen.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
/**
 * Determine all of the types in the model definitions that are aliases of
 * simple types.
 * @param allDefinitions The complete set of model definitions.
 * @return A mapping from model name to type alias
 */
private static Map<String, String> getAllAliases(Map<String, Model> allDefinitions) {
    Map<String, String> aliases = new HashMap<>();
    if (allDefinitions != null) {
        for (Map.Entry<String, Model> entry : allDefinitions.entrySet()) {
            String swaggerName = entry.getKey();
            Model m = entry.getValue();
            if (m instanceof ModelImpl) {
                ModelImpl impl = (ModelImpl) m;
                if (impl.getType() != null &&
                        !impl.getType().equals("object") &&
                        impl.getEnum() == null) {
                    aliases.put(swaggerName, impl.getType());
                }
            }
        }
    }
    return aliases;
}
 
Example #16
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 #17
Source File: BodyProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public ParamValueProcessor create(Parameter parameter, Type genericParamType) {
  Model model = ((BodyParameter) parameter).getSchema();
  JavaType swaggerType = null;
  if (model instanceof ModelImpl) {
    swaggerType = ConverterMgr.findJavaType(((ModelImpl) model).getType(), ((ModelImpl) model).getFormat());
  }
  boolean isString = swaggerType != null && swaggerType.getRawClass().equals(String.class);

  JavaType targetType =
      genericParamType == null ? null : TypeFactory.defaultInstance().constructType(genericParamType);
  boolean rawJson = SwaggerUtils.isRawJsonType(parameter);
  if (rawJson) {
    return new RawJsonBodyProcessor(targetType, (String) parameter.getVendorExtensions()
        .get(SwaggerConst.EXT_JSON_VIEW), isString, parameter.getRequired());
  }

  return new BodyProcessor(targetType, (String) parameter.getVendorExtensions()
      .get(SwaggerConst.EXT_JSON_VIEW), isString, parameter.getRequired());
}
 
Example #18
Source File: ConsumerDrivenValidator.java    From assertj-swagger with Apache License 2.0 6 votes vote down vote up
private void validateModel(Model actualDefinition, Model expectedDefinition, String message) {
    if (isAssertionEnabled(SwaggerAssertionType.MODELS)) {
        if (expectedDefinition instanceof ModelImpl) {
            // TODO Validate ModelImpl
            softAssertions.assertThat(actualDefinition).as(message).isExactlyInstanceOf(ModelImpl.class);
        } else if (expectedDefinition instanceof RefModel) {
            // TODO Validate RefModel
            softAssertions.assertThat(actualDefinition).as(message).isExactlyInstanceOf(RefModel.class);
        } else if (expectedDefinition instanceof ArrayModel) {
            ArrayModel arrayModel = (ArrayModel) expectedDefinition;
            // TODO Validate ArrayModel
            softAssertions.assertThat(actualDefinition).as(message).isExactlyInstanceOf(ArrayModel.class);
        } else {
            // TODO Validate all model types
            softAssertions.assertThat(actualDefinition).isExactlyInstanceOf(expectedDefinition.getClass());
        }
    }
}
 
Example #19
Source File: RestOperationMeta.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #20
Source File: DocumentationDrivenValidator.java    From assertj-swagger with Apache License 2.0 6 votes vote down vote up
private void validateDefinition(String definitionName, Model actualDefinition, Model expectedDefinition) {
    if (expectedDefinition != null && actualDefinition != null) {
        validateModel(actualDefinition, expectedDefinition, String.format("Checking model of definition '%s", definitionName));
        validateDefinitionProperties(schemaObjectResolver.resolvePropertiesFromActual(actualDefinition),
                                     schemaObjectResolver.resolvePropertiesFromExpected(expectedDefinition),
                                     definitionName);

        if (expectedDefinition instanceof ModelImpl && actualDefinition instanceof ModelImpl) {
            validateTypeDefinition(actualDefinition, expectedDefinition);
            validateDefinitionEnum(actualDefinition, expectedDefinition);
            validateDefinitionRequiredProperties(((ModelImpl) actualDefinition).getRequired(),
                                                 ((ModelImpl) expectedDefinition).getRequired(),
                                                   definitionName);
        }
    }
}
 
Example #21
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
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 #22
Source File: ModelResolverExt.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public Model resolve(JavaType type, ModelConverterContext context, Iterator<ModelConverter> next) {
  // property is not a model
  if (propertyCreatorMap.containsKey(type.getRawClass())) {
    return null;
  }

  Model model = super.resolve(type, context, next);
  if (model == null) {
    return null;
  }

  checkType(type);

  // 只有声明model的地方才需要标注类型
  if (model instanceof ModelImpl && !StringUtils.isEmpty(((ModelImpl) model).getName())) {
    setType(type, model.getVendorExtensions());
  }
  return model;
}
 
Example #23
Source File: AbstractOperationGenerator.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
protected void fillBodyParameter(Swagger swagger, Parameter parameter, Type type, List<Annotation> annotations) {
  // so strange, for bodyParameter, swagger return a new instance
  // that will cause lost some information
  // so we must merge them
  BodyParameter newBodyParameter = (BodyParameter) io.swagger.util.ParameterProcessor.applyAnnotations(
      swagger, parameter, type, annotations);

  // swagger missed enum data, fix it
  ModelImpl model = SwaggerUtils.getModelImpl(swagger, newBodyParameter);
  if (model != null) {
    Property property = ModelConverters.getInstance().readAsProperty(type);
    if (property instanceof StringProperty) {
      model.setEnum(((StringProperty) property).getEnum());
    }
  }

  mergeBodyParameter((BodyParameter) parameter, newBodyParameter);
}
 
Example #24
Source File: ModelImplConverter.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public JavaType doConvert(Swagger swagger, Object model) {
  ModelImpl modelImpl = (ModelImpl) model;

  JavaType javaType = ConverterMgr.findJavaType(modelImpl.getType(), modelImpl.getFormat());
  if (javaType != null) {
    return javaType;
  }

  if (modelImpl.getReference() != null) {
    return convertRef(swagger, modelImpl.getReference());
  }

  if (modelImpl.getAdditionalProperties() != null) {
    return MapPropertyConverter.findJavaType(swagger, modelImpl.getAdditionalProperties());
  }

  return OBJECT_JAVA_TYPE;
}
 
Example #25
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 #26
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 #27
Source File: BodyParameterAdapter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormat() {
  if (model instanceof ModelImpl) {
    return ((ModelImpl) model).getFormat();
  }

  return null;
}
 
Example #28
Source File: ModelAdapter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public Property getMapItem() {
  if (model instanceof ModelImpl) {
    return ((ModelImpl) model).getAdditionalProperties();
  }

  return null;
}
 
Example #29
Source File: AbstractOktaJavaClientCodegen.java    From okta-sdk-java with Apache License 2.0 5 votes vote down vote up
protected void tagEnums(Swagger swagger) {
    swagger.getDefinitions().forEach((name, model) -> {

        if (model instanceof ModelImpl && ((ModelImpl) model).getEnum() != null) {
            enumList.add(name);
        }
    });
}
 
Example #30
Source File: BodyParameterAdapter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getEnum() {
  if (model instanceof ModelImpl) {
    return ((ModelImpl) model).getEnum();
  }

  return Collections.emptyList();
}