Esempio n. 1
0
        public IEnumerable <BaseMethodDeclarationSyntax> Generate(ILocatedOpenApiElement <OpenApiResponse> response, string className)
        {
            if (!response.IsRoot() && response.Element.Reference != null)
            {
                // Do not generator for responses within operations that are references to components, these will inherit
                // their get body method from the component base class
                yield break;
            }

            if (response.Element.Content == null)
            {
                yield break;
            }

            ILocatedOpenApiElement <OpenApiMediaType>?mediaType = MediaTypeSelector.Select(response);
            ILocatedOpenApiElement <OpenApiSchema>?   schema    = mediaType?.GetSchema();

            if (schema == null)
            {
                yield break;
            }

            ITypeGenerator schemaGenerator = Context.TypeGeneratorRegistry.Get(schema);

            TypeSyntax returnType = schemaGenerator.TypeInfo.Name;

            yield return(MethodDeclaration(
                             WellKnownTypes.System.Threading.Tasks.ValueTaskT.Name(returnType),
                             GetBodyMethodName)
                         .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.AsyncKeyword))
                         .WithBody(Block(GenerateStatements(response, returnType))));
        }
        public IEnumerable <BaseMethodDeclarationSyntax> Generate(ILocatedOpenApiElement <OpenApiResponse> response, string className)
        {
            var bodyType = GetBodyType(response);

            if (bodyType is not null)
            {
                // We don't want these overloads if there is a body, they'll just add confusion
                yield break;
            }

            if (!response.IsRoot())
            {
                // Construct from status code and headers without body
                yield return(ConstructorDeclaration(
Esempio n. 3
0
        public IEnumerable <BaseMethodDeclarationSyntax> Generate(ILocatedOpenApiElement <OpenApiResponse> response, string className)
        {
            var bodyType = GetBodyType(response);

            if (bodyType is null)
            {
                yield break;
            }

            if (response.IsRoot())
            {
                // this is a component which will be inherited from, it should receive the status code on the constructor

                yield return(ConstructorDeclaration(
 /// <summary>
 /// Determines if this response type is the one where primary work is done. This would be either a response
 /// in the components section, or a response within an operation which isn't a reference to the components
 /// section. Are reference to components section is implemented as inherited from the components section
 /// implementation, which doesn't require primary work implementation.
 /// </summary>
 /// <param name="response"></param>
 /// <returns></returns>
 private static bool IsBaseResponseClass(ILocatedOpenApiElement <OpenApiResponse> response) =>
 response.IsRoot() || response.Element.Reference == null;