io.swagger.v3.oas.models.media.ObjectSchema Java Examples
The following examples show how to use
io.swagger.v3.oas.models.media.ObjectSchema.
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: CollectionModelContentConverter.java From springdoc-openapi with Apache License 2.0 | 7 votes |
@Override public Schema<?> resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) { if (chain.hasNext() && type != null && type.getType() instanceof CollectionType && "_embedded".equalsIgnoreCase(type.getPropertyName())) { Schema<?> schema = chain.next().resolve(type, context, chain); if (schema instanceof ArraySchema) { Class<?> entityType = getEntityType(type); String entityClassName = linkRelationProvider.getCollectionResourceRelFor(entityType).value(); return new ObjectSchema() .name("_embedded") .addProperties(entityClassName, schema); } } return chain.hasNext() ? chain.next().resolve(type, context, chain) : null; }
Example #2
Source File: ExtensionsUtilTest.java From swagger-inflector with Apache License 2.0 | 7 votes |
@Test public void resolveComposedAllOfReferenceSchema(@Injectable final List<AuthorizationValue> auths){ ParseOptions options = new ParseOptions(); options.setResolve(true); options.setResolveFully(true); OpenAPI openAPI = new OpenAPIV3Parser().readLocation("./src/test/swagger/oas3.yaml",auths,options).getOpenAPI(); ResolverFully resolverUtil = new ResolverFully(); resolverUtil.resolveFully(openAPI); assertTrue(openAPI.getPaths().get("/withInvalidComposedModelArray").getPost().getRequestBody().getContent().get("*/*").getSchema() instanceof ArraySchema); ArraySchema arraySchema = (ArraySchema) openAPI.getPaths().get("/withInvalidComposedModelArray").getPost().getRequestBody().getContent().get("*/*").getSchema(); assertTrue(arraySchema.getItems() instanceof ObjectSchema); }
Example #3
Source File: SerializerUtilsTest.java From openapi-generator with Apache License 2.0 | 7 votes |
private OpenAPI createCompleteExample() { OpenAPI openAPI = new OpenAPI(); openAPI.setInfo(new Info().title("Some title").description("Some description")); openAPI.setExternalDocs(new ExternalDocumentation().url("http://abcdef.com").description("a-description")); openAPI.setServers(Arrays.asList( new Server().url("http://www.server1.com").description("first server"), new Server().url("http://www.server2.com").description("second server") )); openAPI.setSecurity(Arrays.asList( new SecurityRequirement().addList("some_auth", Arrays.asList("write", "read")) )); openAPI.setTags(Arrays.asList( new Tag().name("tag1").description("some 1 description"), new Tag().name("tag2").description("some 2 description"), new Tag().name("tag3").description("some 3 description") )); openAPI.path("/ping/pong", new PathItem().get(new Operation() .description("Some description") .operationId("pingOp") .responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("Ok"))))); openAPI.components(new Components().addSchemas("SomeObject", new ObjectSchema().description("An Obj").addProperties("id", new StringSchema()))); openAPI.setExtensions(new LinkedHashMap<>()); // required because swagger-core is using HashMap instead of LinkedHashMap internally. openAPI.addExtension("x-custom", "value1"); openAPI.addExtension("x-other", "value2"); return openAPI; }
Example #4
Source File: InlineModelResolverTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testArbitraryObjectResponseMapInline() { OpenAPI openAPI = new OpenAPI(); Schema schema = new Schema(); schema.setAdditionalProperties(new ObjectSchema()); openAPI.path("/foo/baz", new PathItem() .get(new Operation() .responses(new ApiResponses().addApiResponse("200", new ApiResponse() .description("it works!") .content(new Content().addMediaType("*/*", new MediaType().schema(schema))))))); new InlineModelResolver().flatten(openAPI); ApiResponse response = openAPI.getPaths().get("/foo/baz").getGet().getResponses().get("200"); Schema property = response.getContent().get("*/*").getSchema(); assertTrue(property.getAdditionalProperties() != null); assertTrue(property.getAdditionalProperties() instanceof Schema); assertTrue(openAPI.getComponents().getSchemas() == null); Schema inlineProp = (Schema)property.getAdditionalProperties(); assertTrue(inlineProp instanceof ObjectSchema); ObjectSchema op = (ObjectSchema) inlineProp; assertNull(op.getProperties()); }
Example #5
Source File: GenericParameterBuilder.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Calculate request body schema schema. * * @param components the components * @param parameterInfo the parameter info * @param requestBodyInfo the request body info * @param schemaN the schema n * @param paramName the param name * @return the schema */ private Schema calculateRequestBodySchema(Components components, ParameterInfo parameterInfo, RequestBodyInfo requestBodyInfo, Schema schemaN, String paramName) { if (schemaN != null && StringUtils.isEmpty(schemaN.getDescription()) && parameterInfo.getParameterModel() != null) { String description = parameterInfo.getParameterModel().getDescription(); if (schemaN.get$ref() != null && schemaN.get$ref().contains(AnnotationsUtils.COMPONENTS_REF)) { String key = schemaN.get$ref().substring(21); Schema existingSchema = components.getSchemas().get(key); existingSchema.setDescription(description); } else schemaN.setDescription(description); } if (requestBodyInfo.getMergedSchema() != null) { requestBodyInfo.getMergedSchema().addProperties(paramName, schemaN); schemaN = requestBodyInfo.getMergedSchema(); } else if (schemaN instanceof FileSchema || schemaN instanceof ArraySchema && ((ArraySchema) schemaN).getItems() instanceof FileSchema) { schemaN = new ObjectSchema().addProperties(paramName, schemaN); requestBodyInfo.setMergedSchema(schemaN); } else requestBodyInfo.addProperties(paramName, schemaN); return schemaN; }
Example #6
Source File: SpringDocHateoasConfiguration.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Registers an OpenApiCustomiser and a jackson mixin to ensure the definition of `Links` matches the serialized * output. This is done because the customer serializer converts the data to a map before serializing it. * * @param halProvider the hal provider * @return the open api customiser * @see org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalLinkListSerializer#serialize(Links, JsonGenerator, SerializerProvider) org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalLinkListSerializer#serialize(Links, JsonGenerator, SerializerProvider) */ @Bean @ConditionalOnMissingBean @Lazy(false) OpenApiCustomiser linksSchemaCustomiser(HateoasHalProvider halProvider) { if (!halProvider.isHalEnabled()) { return openApi -> { }; } Json.mapper().addMixIn(RepresentationModel.class, RepresentationModelLinksOASMixin.class); ResolvedSchema resolvedLinkSchema = ModelConverters.getInstance() .resolveAsResolvedSchema(new AnnotatedType(Link.class)); return openApi -> openApi .schema("Link", resolvedLinkSchema.schema) .schema("Links", new MapSchema() .additionalProperties(new StringSchema()) .additionalProperties(new ObjectSchema().$ref(AnnotationsUtils.COMPONENTS_REF +"Link"))); }
Example #7
Source File: Link.java From crnk-framework with Apache License 2.0 | 6 votes |
public Schema schema() { return new ComposedSchema() .oneOf( Arrays.asList( new StringSchema() .description("A string containing the link's URL.") .format("uri"), new ObjectSchema() .required(Collections.singletonList("href")) .addProperties( "href", new StringSchema() .format("uri") .description("A string containing the link's URL.")) .addProperties( "meta", new Meta().$ref()))) .description("A link **MUST** be represented as either: a string containing the link's URL or a link object."); }
Example #8
Source File: Failure.java From crnk-framework with Apache License 2.0 | 6 votes |
public Schema schema() { return new ObjectSchema() .addProperties("jsonapi", new JsonApi().$ref()) .addProperties( "errors", new ArraySchema() .items(new ApiError().$ref()) .uniqueItems(true)) .addProperties( "meta", new Meta().$ref()) .addProperties( "links", new Links().$ref()) .required(Collections.singletonList("errors")) .additionalProperties(false); }
Example #9
Source File: OASUtilsTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Test public void testEnumAnythingElse() { MetaEnumType type = new MetaEnumType(); type.setName("TestEnum"); List<String> names = Arrays.asList("Remo", "Mac", "Ralph"); List<MetaElement> people = new ArrayList<>(); for (String name : names) { MetaPrimitiveType person = new MetaPrimitiveType(); person.setName(name); people.add(person); } type.setChildren(people); Schema schema = OASUtils.transformMetaResourceField(type); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertEquals(true, schema.getAdditionalProperties()); }
Example #10
Source File: ResourcePatchAttributesTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Test void notUpdatable() { MetaResource metaResource = getTestMetaResource(); MetaResourceField additionalMetaResourceField = (MetaResourceField) metaResource.getChildren().get(1); additionalMetaResourceField.setUpdatable(false); Schema schema = new ResourcePatchAttributes(metaResource).schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("attributes")); Assert.assertEquals(1, schema.getProperties().size()); Schema attributes = (Schema) schema.getProperties().get("attributes"); Assert.assertTrue(attributes instanceof ObjectSchema); Assert.assertEquals(0, attributes.getProperties().size()); }
Example #11
Source File: ResourcePostAttributesTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Test void isInsertable() { MetaResource metaResource = getTestMetaResource(); MetaResourceField additionalMetaResourceField = (MetaResourceField) metaResource.getChildren().get(1); additionalMetaResourceField.setInsertable(true); Schema schema = new ResourcePostAttributes(metaResource).schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("attributes")); Assert.assertEquals(1, schema.getProperties().size()); Schema attributes = (Schema) schema.getProperties().get("attributes"); Assert.assertTrue(attributes instanceof ObjectSchema); Assert.assertTrue(attributes.getProperties().containsKey("name")); Assert.assertEquals(1, attributes.getProperties().size()); Schema name = (Schema) attributes.getProperties().get("name"); Assert.assertEquals( "#/components/schemas/ResourceTypeNameResourceAttribute", name.get$ref()); }
Example #12
Source File: ResourcePostAttributesTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Test void notInsertable() { MetaResource metaResource = getTestMetaResource(); MetaResourceField additionalMetaResourceField = (MetaResourceField) metaResource.getChildren().get(1); additionalMetaResourceField.setInsertable(false); Schema schema = new ResourcePostAttributes(metaResource).schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("attributes")); Assert.assertEquals(1, schema.getProperties().size()); Schema attributes = (Schema) schema.getProperties().get("attributes"); Assert.assertTrue(attributes instanceof ObjectSchema); Assert.assertEquals(0, attributes.getProperties().size()); }
Example #13
Source File: ResourcePostRelationshipsTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Test void isInsertable() { final Schema relationshipsSchema = checkRelationshipsSchema(true); assertIterableEquals(singleton("resourceRelation"), relationshipsSchema.getProperties().keySet()); Schema resourceRelationSchema = ((ObjectSchema) relationshipsSchema).getProperties().get("resourceRelation"); assertNotNull(resourceRelationSchema); assertEquals(ObjectSchema.class, resourceRelationSchema.getClass()); Map<String, Schema> resourceRelationProps = ((ObjectSchema) resourceRelationSchema).getProperties(); assertIterableEquals(singleton("data"), resourceRelationProps.keySet()); Schema dataSchema = resourceRelationProps.get("data"); assertNotNull(dataSchema); assertEquals(ComposedSchema.class, dataSchema.getClass()); List<Schema> dataOneOfSchema = ((ComposedSchema) dataSchema).getOneOf(); assertNotNull(dataOneOfSchema); assertEquals(2, dataOneOfSchema.size()); assertEquals("#/components/schemas/RelatedResourceTypeResourceReference", dataOneOfSchema.get(1).get$ref()); }
Example #14
Source File: ResourcePatchRelationshipsTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Test void isUpdatable() { final Schema relationshipsSchema = checkRelationshipsSchema(true); assertIterableEquals(singleton("resourceRelation"), relationshipsSchema.getProperties().keySet()); Schema resourceRelationSchema = ((ObjectSchema) relationshipsSchema).getProperties().get("resourceRelation"); assertNotNull(resourceRelationSchema); assertEquals(ObjectSchema.class, resourceRelationSchema.getClass()); Map<String, Schema> resourceRelationProps = ((ObjectSchema) resourceRelationSchema).getProperties(); assertIterableEquals(singleton("data"), resourceRelationProps.keySet()); Schema dataSchema = resourceRelationProps.get("data"); assertNotNull(dataSchema); assertEquals(ComposedSchema.class, dataSchema.getClass()); List<Schema> dataOneOfSchema = ((ComposedSchema) dataSchema).getOneOf(); assertNotNull(dataOneOfSchema); assertEquals(2, dataOneOfSchema.size()); assertEquals("#/components/schemas/RelatedResourceTypeResourceReference", dataOneOfSchema.get(1).get$ref()); }
Example #15
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 6 votes |
private Schema createSingleSchema(String fullQualifiedName, TypeDeclaration<?> typeDeclaration) { Optional<String> description = typeDeclaration.getJavadoc() .map(javadoc -> javadoc.getDescription().toText()); Schema schema = new ObjectSchema(); schema.setName(fullQualifiedName); description.ifPresent(schema::setDescription); Map<String, Schema> properties = getPropertiesFromClassDeclaration( typeDeclaration); schema.properties(properties); List<String> requiredList = properties.entrySet().stream() .filter(stringSchemaEntry -> GeneratorUtils .isNotTrue(stringSchemaEntry.getValue().getNullable())) .map(Map.Entry::getKey).collect(Collectors.toList()); // Nullable is represented in requiredList instead. properties.values() .forEach(propertySchema -> propertySchema.nullable(null)); schema.setRequired(requiredList); return schema; }
Example #16
Source File: InlineModelResolver.java From swagger-parser with Apache License 2.0 | 6 votes |
@SuppressWarnings("static-method") public Schema modelFromProperty(ArraySchema object, @SuppressWarnings("unused") String path) { String description = object.getDescription(); String example = null; Object obj = object.getExample(); if (obj != null) { example = obj.toString(); } Schema inner = object.getItems(); if (inner instanceof ObjectSchema) { ArraySchema model = new ArraySchema(); model.setDescription(description); model.setExample(example); model.setItems(object.getItems()); return model; } return null; }
Example #17
Source File: InlineModelResolverTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testArbitraryObjectModelWithArrayInlineWithoutTitle() { OpenAPI openAPI = new OpenAPI(); openAPI.setComponents(new Components()); Schema items = new ObjectSchema(); items.setDefault("default"); items.setReadOnly(false); items.setDescription("description"); items.setName("name"); items.addProperties("arbitrary", new ObjectSchema()); openAPI.getComponents().addSchemas("User", new ArraySchema().items(items).addRequiredItem("name")); new InlineModelResolver().flatten(openAPI); Schema model = openAPI.getComponents().getSchemas().get("User"); assertTrue(model instanceof ArraySchema); ArraySchema am = (ArraySchema) model; Schema inner = am.getItems(); assertTrue(inner.get$ref() != null); Schema userInner = openAPI.getComponents().getSchemas().get("User_inner"); assertNotNull(userInner); Schema inlineProp = (Schema)userInner.getProperties().get("arbitrary"); assertTrue(inlineProp instanceof ObjectSchema); ObjectSchema op = (ObjectSchema) inlineProp; assertNull(op.getProperties()); }
Example #18
Source File: ComponentSchemaTransformer.java From spring-openapi with MIT License | 5 votes |
private Optional<Schema> getFieldSchema(Class<?> clazz, Field field, List<String> requiredFields) { if (shouldIgnoreField(clazz, field)) { return Optional.empty(); } Class<?> typeSignature = field.getType(); Annotation[] annotations = field.getAnnotations(); if (isRequired(annotations)) { requiredFields.add(field.getName()); } if (typeSignature.isPrimitive()) { return createBaseTypeSchema(field, requiredFields, annotations); } else if (typeSignature.isArray()) { return createArrayTypeSchema(typeSignature, annotations); } else if (StringUtils.equalsIgnoreCase(typeSignature.getName(), "java.lang.Object")) { ObjectSchema objectSchema = new ObjectSchema(); 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]; return Optional.of(schemaGeneratorHelper.parseArraySignature(listGenericParameter, annotations)); } return Optional.empty(); } else { return createClassRefSchema(typeSignature, annotations); } }
Example #19
Source File: InfluxJavaGenerator.java From influxdb-client-java with MIT License | 5 votes |
@Override public void setGlobalOpenAPI(final OpenAPI openAPI) { super.setGlobalOpenAPI(openAPI); InlineModelResolver inlineModelResolver = new InlineModelResolver(); inlineModelResolver.flatten(openAPI); String[] schemaNames = openAPI.getComponents().getSchemas().keySet().toArray(new String[0]); for (String schemaName : schemaNames) { Schema schema = openAPI.getComponents().getSchemas().get(schemaName); if (schema instanceof ComposedSchema) { List<Schema> allOf = ((ComposedSchema) schema).getAllOf(); if (allOf != null) { allOf.forEach(child -> { if (child instanceof ObjectSchema) { inlineModelResolver.flattenProperties(child.getProperties(), schemaName); } }); } } } }
Example #20
Source File: SchemaResolverTest.java From flow with Apache License 2.0 | 5 votes |
@Test public void should_ReturnNotNullableBeanSchema_When_GivenTypeIsABeanType() { ResolvedType resolvedType = mockReferencedTypeOf(TestBean.class); Schema schema = schemaResolver.parseResolvedTypeToSchema(resolvedType); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertNull(schema.getNullable()); String beanRef = schemaResolver .getFullQualifiedNameRef(TestBean.class.getCanonicalName()); Assert.assertEquals(beanRef, schema.get$ref()); Assert.assertEquals(1, schemaResolver.getFoundTypes().size()); }
Example #21
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 5 votes |
@SuppressWarnings("squid:S1872") private List<Schema> parseReferencedTypeAsSchema( ResolvedReferenceType resolvedType) { List<Schema> results = new ArrayList<>(); Schema schema = createSingleSchemaFromResolvedType(resolvedType); String qualifiedName = resolvedType.getQualifiedName(); generatedSchema.add(qualifiedName); List<ResolvedReferenceType> directAncestors = resolvedType .getDirectAncestors().stream() .filter(parent -> parent.getTypeDeclaration().isClass() && !Object.class.getName() .equals(parent.getQualifiedName())) .collect(Collectors.toList()); if (directAncestors.isEmpty() || resolvedType.getTypeDeclaration().isEnum()) { results.add(schema); results.addAll(generatedRelatedSchemas(schema)); } else { ComposedSchema parentSchema = new ComposedSchema(); parentSchema.name(qualifiedName); results.add(parentSchema); for (ResolvedReferenceType directAncestor : directAncestors) { String ancestorQualifiedName = directAncestor .getQualifiedName(); String parentRef = schemaResolver .getFullQualifiedNameRef(ancestorQualifiedName); parentSchema.addAllOfItem(new ObjectSchema().$ref(parentRef)); schemaResolver.addFoundTypes(ancestorQualifiedName, directAncestor); } parentSchema.addAllOfItem(schema); results.addAll(generatedRelatedSchemas(parentSchema)); } return results; }
Example #22
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 5 votes |
private Schema parseTypeToSchema(Type javaType, String description) { try { Schema schema = parseResolvedTypeToSchema(javaType.resolve()); if (GeneratorUtils.isNotBlank(description)) { schema.setDescription(description); } return schema; } catch (Exception e) { getLogger().info(String.format( "Can't resolve type '%s' for creating custom OpenAPI Schema. Using the default ObjectSchema instead.", javaType.asString()), e); } return new ObjectSchema(); }
Example #23
Source File: InfluxJavaGenerator.java From influxdb-client-java with MIT License | 5 votes |
private List<Schema> getObjectSchemas(final Schema schema, final Map<String, Schema> allDefinitions) { if (schema instanceof ObjectSchema) { return Lists.newArrayList(schema); } else if (schema instanceof ComposedSchema) { List<Schema> allOf = ((ComposedSchema) schema).getAllOf(); if (allOf != null) { return allOf.stream().map(it -> getObjectSchemas(it, allDefinitions)) .flatMap(Collection::stream) .collect(Collectors.toList()); } } else if (schema.get$ref() != null) { return Lists.newArrayList(allDefinitions.get(ModelUtils.getSimpleRef(schema.get$ref()))); } return Lists.newArrayList(); }
Example #24
Source File: ResourceRelationships.java From crnk-framework with Apache License 2.0 | 5 votes |
private static Schema generateRelationshipSchema(MetaResource metaResource, MetaResourceField field) { return new ObjectSchema() .addProperties("links", new ObjectSchema() .addProperties("self", new StringSchema() ._default(OASUtils.getRelationshipsPath(metaResource, field))) .addProperties("related", new StringSchema() ._default(OASUtils.getNestedPath(metaResource, field)))) .addProperties("data", new ComposedSchema() .addOneOfItem(new ArraySchema().items(OASUtils.transformMetaResourceField(field.getType()))) .addOneOfItem(OASUtils.transformMetaResourceField(field.getType())) ); }
Example #25
Source File: SchemaResolver.java From flow with Apache License 2.0 | 5 votes |
private Schema createUserBeanSchema(ResolvedType resolvedType) { if (resolvedType.isReferenceType()) { String qualifiedName = resolvedType.asReferenceType() .getQualifiedName(); foundTypes.put(qualifiedName, resolvedType.asReferenceType()); return new ObjectSchema().name(qualifiedName) .$ref(getFullQualifiedNameRef(qualifiedName)); } return new ObjectSchema(); }
Example #26
Source File: SchemaResolver.java From flow with Apache License 2.0 | 5 votes |
Schema parseResolvedTypeToSchema(ResolvedType resolvedType) { if (resolvedType.isArray()) { return createArraySchema(resolvedType); } if (isNumberType(resolvedType)) { return new NumberSchema(); } else if (isStringType(resolvedType)) { return new StringSchema(); } else if (isCollectionType(resolvedType)) { return createCollectionSchema(resolvedType.asReferenceType()); } else if (isBooleanType(resolvedType)) { return new BooleanSchema(); } else if (isMapType(resolvedType)) { return createMapSchema(resolvedType); } else if (isDateType(resolvedType)) { return new DateSchema(); } else if (isDateTimeType(resolvedType)) { return new DateTimeSchema(); } else if (isOptionalType(resolvedType)) { return createOptionalSchema(resolvedType.asReferenceType()); } else if (isUnhandledJavaType(resolvedType)) { return new ObjectSchema(); } else if (isTypeOf(resolvedType, Enum.class)) { return createEnumTypeSchema(resolvedType); } return createUserBeanSchema(resolvedType); }
Example #27
Source File: PatchResourceTest.java From crnk-framework with Apache License 2.0 | 5 votes |
@Test void schema() { relationshipMetaResourceField.setUpdatable(true); Schema requestSchema = new PatchResource(metaResource).schema(); ObjectSchema topLevelSchema = (ObjectSchema) requestSchema; assertIterableEquals(singleton("data"), topLevelSchema.getProperties().keySet()); Schema dataSchema = topLevelSchema.getProperties().get("data"); assertEquals(ComposedSchema.class, dataSchema.getClass()); List<Schema> allOf = ((ComposedSchema) dataSchema).getAllOf(); assertEquals(2, allOf.size()); assertEquals("#/components/schemas/ResourceTypeResourceReference", allOf.get(0).get$ref()); assertEquals("#/components/schemas/ResourceTypeResourcePatchRelationships", allOf.get(1).get$ref()); }
Example #28
Source File: ResourcePatchRelationshipsTest.java From crnk-framework with Apache License 2.0 | 5 votes |
private Schema checkRelationshipsSchema(boolean updatable) { relationshipMetaResourceField.setUpdatable(updatable); Schema schema = new ResourcePatchRelationships(metaResource).schema(); assertNotNull(schema); assertEquals(ObjectSchema.class, schema.getClass()); assertIterableEquals(singleton("relationships"), schema.getProperties().keySet()); Schema relationshipsSchema = ((ObjectSchema) schema).getProperties().get("relationships"); assertNotNull(relationshipsSchema); assertEquals(ObjectSchema.class, relationshipsSchema.getClass()); return relationshipsSchema; }
Example #29
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 5 votes |
private List<Schema> parseNonEndpointClassAsSchema( String fullQualifiedName) { TypeDeclaration<?> typeDeclaration = nonEndpointMap.get(fullQualifiedName); if (typeDeclaration == null || typeDeclaration.isEnumDeclaration()) { return Collections.emptyList(); } List<Schema> result = new ArrayList<>(); Schema schema = createSingleSchema(fullQualifiedName, typeDeclaration); generatedSchema.add(fullQualifiedName); NodeList<ClassOrInterfaceType> extendedTypes = null; if (typeDeclaration.isClassOrInterfaceDeclaration()) { extendedTypes = typeDeclaration.asClassOrInterfaceDeclaration() .getExtendedTypes(); } if (extendedTypes == null || extendedTypes.isEmpty()) { result.add(schema); result.addAll(generatedRelatedSchemas(schema)); } else { ComposedSchema parentSchema = new ComposedSchema(); parentSchema.setName(fullQualifiedName); result.add(parentSchema); extendedTypes.forEach(parentType -> { ResolvedReferenceType resolvedParentType = parentType.resolve(); String parentQualifiedName = resolvedParentType .getQualifiedName(); String parentRef = schemaResolver .getFullQualifiedNameRef(parentQualifiedName); parentSchema.addAllOfItem(new ObjectSchema().$ref(parentRef)); schemaResolver.addFoundTypes(parentQualifiedName, resolvedParentType); }); // The inserting order matters for `allof` property. parentSchema.addAllOfItem(schema); result.addAll(generatedRelatedSchemas(parentSchema)); } return result; }
Example #30
Source File: ResourcePostRelationshipsTest.java From crnk-framework with Apache License 2.0 | 5 votes |
private Schema checkRelationshipsSchema(boolean insertable) { relationshipMetaResourceField.setInsertable(insertable); Schema schema = new ResourcePostRelationships(metaResource).schema(); assertNotNull(schema); assertEquals(ObjectSchema.class, schema.getClass()); assertIterableEquals(singleton("relationships"), schema.getProperties().keySet()); Schema relationshipsSchema = ((ObjectSchema) schema).getProperties().get("relationships"); assertNotNull(relationshipsSchema); assertEquals(ObjectSchema.class, relationshipsSchema.getClass()); return relationshipsSchema; }