Example #1
0
        protected virtual IEnumerable <StatementSyntax> GenerateStatements(
            ILocatedOpenApiElement <OpenApiOperation> operation)
        {
            yield return(GenerateRequestMessageVariable(operation));

            yield return(ExpressionStatement(AddHeadersMethodGenerator.InvokeAddHeaders(
                                                 ThisExpression(),
                                                 IdentifierName(RequestMessageVariableName))));

            yield return(ExpressionStatement(AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
                                                                  SyntaxHelpers.MemberAccess(RequestMessageVariableName, "Content"),
                                                                  BuildContentMethodGenerator.InvokeBuildContent(
                                                                      ThisExpression(),
                                                                      IdentifierName(TypeSerializerRegistryParameterName)))));

            yield return(ReturnStatement(IdentifierName(RequestMessageVariableName)));
        }
Example #2
0
        public override IEnumerable <MemberDeclarationSyntax> Generate()
        {
            var classNameAndNamespace = (QualifiedNameSyntax)GetTypeName();

            string className = classNameAndNamespace.Right.Identifier.Text;

            ClassDeclarationSyntax declaration = ClassDeclaration(className)
                                                 .AddElementAnnotation(Element, Context.ElementRegistry)
                                                 .AddModifiers(Token(SyntaxKind.PublicKeyword))
                                                 .AddBaseListTypes(SimpleBaseType(RequestsNamespace.OperationRequest))
                                                 .AddMembers(ConstructorDeclaration(className)
                                                             .AddModifiers(Token(SyntaxKind.PublicKeyword))
                                                             .WithBody(Block()));

            declaration = AddParameterProperties(declaration, Element.GetParameters());

            var requestBodyElement = Element.GetRequestBody();

            if (requestBodyElement != null)
            {
                var schema = MediaTypeSelector.Select(requestBodyElement)?.GetSchema();
                if (schema != null)
                {
                    declaration = declaration.AddMembers(
                        CreatePropertyDeclaration(requestBodyElement, className, schema, "Body"));
                }
            }

            declaration = declaration.AddMembers(
                BuildRequestMethodGenerator.Generate(Element),
                BuildUriMethodGenerator.Generate(Element),
                AddHeadersMethodGenerator.Generate(Element),
                BuildContentMethodGenerator.Generate(Element));

            yield return(declaration);
        }