public async Task <OpenApiDocument> GenerateAsync(HttpContext httpContext, IAppEntity app, IEnumerable <ISchemaEntity> schemas, bool flat = false)
        {
            var document = CreateApiDocument(httpContext, app);

            var schemaResolver = new OpenApiSchemaResolver(document, schemaSettings);

            requestCache.AddDependency(app.UniqueId, app.Version);

            foreach (var schema in schemas)
            {
                requestCache.AddDependency(schema.UniqueId, schema.Version);
            }

            var builder = new Builder(app, document, schemaResolver, schemaGenerator);

            var validSchemas =
                schemas.Where(x =>
                              x.SchemaDef.IsPublished &&
                              x.SchemaDef.Type != SchemaDefType.Component &&
                              x.SchemaDef.Fields.Count > 0);

            var partitionResolver = app.PartitionResolver();

            foreach (var schema in validSchemas)
            {
                var components = await appProvider.GetComponentsAsync(schema, httpContext.RequestAborted);

                GenerateSchemaOperations(builder.Schema(schema.SchemaDef, partitionResolver, components, true));
            }

            GenerateSharedOperations(builder.Shared());

            var context =
                new DocumentProcessorContext(document,
                                             Enumerable.Empty <Type>(),
                                             Enumerable.Empty <Type>(),
                                             schemaResolver,
                                             schemaGenerator,
                                             schemaSettings);

            foreach (var processor in schemaSettings.DocumentProcessors)
            {
                processor.Process(context);
            }

            return(document);
        }
Ejemplo n.º 2
0
        public GraphQLModel(IAppEntity app, IEnumerable <ISchemaEntity> schemas, IGraphQLUrlGenerator urlGenerator)
        {
            this.app = app;

            partitionResolver = app.PartitionResolver();

            CanGenerateAssetSourceUrl = urlGenerator.CanGenerateAssetSourceUrl;

            assetType     = new AssetGraphType(this);
            assetListType = new ListGraphType(new NonNullGraphType(assetType));

            schemasById = schemas.ToDictionary(x => x.Id);

            graphQLSchema = BuildSchema(this);
            graphQLSchema.RegisterValueConverter(JsonConverter.Instance);

            InitializeContentTypes();
        }
Ejemplo n.º 3
0
        public GraphQLModel(IAppEntity app,
                            IEnumerable <ISchemaEntity> schemas,
                            int pageSizeContents,
                            int pageSizeAssets,
                            IUrlGenerator urlGenerator)
        {
            partitionResolver = app.PartitionResolver();

            CanGenerateAssetSourceUrl = urlGenerator.CanGenerateAssetSourceUrl;

            assetType     = new AssetGraphType(this);
            assetListType = new ListGraphType(new NonNullGraphType(assetType));

            var allSchemas = schemas.Where(x => x.SchemaDef.IsPublished).ToList();

            BuildSchemas(allSchemas);

            graphQLSchema = BuildSchema(this, pageSizeContents, pageSizeAssets, allSchemas);
            graphQLSchema.RegisterValueConverter(JsonConverter.Instance);
            graphQLSchema.RegisterValueConverter(InstantConverter.Instance);

            InitializeContentTypes();
        }
Ejemplo n.º 4
0
        public GraphQLModel(IAppEntity app, IEnumerable <ISchemaEntity> schemas, GraphQLTypeFactory typeFactory, ISemanticLog log)
        {
            graphQLTypeFactory = typeFactory;

            this.log = log;

            partitionResolver = app.PartitionResolver();

            typeVisitor = new GraphQLTypeVisitor(contentTypes, this);

            var allSchemas = schemas.Where(x => x.SchemaDef.IsPublished).ToList();

            BuildSchemas(allSchemas);

            graphQLSchema = BuildSchema(this, allSchemas);
            graphQLSchema.RegisterValueConverter(JsonConverter.Instance);
            graphQLSchema.RegisterValueConverter(InstantConverter.Instance);

            InitializeContentTypes(allSchemas);

            partitionResolver = null !;

            typeVisitor = null !;
        }
Ejemplo n.º 5
0
        private static EdmModel BuildEdmModel(Schema schema, IAppEntity app,
                                              ResolvedComponents components, bool withHiddenFields)
        {
            var model = new EdmModel();

            var pascalAppName    = app.Name.ToPascalCase();
            var pascalSchemaName = schema.Name.ToPascalCase();

            var typeFactory = new EdmTypeFactory(name =>
            {
                var finalName = pascalSchemaName;

                if (!string.IsNullOrWhiteSpace(name))
                {
                    finalName += ".";
                    finalName += name;
                }

                var result = model.SchemaElements.OfType <EdmComplexType>().FirstOrDefault(x => x.Name == finalName);

                if (result != null)
                {
                    return(result, false);
                }

                result = new EdmComplexType(pascalAppName, finalName);

                model.AddElement(result);

                return(result, true);
            });

            var schemaType = schema.BuildEdmType(withHiddenFields, app.PartitionResolver(), typeFactory, components);

            return(BuildEdmModel(app.Name.ToPascalCase(), schema.Name, model, schemaType));
        }
Ejemplo n.º 6
0
        public Task GenerateDefaultValuesAsync(NamedContentData data)
        {
            data.GenerateDefaultValues(schema.SchemaDef, app.PartitionResolver());

            return(Task.CompletedTask);
        }
Ejemplo n.º 7
0
        private static JsonSchema BuildJsonSchema(Schema schema, IAppEntity app, bool withHiddenFields)
        {
            var dataSchema = schema.BuildJsonSchema(app.PartitionResolver(), (n, s) => s, withHiddenFields);

            return(new ContentSchemaBuilder().CreateContentSchema(schema, dataSchema));
        }
Ejemplo n.º 8
0
        private void GenerateSchemasOperations(IEnumerable<ISchemaEntity> schemas, IAppEntity app)
        {
            var appBasePath = $"/content/{app.Name}";

            foreach (var schema in schemas.Where(x => x.IsPublished).Select(x => x.SchemaDef))
            {
                new SchemaSwaggerGenerator(document, appBasePath, schema, AppendSchema, app.PartitionResolver()).GenerateSchemaOperations();
            }
        }
Ejemplo n.º 9
0
        public Task EnrichAsync(NamedContentData data)
        {
            data.Enrich(schemaEntity.SchemaDef, appEntity.PartitionResolver());

            return(TaskHelper.Done);
        }
Ejemplo n.º 10
0
        private static JsonSchema BuildJsonSchema(Schema schema, IAppEntity app, bool withHiddenFields)
        {
            var dataSchema = schema.BuildJsonSchema(app.PartitionResolver(), (n, s) => s, withHiddenFields);

            return(BuildJsonSchema(schema.DisplayName(), dataSchema));
        }
Ejemplo n.º 11
0
        public Task GenerateDefaultValuesAsync(NamedContentData data)
        {
            data.GenerateDefaultValues(schemaEntity.SchemaDef, appEntity.PartitionResolver());

            return(TaskHelper.Done);
        }
Ejemplo n.º 12
0
 private PartitionResolver Partition()
 {
     return(app.PartitionResolver());
 }
Ejemplo n.º 13
0
        private static JsonSchema BuildJsonSchema(Schema schema, IAppEntity app, bool withHiddenFields)
        {
            var dataSchema = schema.BuildJsonSchema(app.PartitionResolver(), withHiddenFields);

            return(ContentJsonSchemaBuilder.BuildSchema(schema.DisplayName(), dataSchema, false, true));
        }