Ejemplo n.º 1
0
        private Schema CreateResourceChildSchema(ResourceChildItem resourceChildItem, SwaggerResource swaggerResource)
        {
            var properties = resourceChildItem.Properties
                             .Select(
                p => new
            {
                IsRequired = p.IsIdentifying || !p.PropertyType.IsNullable,
                Key        = UniqueIdSpecification.GetUniqueIdPropertyName(p.JsonPropertyName).ToCamelCase(),
                Schema     = SwaggerDocumentHelper.CreatePropertySchema(p)
            }).Concat(
                resourceChildItem.References.Select(
                    r => new
            {
                r.IsRequired,
                Key    = r.PropertyName.ToCamelCase(),
                Schema = new Schema
                {
                    @ref = SwaggerDocumentHelper.GetDefinitionReference(
                        _swaggerDefinitionsFactoryNamingStrategy.GetReferenceName(swaggerResource.Resource, r))
                }
            })).Concat(
                resourceChildItem.Collections.Select(
                    c => new
            {
                IsRequired = c.Association.IsRequiredCollection,
                Key        = c.JsonPropertyName,
                Schema     = CreateCollectionSchema(c, swaggerResource)
            })).Concat(
                resourceChildItem.EmbeddedObjects.Select(
                    e => new
            {
                IsRequired = false,
                Key        = e.JsonPropertyName,
                Schema     = CreateEmbeddedObjectSchema(e, swaggerResource)
            })).ToList();

            var bridgeSchema = GetEdFiExtensionBridgeReferenceSchema(resourceChildItem, swaggerResource);

            if (bridgeSchema != null)
            {
                properties.Add(
                    new
                {
                    IsRequired = false,
                    Key        = ExtensionCollectionKey,
                    Schema     = bridgeSchema
                });
            }

            var requiredProperties = properties.Where(x => x.IsRequired).Select(x => x.Key).ToList();

            return(new Schema
            {
                type = "object",
                required = requiredProperties.Any()
                    ? requiredProperties
                    : null,
                properties = properties.ToDictionary(k => k.Key, v => v.Schema)
            });
        }
Ejemplo n.º 2
0
        public string GetContainedItemTypeName(
            OpenApiMetadataResource openApiMetadataResource,
            ResourceChildItem resourceChildItem)
        {
            var schemaPrefix = resourceChildItem.SchemaProperCaseName;

            return(OpenApiMetadataDocumentHelper.CamelCaseSegments($"{schemaPrefix}_{resourceChildItem.Name}"));
        }
        public string GetContainedItemTypeName(
            SwaggerResource swaggerResource,
            ResourceChildItem resourceChildItem)
        {
            var schemaPrefix = resourceChildItem.SchemaProperCaseName;

            return(SwaggerDocumentHelper.CamelCaseSegments($"{schemaPrefix}_{resourceChildItem.Name}"));
        }
 public string GetContainedItemTypeName(
     SwaggerResource swaggerResource,
     ResourceChildItem resourceChildItem)
 {
     return(CreateCompositeChildModelTypeName(
                swaggerResource.Resource.Name,
                resourceChildItem.Name,
                resourceChildItem.Parent));
 }
Ejemplo n.º 5
0
 public string GetContainedItemTypeName(
     OpenApiMetadataResource openApiMetadataResource,
     ResourceChildItem resourceChildItem)
 {
     return(CreateCompositeChildModelTypeName(
                openApiMetadataResource.Resource.Name,
                resourceChildItem.Name,
                resourceChildItem.Parent));
 }
        private static string GetContextualNamespacePrefix(ResourceChildItem resourceChildItem)
        {
            var schemaNameMapProvider = resourceChildItem.Entity.DomainModel.SchemaNameMapProvider;

            // TODO: Embedded Convention - relative namespace prefix for extension interfaces
            return("Entities.Common."
                   + schemaNameMapProvider.GetSchemaMapByPhysicalName(resourceChildItem.FullName.Schema)
                   .ProperCaseName
                   + ".");
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Check if resource child item is derived from another resource.
 /// </summary>
 /// <param name="resourceChildItem">ResourceChildItem object</param>
 /// <param name="resource">Resource object</param>
 /// <returns></returns>
 public static bool IsDerivedFrom(this ResourceChildItem resourceChildItem, ResourceClassBase resource)
 {
     return(resourceChildItem.Entity.IncomingAssociations.Any(
                a => (a.OtherEntity.IsBase || a.OtherEntity.IsAbstract) &&
                resource.Entity != null &&
                resource.Entity.BaseEntity != null &&
                ModelComparers.Entity.Equals(
                    a.OtherEntity,
                    resource.Entity.BaseEntity)));
 }
            protected override void Arrange()
            {
                var resourceModel =
                    DomainModelDefinitionsProviderHelper.ResourceModelProvider.GetResourceModel();

                var resources = resourceModel.GetAllResources();

                _resourceChildItem = resources.SelectMany(r => r.AllContainedItemTypes)
                                     .First(i => i.Name == "AssessmentContentStandard");

                _resource = resources.First(r => r.Name == "StateEducationAgency");
            }
Ejemplo n.º 9
0
        public string GetContainedItemTypeName(SwaggerResource swaggerResource, ResourceChildItem resourceChildItem)
        {
            var name = resourceChildItem.IsDerivedFrom(swaggerResource.Resource)
                ? CreateChildModelTypeName(
                swaggerResource.Resource,
                resourceChildItem.Name,
                resourceChildItem.Parent)
                : resourceChildItem.Name;

            return
                (SwaggerDocumentHelper.CamelCaseSegments(
                     $"{resourceChildItem.SchemaProperCaseName}_{name}_{swaggerResource.OperationNamingContext}"));
        }
Ejemplo n.º 10
0
            protected override void Act()
            {
                _educationOrganizationAddresses = _resourceModel
                                                  .GetResourceByFullName(new FullName("edfi", "EducationOrganizationNetwork"))
                                                  .CollectionByName["EducationOrganizationAddresses"]
                                                  .ItemType;

                _student = _resourceModel.GetResourceByFullName(new FullName("edfi", "Student"));

                _studentExtension = _student.ExtensionByName["Sample"]
                                    .ObjectType;

                _studentPetPreference = _studentExtension.EmbeddedObjectByName["StudentPetPreference"]
                                        .ObjectType;

                _studentPet = _studentExtension.CollectionByName["StudentPets"]
                              .ItemType;
            }
Ejemplo n.º 11
0
        private ResourceClassBase GetContextualParent(
            ResourceChildItem resourceChildItem,
            ResourceProfileData profileData)
        {
            if (resourceChildItem == null)
            {
                return(null);
            }

            if (profileData.IsBaseResource && resourceChildItem.IsInheritedChildItem)
            {
                return(profileData.ContextualRootResource.AllContainedItemTypes.Single(
                           x => x.FullName == resourceChildItem.FullName)
                       .Parent);
            }

            return(resourceChildItem.Parent);
        }