Example #1
0
        public void When_generating_operation_ids_then_all_are_set()
        {
            //// Arrange
            var document = new OpenApiDocument();

            document.Paths["path"] = new OpenApiPathItem
            {
                {
                    OpenApiOperationMethod.Get,
                    new OpenApiOperation {
                    }
                },
                {
                    OpenApiOperationMethod.Post,
                    new OpenApiOperation {
                    }
                }
            };

            //// Act
            document.GenerateOperationIds();

            //// Assert
            Assert.True(document.Operations.GroupBy(o => o.Operation.OperationId).All(g => g.Count() == 1));
        }
Example #2
0
        /// <summary>
        /// get the api document all operations
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable <TypeScriptOperationModel> GetAllOperationModels()
        {
            // The intention here is to use the GetOperations of instance, but found that the Emun
            // type in Query will be thrown away, so directly take the source code to re-process the
            // type inside _resolver
            _openApiDocument.GenerateOperationIds();
            return(_openApiDocument.Paths
                   .SelectMany(pair => pair.Value.Select(p => new
                                                         { Path = pair.Key.TrimStart('/'), HttpMethod = p.Key, Operation = p.Value }))
                   .Select(tuple =>
            {
                var operationName =
                    _clientGeneratorSettings.OperationNameGenerator.GetOperationName(_openApiDocument, tuple.Path,
                                                                                     tuple.HttpMethod, tuple.Operation);
                if (operationName.EndsWith("Async"))
                {
                    operationName = operationName.Substring(0, operationName.Length - "Async".Length);
                }

                var operationModel = new TypeScriptOperationModel(tuple.Operation, _clientGeneratorSettings,
                                                                  _typeScriptClientGenerator,
                                                                  _resolver); // CreateOperationModel(tuple.Operation, _clientGeneratorSettings);
                operationModel.ControllerName =
                    _clientGeneratorSettings.OperationNameGenerator.GetClientName(_openApiDocument, tuple.Path,
                                                                                  tuple.HttpMethod, tuple.Operation);
                operationModel.Path = tuple.Path;
                operationModel.HttpMethod = tuple.HttpMethod;
                operationModel.OperationName = operationName;
                return operationModel;
            }));
        }
Example #3
0
        private List <TOperationModel> GetOperations(OpenApiDocument document)
        {
            document.GenerateOperationIds();

            return(document.Paths
                   .SelectMany(pair => pair.Value.ActualPathItem
                               .Select(p => new { Path = pair.Key.TrimStart('/'), HttpMethod = p.Key, Operation = p.Value }))
                   .Select(tuple =>
            {
                var operationName = BaseSettings.OperationNameGenerator.GetOperationName(document, tuple.Path, tuple.HttpMethod, tuple.Operation);

                if (operationName.Contains("."))
                {
                    operationName = operationName.Replace(".", "_");
                }

                if (operationName.EndsWith("Async"))
                {
                    operationName = operationName.Substring(0, operationName.Length - "Async".Length);
                }

                var operationModel = CreateOperationModel(tuple.Operation, BaseSettings);
                operationModel.ControllerName = BaseSettings.OperationNameGenerator.GetClientName(document, tuple.Path, tuple.HttpMethod, tuple.Operation);
                operationModel.Path = tuple.Path;
                operationModel.HttpMethod = tuple.HttpMethod;
                operationModel.OperationName = operationName;
                return operationModel;
            })
                   .ToList());
        }
Example #4
0
        private List <TOperationModel> GetOperations(OpenApiDocument document)
        {
            document.GenerateOperationIds();

            var result = new List <TOperationModel>();

            foreach (var pair in document.Paths)
            {
                foreach (var p in pair.Value.ActualPathItem)
                {
                    var path       = pair.Key.TrimStart('/');
                    var httpMethod = p.Key;
                    var operation  = p.Value;

                    var operationName = BaseSettings.OperationNameGenerator.GetOperationName(document, path, httpMethod, operation);

                    if (operationName.Contains("."))
                    {
                        operationName = operationName.Replace(".", "_");
                    }

                    if (operationName.EndsWith("Async"))
                    {
                        operationName = operationName.Substring(0, operationName.Length - "Async".Length);
                    }

                    var operationModel = CreateOperationModel(operation, BaseSettings);
                    operationModel.ControllerName = BaseSettings.OperationNameGenerator.GetClientName(document, path, httpMethod, operation);
                    operationModel.Path           = path;
                    operationModel.HttpMethod     = httpMethod;
                    operationModel.OperationName  = operationName;

                    result.Add(operationModel);
                }
            }
            return(result);
        }