public void GenerateResponseType(TSBuilder builder)
        {
            builder.DocumentationComment($"Contains response data for the {Name} operation.");
            builder.ExportIntersectionType(HttpResponseName, type =>
            {
                if (ReturnType.Body is DictionaryTypeTS dictionaryBody)
                {
                    type.ObjectType(dict =>
                    {
                        dict.DocumentationComment("The response body properties.");
                        dict.IndexSignature(dictionaryBody.ValueType.TSType(inModelsModule: true));
                    });
                }
                else if (ReturnType.Body is SequenceTypeTS sequenceBody)
                {
                    type.NamedType($"Array<{sequenceBody.ElementType.TSType(inModelsModule: true)}>");
                }
                else if (ReturnType.Body is CompositeTypeTS compositeBody)
                {
                    type.NamedType(compositeBody.TSType(inModelsModule: true));
                }

                if (ReturnType.Headers != null)
                {
                    type.NamedType(ReturnType.Headers.TSType(inModelsModule: true));
                }

                type.ObjectType(iface =>
                {
                    if (HasStreamResponseType())
                    {
                        iface.DocumentationComment(
                            "BROWSER ONLY",
                            "",
                            "The response body as a browser Blob.",
                            "Always undefined in node.js.");

                        iface.Property("blobBody", "Promise<Blob>", optional: true);

                        iface.DocumentationComment(
                            "NODEJS ONLY",
                            "",
                            "The response body as a node.js Readable stream.",
                            "Always undefined in the browser.");

                        iface.Property("readableStreamBody", "NodeJS.ReadableStream", optional: true);
                    }
                    else if (ReturnType.Body != null && !(ReturnType.Body is CompositeTypeTS || ReturnType.Body is SequenceTypeTS || ReturnType.Body is DictionaryTypeTS))
                    {
                        iface.DocumentationComment("The parsed response body.");
                        iface.Property(primitiveHttpBodyPropertyName, ReturnType.Body.TSType(inModelsModule: true));
                    }

                    iface.DocumentationComment("The underlying HTTP response.");
                    iface.Property(rawHttpResponsePropertyName, GenerateHttpOperationResponseType);
                });
            });
        }
Beispiel #2
0
        public void GenerateResponseType(TSBuilder builder)
        {
            builder.DocumentationComment($"Contains response data for the {Name} operation.");
            builder.ExportIntersectionType(HttpResponseName, type =>
            {
                if (ReturnType.Body is DictionaryTypeTS dictionaryBody)
                {
                    type.ObjectType(dict =>
                    {
                        dict.DocumentationComment("The response body properties.");
                        dict.IndexSignature(dictionaryBody.ValueType.TSType(inModelsModule: true));
                    });
                }
                else if (ReturnType.Body is SequenceTypeTS sequenceBody)
                {
                    type.NamedType($"Array<{sequenceBody.ElementType.TSType(inModelsModule: true)}>");
                }
                else if (ReturnType.Body is CompositeTypeTS compositeBody)
                {
                    type.NamedType(compositeBody.TSType(inModelsModule: true));
                }

                if (ReturnType.Headers != null)
                {
                    type.NamedType(ReturnType.Headers.TSType(inModelsModule: true));
                }

                if (HasStreamResponseType())
                {
                    type.ObjectType(iface =>
                    {
                        iface.DocumentationComment("The response body as a node.js Readable stream.");
                        iface.Property("body", "NodeJS.ReadableStream", optional: true);
                    });
                }

                type.ObjectType(iface =>
                {
                    string statusCodeValue = string.Join(" | ", Responses.Keys.Select(val => ((int)val).ToString()));
                    iface.DocumentationComment("The response status code.");
                    iface.Property("statusCode", statusCodeValue, optional: false);
                });
            });
        }