io.swagger.models.properties.RefProperty Java Examples

The following examples show how to use io.swagger.models.properties.RefProperty. 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: SwaggerGeneratorTestIt.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@org.junit.Test
public void testGenerateGroupingsModuleUnpacking() {
    //when
    swaggerFor(p -> p.getFileName().toString().equals("with-groupings.yang"),
            g -> g.strategy(SwaggerGenerator.Strategy.unpacking));

    //then
    assertEquals(3, swagger.getPaths().entrySet().stream().filter(e -> e.getKey().contains("g2-c-c1")).count());
    assertEquals(8, swagger.getDefinitions().keySet().size());
    assertThat(swagger.getDefinitions().keySet(), not(hasItems("G1", "G2", "G3")));

    Model model = swagger.getDefinitions().get("with.groupings.GroupingRoot");
    RefProperty groupingChild2 = (RefProperty) model.getProperties().get("grouping-child2");
    assertEquals("with.groupings.groupingroot.GroupingChild2", groupingChild2.getSimpleRef());

}
 
Example #2
Source File: Reader.java    From dorado with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void addResponse(Operation operation, ApiResponse apiResponse, JsonView jsonView) {
	Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders(), jsonView);
	Map<String, Object> examples = parseExamples(apiResponse.examples());

	Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
	response.setExamples(examples);

	if (apiResponse.code() == 0) {
		operation.defaultResponse(response);
	} else {
		operation.response(apiResponse.code(), response);
	}

	if (StringUtils.isNotEmpty(apiResponse.reference())) {
		response.schema(new RefProperty(apiResponse.reference()));
	} else if (!isVoid(apiResponse.response())) {
		Type responseType = apiResponse.response();
		final Property property = ModelConverters.getInstance().readAsProperty(responseType, jsonView);
		if (property != null) {
			response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
			appendModels(responseType);
		}
	}
}
 
Example #3
Source File: ApiGatewaySdkSwaggerApiImporter.java    From aws-apigateway-importer with Apache License 2.0 6 votes vote down vote up
private Optional<Model> getModel(RestApi api, Response response) {

        String modelName;

        // if the response references a proper model, look for a model matching the model name
        if (response.getSchema() != null && response.getSchema().getType().equals("ref")) {
            modelName = ((RefProperty) response.getSchema()).getSimpleRef();
        } else {
            // if the response has an embedded schema, look for a model matching the generated name
            modelName = generateModelName(response);
        }

        try {
            Model model = api.getModelByName(modelName);
            if (model.getName() != null) {
                return Optional.of(model);
            }
        } catch (Exception ignored) {}

        return Optional.empty();
    }
 
Example #4
Source File: RestControllerProcessor.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the return value of a RequestMapping annotated method.
 *
 * @param returnType the return type.
 * @param operation the operation.
 * @param returnDescription the description of the return value.
 *
 * @throws MojoExecutionException if the return type isn't an XmlType.
 */
private void processRestMethodReturnValue(Class<?> returnType, Operation operation, String returnDescription) throws MojoExecutionException
{
    log.debug("Processing REST method return value \"" + returnType.getName() + "\".");

    // Add the class name to the list of classes which we will create an example for.
    exampleClassNames.add(returnType.getSimpleName());

    // Add the success response
    operation.response(200, new Response().description(returnDescription == null ? "Success" : returnDescription)
        .schema(new RefProperty(getXmlType(returnType).name().trim())));

    // If we have an error class, add that as the default response.
    if (modelErrorClass != null)
    {
        operation.defaultResponse(new Response().description("General Error").schema(new RefProperty(getXmlType(modelErrorClass).name().trim())));
    }
}
 
Example #5
Source File: SwaggerToWordExample.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
private Object valueOfProperty(Map<String, Model> definitions, Property prop, Set<String> keyCache) {
    Object value;
    if (prop instanceof RefProperty) {
        String ref = ((RefProperty) prop).get$ref().substring("#/definitions/".length());
        if (keyCache.contains(ref)) value = ((RefProperty) prop).get$ref();
        else value = valueOfModel(definitions, definitions.get(ref), keyCache);
    } else if (prop instanceof ArrayProperty) {
        List<Object> list = new ArrayList<>();
        Property insideItems = ((ArrayProperty) prop).getItems();
        list.add(valueOfProperty(definitions, insideItems, keyCache));
        value = list;
    } else if (prop instanceof AbstractNumericProperty) {
        value = 0;
    } else if (prop instanceof BooleanProperty) {
        value = false;
    } else {
        value = prop.getType();
    }
    return value;
}
 
Example #6
Source File: SwaggerToWordExample.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
private List<TextRenderData> formatProperty(Property items) {
    List<TextRenderData> schema = new ArrayList<>();
    if (null != items) {
        if (items instanceof RefProperty) {
            String ref = ((RefProperty) items).get$ref().substring("#/definitions/".length());
            schema.add(new HyperLinkTextRenderData(ref, "anchor:" + ref));
        } else if (items instanceof ArrayProperty) {
            Property insideItems = ((ArrayProperty) items).getItems();
            schema.add(new TextRenderData("<"));
            schema.addAll(formatProperty(insideItems));
            schema.add(new TextRenderData(">"));
            schema.add(new TextRenderData(items.getType()));
        } else {
            schema.add(new TextRenderData(items.getType()));
        }
    }
    return schema;
}
 
Example #7
Source File: OAS2Parser.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a json string using the swagger object.
 *
 * @param swaggerObj swagger object
 * @return json string using the swagger object
 * @throws APIManagementException error while creating swagger json
 */
private String getSwaggerJsonString(Swagger swaggerObj) throws APIManagementException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    //this is to ignore "originalRef" in schema objects
    mapper.addMixIn(RefModel.class, IgnoreOriginalRefMixin.class);
    mapper.addMixIn(RefProperty.class, IgnoreOriginalRefMixin.class);
    mapper.addMixIn(RefPath.class, IgnoreOriginalRefMixin.class);
    mapper.addMixIn(RefParameter.class, IgnoreOriginalRefMixin.class);
    mapper.addMixIn(RefResponse.class, IgnoreOriginalRefMixin.class);

    //this is to ignore "responseSchema" in response schema objects
    mapper.addMixIn(Response.class, ResponseSchemaMixin.class);
    try {
        return new String(mapper.writeValueAsBytes(swaggerObj));
    } catch (JsonProcessingException e) {
        throw new APIManagementException("Error while generating Swagger json from model", e);
    }
}
 
Example #8
Source File: OASParserUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a json string using the swagger object.
 *
 * @param swaggerObj swagger object
 * @return json string using the swagger object
 * @throws APIManagementException error while creating swagger json
 */
public static String getSwaggerJsonString(Swagger swaggerObj) throws APIManagementException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    //this is to ignore "originalRef" in schema objects
    mapper.addMixIn(RefModel.class, IgnoreOriginalRefMixin.class);
    mapper.addMixIn(RefProperty.class, IgnoreOriginalRefMixin.class);
    mapper.addMixIn(RefPath.class, IgnoreOriginalRefMixin.class);
    mapper.addMixIn(RefParameter.class, IgnoreOriginalRefMixin.class);
    mapper.addMixIn(RefResponse.class, IgnoreOriginalRefMixin.class);

    //this is to ignore "responseSchema" in response schema objects
    mapper.addMixIn(Response.class, ResponseSchemaMixin.class);
    try {
        return new String(mapper.writeValueAsBytes(swaggerObj));
    } catch (JsonProcessingException e) {
        throw new APIManagementException("Error while generating Swagger json from model", e);
    }
}
 
Example #9
Source File: OperationsTransformer.java    From spring-openapi with MIT License 6 votes vote down vote up
private io.swagger.models.parameters.Parameter createNswagRequestBody(ParameterNamePair requestBodyParameter, Property property) {
	CustomBodyParameter requestBody = new CustomBodyParameter();

	if (property instanceof RefProperty) {
		CustomSchema customSchema = new CustomSchema();
		customSchema.setRef(((RefProperty) property).get$ref());
		requestBody.setSchema(customSchema);
	} else if (property instanceof ArrayProperty) {
		requestBody.setType("array");
		requestBody.setItems(((ArrayProperty) property).getItems());
	}

	requestBody.setRequired(true);
	requestBody.setName(resolveRequestBodyName(property, requestBodyParameter.getName()));
	requestBody.setDescription(requestBody.getName());

	return requestBody;
}
 
Example #10
Source File: ExtendedSwaggerReader.java    From msf4j with Apache License 2.0 6 votes vote down vote up
private void addResponse(Operation operation, ApiResponse apiResponse) {
    Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders());

    Response response = new Response().description(apiResponse.message()).headers(responseHeaders);

    if (apiResponse.code() == 0) {
        operation.defaultResponse(response);
    } else {
        operation.response(apiResponse.code(), response);
    }

    if (StringUtils.isNotEmpty(apiResponse.reference())) {
        response.schema(new RefProperty(apiResponse.reference()));
    } else if (!isVoid(apiResponse.response())) {
        Type responseType = apiResponse.response();
        final Property property = ModelConverters.getInstance().readAsProperty(responseType);
        if (property != null) {
            response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
            appendModels(responseType);
        }
    }
}
 
Example #11
Source File: Reader.java    From proteus with Apache License 2.0 6 votes vote down vote up
private void addResponse(Operation operation, ApiResponse apiResponse) {
    Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders());

    Response response = new Response().description(apiResponse.message()).headers(responseHeaders);

    if (apiResponse.code() == 0) {
        operation.defaultResponse(response);
    } else {
        operation.response(apiResponse.code(), response);
    }

    if (StringUtils.isNotEmpty(apiResponse.reference())) {
        response.schema(new RefProperty(apiResponse.reference()));
    } else if (!isVoid(apiResponse.response())) {
        Type responseType = apiResponse.response();
        final Property property = ModelConverters.getInstance().readAsProperty(responseType);
        if (property != null) {
            response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
            appendModels(responseType);
        }
    }
}
 
Example #12
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param refProperty
 * @param models
 * @param modelObject
 * @param variablName
 * @return
 */
private ClassMembers getClassMember(RefProperty refProperty, Map<String, Model> models, Model modelObject,
		String variablName) {
	LOGGER.entering(LOGGER.getName(), "getClassMember-RefProperty");

	ClassMembers classMemberObject = new ClassMembers();
	classMemberObject.setDataType(getDataType(refProperty.getSimpleRef(), true));
	classMemberObject.setName(variablName);

	if (models.containsKey(refProperty.getSimpleRef())) {
		classMemberObject.setClassName(refProperty.getSimpleRef());
	}

	if (includeCardinality && StringUtils.isNotEmpty(variablName) && modelObject != null) {
		if (isRequiredProperty(modelObject, variablName)) {
			classMemberObject.setCardinality(CARDINALITY_ONE_TO_MANY);
		} else {
			classMemberObject.setCardinality(CARDINALITY_NONE_TO_MANY);
		}
	}

	LOGGER.exiting(LOGGER.getName(), "getClassMember-RefProperty");
	return classMemberObject;
}
 
Example #13
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param operation
 * @return
 */
private String getErrorClassName(Operation operation) {
	StringBuilder errorClass = new StringBuilder();
	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) {
				String errorClassName = ((RefProperty) responseProperty).getSimpleRef();
				if (!errorClass.toString().contains(errorClassName)) {
					if (StringUtils.isNotEmpty(errorClass)) {
						errorClass.append(",");
					}
					errorClass.append(errorClassName);
				}
			}
		}
	}

	return errorClass.toString();
}
 
Example #14
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param modelObject
 * @param models
 * @param variablName
 * @param classMemberObject
 * @param propObject
 */
private ClassMembers getClassMember(ArrayProperty property, Model modelObject, Map<String, Model> models,
		String variablName) {
	LOGGER.entering(LOGGER.getName(), "getClassMember-ArrayProperty");

	ClassMembers classMemberObject = new ClassMembers();
	Property propObject = property.getItems();

	if (propObject instanceof RefProperty) {
		classMemberObject = getClassMember((RefProperty) propObject, models, modelObject, variablName);
	} else if (propObject instanceof StringProperty) {
		classMemberObject = getClassMember((StringProperty) propObject, variablName);
	}

	LOGGER.exiting(LOGGER.getName(), "getClassMember-ArrayProperty");
	return classMemberObject;
}
 
Example #15
Source File: SwaggerGeneratorWithOdlPathHandlerTest.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@org.junit.Test
  public void testInheritenceWithAugmentation() throws Exception {
      SchemaContext ctx = ContextHelper.getFromClasspath(p -> p.getParent().getFileName().toString().equals("inheritence-with-augmentation"));

SwaggerGenerator generator = new SwaggerGenerator(ctx, ctx.getModules()).defaultConfig()
		.pathHandler(new ODLPathHandlerBuilder());
      swagger = generator.generate();

      ComposedModel base = (ComposedModel) swagger.getDefinitions().get("base.Base");
      assertEquals(1, base.getInterfaces().size());
      assertEquals("base.Ident", base.getInterfaces().get(0).getSimpleRef());
      RefProperty managersRef = (RefProperty) ((ArrayProperty) base.getChild().getProperties().get("managers")).getItems();
      RefProperty usersRef = (RefProperty) ((ArrayProperty) base.getChild().getProperties().get("users")).getItems();


      ComposedModel managers = (ComposedModel) swagger.getDefinitions().get(managersRef.getSimpleRef());
      ComposedModel users = (ComposedModel) swagger.getDefinitions().get(usersRef.getSimpleRef());
      assertEquals(2, managers.getAllOf().size());
      assertEquals(2, managers.getInterfaces().size());
      //users are augmented
      assertEquals(3, users.getAllOf().size());
      assertEquals(2, users.getInterfaces().size());
  }
 
Example #16
Source File: SwaggerGeneratorWithOdlPathHandlerTest.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@org.junit.Test
  public void testAugGroupEx() throws Exception {
      SchemaContext ctx = ContextHelper.getFromClasspath(p -> p.getParent().getFileName().toString().equals("aug-group-ex"));

SwaggerGenerator generator = new SwaggerGenerator(ctx, ctx.getModules()).defaultConfig()
		.pathHandler(new ODLPathHandlerBuilder());
      swagger = generator.generate();

      Model base = swagger.getDefinitions().get("base.Base");
      RefProperty c1 = (RefProperty) base.getProperties().get("c1");
      RefProperty c2 = (RefProperty) base.getProperties().get("c2");


      assertEquals("base.Coll",c1.getSimpleRef());
      assertEquals("base.base.C2",c2.getSimpleRef());
  }
 
Example #17
Source File: SwaggerGeneratorAugmentationsTestIt.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@org.junit.Test
public void testInheritenceWithAugmentation() {
    swaggerFor(p -> p.getParent().getFileName().toString().equals("inheritence-with-augmentation"));


    ComposedModel base = (ComposedModel) swagger.getDefinitions().get("base.Base");
    assertEquals(1, base.getInterfaces().size());
    assertEquals("base.Ident", base.getInterfaces().get(0).getSimpleRef());
    RefProperty managersRef = (RefProperty) ((ArrayProperty) base.getChild().getProperties().get("managers")).getItems();
    RefProperty usersRef = (RefProperty) ((ArrayProperty) base.getChild().getProperties().get("users")).getItems();


    ComposedModel managers = (ComposedModel) swagger.getDefinitions().get(managersRef.getSimpleRef());
    ComposedModel users = (ComposedModel) swagger.getDefinitions().get(usersRef.getSimpleRef());
    assertEquals(2, managers.getAllOf().size());
    assertEquals(2, managers.getInterfaces().size());
    //users are augmented
    assertEquals(3, users.getAllOf().size());
    assertEquals(2, users.getInterfaces().size());
}
 
Example #18
Source File: PatchOperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Operation execute(DataSchemaNode node) {
    final Operation patch = defaultOperation();
    final RefModel definition = new RefModel(getDefinitionId(node));
    patch.summary("patches " + getName(node));
    String description = node.getDescription() == null ? "patches " + getName(node) :
            node.getDescription();
    patch.description(description);
    patch.parameter(new BodyParameter()
            .name(getName(node) + ".body-param")
            .schema(definition)
            .description(getName(node) + " to be added or updated"));

    patch.response(200, new Response()
            .schema(new RefProperty(getDefinitionId(node)))
            .description(getName(node)));
    patch.response(204, new Response().description("Operation successful"));
    return patch;
}
 
Example #19
Source File: SwaggerRefHelper.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
public static String getFromBody(Operation oper) {
    Optional<Parameter> bodyParam =
            oper.getParameters().stream().filter(p -> p instanceof BodyParameter).findFirst();
    if(bodyParam.isPresent()) {
        Model schema = ((BodyParameter) bodyParam.get()).getSchema();
        if(schema instanceof RefModel) {
            return ((RefModel) schema).getSimpleRef();
        }
        if(schema instanceof ModelImpl) {
            Property input = schema.getProperties().get("input");
            if(input instanceof RefProperty)
                return ((RefProperty) input).getSimpleRef();
        }
    }

    return null;
}
 
Example #20
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 #21
Source File: JerseyServerCodegen.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getSwaggerType(Property p) {

    if (p instanceof RefProperty) {
        String datatype;
        try {
            RefProperty r = (RefProperty) p;
            datatype = r.get$ref();
            if (datatype.indexOf("#/definitions/") == 0) {
                datatype = datatype.substring("#/definitions/".length());
            }
        } catch (Exception e) {
            log.warn("Error obtaining the datatype from RefProperty:" + p + ". Datatype default to Object");
            datatype = "Object";
            log.error(e.getMessage(), e);
        }
        return datatype;

    }

    return super.getSwaggerType(p);
}
 
Example #22
Source File: PayloadWrapperProcessor.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
private void processOperation(Operation operation, String propertyName) {
    if(operation == null) {
        return;
    }

    operation.getResponses().values().stream()
            .filter(r -> r.getSchema() instanceof RefProperty)
            .forEach(r -> wrap(propertyName, r));

    operation.getParameters().stream()
            .filter(p -> p instanceof BodyParameter)
            .map(p -> (BodyParameter) p)
            .filter(p -> p.getSchema() instanceof RefModel)
            .forEach(param -> wrap(propertyName, param));


}
 
Example #23
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 #24
Source File: WSDL11SOAPOperationExtractor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private Property getPropertyFromDataType(String dataType) {

        switch (dataType) {
        case "string":
            return new StringProperty();
        case "boolean":
            return new BooleanProperty();
        case "int":
            return new IntegerProperty();
        case "nonNegativeInteger":
            return new IntegerProperty();
        case "integer":
            return new IntegerProperty();
        case "positiveInteger":
            return new IntegerProperty();
        case "double":
            return new DoubleProperty();
        case "float":
            return new FloatProperty();
        case "long":
            return new LongProperty();
        case "date":
            return new DateProperty();
        case "dateTime":
            return new DateTimeProperty();
        default:
            return new RefProperty();
        }
    }
 
Example #25
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a default example value for property.
 *
 * @param property         property
 * @param markupDocBuilder doc builder
 * @return a generated example for the property
 */
public static Object generateExample(Property property, MarkupDocBuilder markupDocBuilder) {

    if (property.getType() == null) {
        return "untyped";
    }

    switch (property.getType()) {
        case "integer":
            return ExamplesUtil.generateIntegerExample(property instanceof IntegerProperty ? ((IntegerProperty) property).getEnum() : null);
        case "number":
            return 0.0;
        case "boolean":
            return true;
        case "string":
            return ExamplesUtil.generateStringExample(property.getFormat(), property instanceof StringProperty ? ((StringProperty) property).getEnum() : null);
        case "ref":
            if (property instanceof RefProperty) {
                if (logger.isDebugEnabled()) logger.debug("generateExample RefProperty for " + property.getName());
                return markupDocBuilder.copy(false).crossReference(((RefProperty) property).getSimpleRef()).toString();
            } else {
                if (logger.isDebugEnabled()) logger.debug("generateExample for ref not RefProperty");
            }
        case "array":
            if (property instanceof ArrayProperty) {
                return generateArrayExample((ArrayProperty) property, markupDocBuilder);
            }
        default:
            return property.getType();
    }
}
 
Example #26
Source File: ModelDiff.java    From swagger-diff with Apache License 2.0 5 votes vote down vote up
private Model findModel(Property property, Map<String, Model> modelMap) {
    String modelName = null;
    if (property instanceof RefProperty) {
        modelName = ((RefProperty) property).getSimpleRef();
    } else if (property instanceof ArrayProperty) {
        Property arrayType = ((ArrayProperty) property).getItems();
        if (arrayType instanceof RefProperty) {
            modelName = ((RefProperty) arrayType).getSimpleRef();
        }
    }
    return modelName == null ? null : modelMap.get(modelName);
}
 
Example #27
Source File: SwaggerGeneratorAugmentationsTestIt.java    From yang2swagger with Eclipse Public License 1.0 5 votes vote down vote up
@org.junit.Test
public void testAugGroupEx() {
    swaggerFor(p -> p.getParent().getFileName().toString().equals("aug-group-ex"));

    Model base = swagger.getDefinitions().get("base.Base");
    RefProperty c1 = (RefProperty) base.getProperties().get("c1");
    RefProperty c2 = (RefProperty) base.getProperties().get("c2");


    assertEquals("base.Coll",c1.getSimpleRef());
    assertEquals("base.base.C2",c2.getSimpleRef());
}
 
Example #28
Source File: ModelDiff.java    From swagger-diff with Apache License 2.0 5 votes vote down vote up
private Model findReferenceModel(Model model, Map<String, Model> modelMap) {
    String modelName = null;
    if (model instanceof RefModel) {
        modelName = ((RefModel) model).getSimpleRef();
    } else if (model instanceof ArrayModel) {
        Property arrayType = ((ArrayModel) model).getItems();
        if (arrayType instanceof RefProperty) {
            modelName = ((RefProperty) arrayType).getSimpleRef();
        }
    }
    return modelName == null ? null : modelMap.get(modelName);
}
 
Example #29
Source File: JaxRs2Extension.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Property enforcePrimitive(final Property in, final int level) {
    if (in instanceof RefProperty) {
        return new StringProperty();
    }
    if (in instanceof ArrayProperty) {
        if (level == 0) {
            final ArrayProperty array = (ArrayProperty) in;
            array.setItems(enforcePrimitive(array.getItems(), level + 1));
        } else {
            return new StringProperty();
        }
    }
    return in;
}
 
Example #30
Source File: ComponentSchemaTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
@Override
protected Property createRefProperty(Class<?> typeSignature, GenerationContext generationContext) {
	RefProperty schema = new RefProperty();
	if (isInPackagesToBeScanned(typeSignature, generationContext)) {
		schema.set$ref(CommonConstants.COMPONENT_REF_PREFIX + typeSignature.getSimpleName());
		return schema;
	}
	UntypedProperty fallBack = new UntypedProperty();
	fallBack.setType("object");
	return fallBack;
}