schema = new Schema().$ref(node.get("$ref").asText()); } else { // assume object schema = deserializeObjectSchema(node);
@Test(description = "it should serialize a RefProperty") public void serializeRefProperty() throws IOException { final Schema p = new Schema().$ref("#/definitions/Dog"); final String json = "{\"$ref\":\"#/definitions/Dog\"}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize an array model") public void serializeArrayModel() throws IOException { final ArraySchema model = new ArraySchema(); model.setItems(new Schema().$ref("Pet")); assertEquals(m.writeValueAsString(model), "{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}"); }
sp = (SerializableParameter) globalV2Parameters.get(simpleRef); name = components.getSchemas().get("formData_" + simpleRef).getName(); schema = new Schema().$ref("#/components/schemas/formData_" + simpleRef); } else { sp = (SerializableParameter) param;
public static Schema getSchema(ProtoType protoType,RefHelper refHelper) { Schema schema = DEFAULT_TYPE_SCHEMA.get(protoType.toString()); if(Objects.isNull(schema)){ schema = new Schema().$ref(refHelper.getRefer(protoType)); } Schema result = new Schema(); BeanUtils.copyProperties(schema, result); return result; }
public Schema getSchemaByType(ProtoType protoType) { if (protoType.isScalar()) { return SchemaUtil.getSchema(protoType, this); } else if (protoType.isMap()) { return new Schema().additionalProperties(getSchemaByType(protoType.valueType())).type("object"); } else { return new Schema().$ref(getRefer(protoType)); } } }
/** * Make a RefProperty * * @param ref new property name * @param property Property * @return */ public Schema makeRefProperty(String ref, Schema property) { Schema newProperty = new Schema().$ref(ref); this.copyVendorExtensions(property, newProperty); return newProperty; }
/** * Make a Schema * * @param ref new property name * @param property Schema * @return {@link Schema} A constructed OpenAPI property */ public Schema makeSchema(String ref, Schema property) { Schema newProperty = new Schema().$ref(ref); this.copyVendorExtensions(property, newProperty); return newProperty; }
/** * Make a RefProperty * * @param ref new property name * @param property Property * @return */ public Schema makeRefProperty(String ref, Schema property) { Schema newProperty = new Schema().$ref(ref); this.copyVendorExtensions(property, newProperty); return newProperty; }
/** * Make a RefProperty * * @param ref new property name * @param property Property * @return */ public Schema makeRefProperty(String ref, Schema property) { Schema newProperty = new Schema().$ref(ref); this.copyVendorExtensions(property, newProperty); return newProperty; }
private static Schema process(Schema id, String propertyName, AnnotatedType type, ModelConverterContext context) { Schema model = context.resolve(removeJsonIdentityAnnotations(type)); Schema mi = model; mi.addProperties(propertyName, id); return new Schema().$ref(StringUtils.isNotEmpty(mi.get$ref()) ? mi.get$ref() : mi.getName()); } private static AnnotatedType removeJsonIdentityAnnotations(AnnotatedType type) {
StringUtils.isNotEmpty(resolvedSchemaAnnotation.ref())) { if (resolvedArrayAnnotation == null) { return new Schema().$ref(resolvedSchemaAnnotation.ref()).name(name); } else { ArraySchema schema = new ArraySchema(); resolveArraySchema(annotatedType, schema, resolvedArrayAnnotation); return schema.items(new Schema().$ref(resolvedSchemaAnnotation.ref()).name(name)); innerSchema = new Schema().$ref(constructRef(innerSchema.getName())); innerSchema = new Schema().$ref(StringUtils.isNotEmpty(innerSchema.get$ref()) ? innerSchema.get$ref() : innerSchema.getName()); implSchema = new Schema().$ref(constructRef(implSchema.getName())); implSchema = new Schema().$ref(StringUtils.isNotEmpty(implSchema.get$ref()) ? implSchema.get$ref() : implSchema.getName()); addPropertiesSchema = new Schema().$ref(constructRef(pName)); addPropertiesSchema = new Schema().$ref(StringUtils.isNotEmpty(addPropertiesSchema.get$ref()) ? addPropertiesSchema.get$ref() : addPropertiesSchema.getName()); items = new Schema().$ref(constructRef(pName)); items = new Schema().$ref(StringUtils.isNotEmpty(items.get$ref()) ? items.get$ref() : items.getName()); property = new Schema().$ref(constructRef(pName)); property = new Schema().$ref(StringUtils.isNotEmpty(property.get$ref()) ? property.get$ref() : property.getName()); model.$ref(ref);
composedSchema = (ComposedSchema) subtypeModel; Schema refSchema = new Schema().$ref(model.getName());
@Test(description = "it should not create an xml object for $ref") public void shouldNotCreateXmlObjectForRef() throws IOException { final Schema model = new Schema().$ref("Monster"); model.setDescription("oops"); model.setExternalDocs(new ExternalDocumentation() .description("external docs") .url("http://swagger.io")); assertEquals(Json.mapper().writeValueAsString(model), "{\"$ref\":\"#/components/schemas/Monster\"}"); }
@Test(description = "it should serialize an array BodyParameter") public void serializeArrayBodyParameter() { final Schema model = new ArraySchema().items(new Schema().$ref("#/definitions/Cat")); final RequestBody p = new RequestBody() .content(new Content().addMediaType("*/*", new MediaType().schema(model))); final String json = "{\"content\":{\"*/*\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Cat\"}}}}}"; SerializationMatchers.assertEqualsToJson(p, json); }
@Test(description = "it should serialize a ref BodyParameter") public void serializeRefBodyParameter() { final Schema model = new Schema().$ref("#/definitions/Cat"); final RequestBody p = new RequestBody() .content(new Content().addMediaType("*/*", new MediaType().schema(model))); final String json = "{\"content\":{\"*/*\":{\"schema\":{\"$ref\":\"#/definitions/Cat\"}}}}"; SerializationMatchers.assertEqualsToJson(p, json); }
private static Schema process(Schema id, String propertyName, AnnotatedType type, ModelConverterContext context) { Schema model = context.resolve(removeJsonIdentityAnnotations(type)); Schema mi = model; mi.addProperties(propertyName, id); return new Schema().$ref(StringUtils.isNotEmpty(mi.get$ref()) ? mi.get$ref() : mi.getName()); } private static AnnotatedType removeJsonIdentityAnnotations(AnnotatedType type) {