Beispiel #1
0
        public override async Task Generate(CodeModel codeModel)
        {
            var @namespace = Class.CreateName(codeModel.Namespace);

            var phpGroups = codeModel.Operations
                            .Where(o => o.Name.RawValue != string.Empty)
                            .Select(o => new PhpFunctionGroup(@namespace, o));

            var phpFunctions = codeModel.Operations
                               .Where(o => o.Name.RawValue == string.Empty)
                               .SelectMany(o => o.Methods.Select(m => new PhpOperation(m)));

            var swaggerObjectData = PHP.Const(
                SwaggerObjectData,
                PHP.FromJson(SwaggerObject.Create(codeModel)));

            var client = PHP.Class(
                name: Class.CreateName(@namespace, codeModel.Name),
                constructor: PHP.Constructor(
                    parameters: ClientConstructorParameters,
                    body: PHP
                    .Statements(CreateClient)
                    .Concat(phpGroups.Select(g => g.Create))
                    .Concat(phpFunctions.SelectMany(f => f.ConstructorStatements))),
                functions: phpGroups
                .Select(o => o.Function)
                .Concat(phpFunctions.Select(f => f.Function)),
                properties: phpGroups
                .Select(o => o.Property)
                .Concat(phpFunctions.Select(f => f.Property)),
                consts: PHP.Consts(swaggerObjectData));

            foreach (var class_ in phpGroups
                     .Select(o => o.Class)
                     .Concat(ImmutableArray.Create(client)))
            {
                await Write(
                    string.Join("\n", class_.ToCodeText(Indent)),
                    class_.Name.FileName,
                    false);
            }
        }