Exemplo n.º 1
0
        private OpenApiSchema GetBodyParamsSchema(string key, SchemaRepository schemaRepository, IRpcMethodInfo methodInfo)
        {
            OpenApiSchema paramsObjectSchema = this.GetOpenApiEmptyObject();

            foreach (IRpcParameterInfo parameterInfo in methodInfo.Parameters)
            {
                string        name   = this.namePolicy.ConvertName(parameterInfo.Name);
                OpenApiSchema schema = this.schemaGenerator.GenerateSchema(parameterInfo.RawType, schemaRepository);
                paramsObjectSchema.Properties.Add(name, schema);
            }

            paramsObjectSchema = schemaRepository.AddDefinition($"{key}", paramsObjectSchema);

            var requestSchema = this.GetOpenApiEmptyObject();

            requestSchema.Properties.Add("id", this.schemaGenerator.GenerateSchema(typeof(string), schemaRepository));
            requestSchema.Properties.Add("jsonrpc", this.schemaGenerator.GenerateSchema(typeof(string), schemaRepository));
            requestSchema.Properties.Add("method", this.schemaGenerator.GenerateSchema(typeof(string), schemaRepository));
            requestSchema.Properties.Add("params", paramsObjectSchema);

            requestSchema = schemaRepository.AddDefinition($"request_{key}", requestSchema);

            this.RewriteJrpcAttributesExamples(requestSchema, schemaRepository, this.namePolicy.ConvertName(methodInfo.Name));

            return(requestSchema);
        }
        private OpenApiSchema GenerateReferencedSchema(
            DataContract dataContract,
            SchemaRepository schemaRepository,
            Func <OpenApiSchema> definitionFactory,
            ParameterInfo parameterInfo)
        {
            var  dataContractType   = dataContract.UnderlyingType;
            var  baseControllerType = typeof(BaseApiController);
            var  baseParameterType  = typeof(RepresentationParameter);
            var  schemaId           = _generatorOptions.SchemaIdSelector(dataContract.UnderlyingType);
            Type controllerType     = null;

            if (baseParameterType.IsAssignableFrom(dataContract.UnderlyingType))
            {
                if (baseControllerType.IsAssignableFrom(parameterInfo.Member.ReflectedType))
                {
                    schemaId         = $"{parameterInfo.Member.ReflectedType.Name}{schemaId}";
                    controllerType   = parameterInfo.Member.ReflectedType;
                    dataContractType = controllerType;
                }
            }

            if (schemaRepository.TryLookupByType(dataContractType, out OpenApiSchema referenceSchema))
            {
                return(referenceSchema);
            }

            schemaRepository.RegisterType(dataContractType, schemaId);

            var schema = definitionFactory();

            ApplyFilters(schema, dataContractType, schemaRepository);
            if (controllerType != null)
            {
                var controller = (BaseApiController)_serviceProvider.GetService(controllerType);
                var scimSchema = _scimSchemaQueryRepository.FindRootSCIMSchemaByResourceType(controller.ResourceType).Result;
                if (scimSchema != null)
                {
                    Enrich(scimSchema, scimSchema.HierarchicalAttributes.Select(a => a.Leaf).ToList(), schema.Properties);
                }
                else
                {
                    _logger.LogError($"the schema '{controller.ResourceType}' doesn't exist !");
                }

                var kvp = schema.Properties.FirstOrDefault(_ => _.Key == "attributes");
                if (!kvp.Equals(default(KeyValuePair <string, OpenApiSchema>)) && !string.IsNullOrWhiteSpace(kvp.Key))
                {
                    schema.Properties.Remove(kvp);
                }
            }

            return(schemaRepository.AddDefinition(schemaId, schema));
        }
Exemplo n.º 3
0
        private OpenApiSchema GeResposeSchema(string key, Type returnMethodType, SchemaRepository schemaRepository)
        {
            var resultSchema = this.schemaGenerator.GenerateSchema(returnMethodType, schemaRepository);

            var responseSchema = this.GetOpenApiEmptyObject();

            responseSchema.Properties.Add("id", this.schemaGenerator.GenerateSchema(typeof(string), schemaRepository));
            responseSchema.Properties.Add("jsonrpc", this.schemaGenerator.GenerateSchema(typeof(string), schemaRepository));
            responseSchema.Properties.Add("result", resultSchema);

            responseSchema = schemaRepository.AddDefinition($"response_{key}", responseSchema);
            this.RewriteJrpcAttributesExamples(responseSchema, schemaRepository);
            return(responseSchema);
        }
Exemplo n.º 4
0
        private OpenApiSchema GenerateReferencedSchema(
            DataContract dataContract,
            SchemaRepository schemaRepository,
            Func <OpenApiSchema> definitionFactory)
        {
            if (schemaRepository.TryLookupByType(dataContract.UnderlyingType, out OpenApiSchema referenceSchema))
            {
                return(referenceSchema);
            }

            var schemaId = _generatorOptions.SchemaIdSelector(dataContract.UnderlyingType);

            schemaRepository.RegisterType(dataContract.UnderlyingType, schemaId);

            var schema = definitionFactory();

            ApplyFilters(schema, dataContract.UnderlyingType, schemaRepository);

            return(schemaRepository.AddDefinition(schemaId, schema));
        }