protected virtual IEnumerable <StatementSyntax> GenerateStatements( ILocatedOpenApiElement <OpenApiOperation> operation) { var requestBody = operation.GetRequestBody(); ILocatedOpenApiElement <OpenApiMediaType>?mediaType; if (requestBody == null || (mediaType = MediaTypeSelector.Select(requestBody)) == null) { yield return(ReturnStatement(LiteralExpression(SyntaxKind.NullLiteralExpression))); yield break; } var createContentExpression = InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SerializationNamespace.TypeSerializerRegistryExtensions, IdentifierName("Serialize"))) .AddArgumentListArguments( Argument(IdentifierName(TypeSerializerRegistryParameterName)), Argument(IdentifierName(RequestTypeGenerator.BodyPropertyName)), Argument(SyntaxHelpers.StringLiteral(mediaType.Key))); yield return(ReturnStatement(ConditionalExpression( IsPatternExpression( IdentifierName(RequestTypeGenerator.BodyPropertyName), ConstantPattern(LiteralExpression(SyntaxKind.NullLiteralExpression))), LiteralExpression(SyntaxKind.NullLiteralExpression), createContentExpression))); }
public static IEnumerable <ILocatedOpenApiElement <OpenApiSchema> > GetAllSchemas( this ILocatedOpenApiElement <OpenApiOperation> operation) { var requestBody = operation.GetRequestBody(); if (requestBody is not null && !requestBody.IsReference()) { var requestSchemas = requestBody .GetMediaTypes() .Select(p => p.GetSchema()) .Where(p => p is not null && !p.IsReference()) .SelectMany(p => p !.GetAllSchemas()); foreach (var schema in requestSchemas) { yield return(schema); } } foreach (var responseSchema in operation .GetResponseSet() .GetResponses() .Where(p => !p.IsReference()) .GetAllSchemas()) { yield return(responseSchema); } }