1 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
|
3 |
|
4 | import {
|
5 | OperationParameter,
|
6 | OperationQueryParameter,
|
7 | OperationURLParameter,
|
8 | } from "./operationParameter";
|
9 | import { OperationResponse } from "./operationResponse";
|
10 | import { MapperType, Serializer } from "./serializer";
|
11 | import { HttpMethods } from "./webResource";
|
12 |
|
13 | /**
|
14 | * A specification that defines an operation.
|
15 | */
|
16 | export interface OperationSpec {
|
17 | /**
|
18 | * The serializer to use in this operation.
|
19 | */
|
20 | readonly serializer: Serializer;
|
21 |
|
22 | /**
|
23 | * The HTTP method that should be used by requests for this operation.
|
24 | */
|
25 | readonly httpMethod: HttpMethods;
|
26 |
|
27 | /**
|
28 | * The URL that was provided in the service's specification. This will still have all of the URL
|
29 | * template variables in it. If this is not provided when the OperationSpec is created, then it
|
30 | * will be populated by a "baseUri" property on the ServiceClient.
|
31 | */
|
32 | readonly baseUrl?: string;
|
33 |
|
34 | /**
|
35 | * The fixed path for this operation's URL. This will still have all of the URL template variables
|
36 | * in it.
|
37 | */
|
38 | readonly path?: string;
|
39 |
|
40 | /**
|
41 | * The content type of the request body. This value will be used as the "Content-Type" header if
|
42 | * it is provided.
|
43 | */
|
44 | readonly contentType?: string;
|
45 |
|
46 | /**
|
47 | * The parameter that will be used to construct the HTTP request's body.
|
48 | */
|
49 | readonly requestBody?: OperationParameter;
|
50 |
|
51 | /**
|
52 | * Whether or not this operation uses XML request and response bodies.
|
53 | */
|
54 | readonly isXML?: boolean;
|
55 |
|
56 | /**
|
57 | * The parameters to the operation method that will be substituted into the constructed URL.
|
58 | */
|
59 | readonly urlParameters?: ReadonlyArray<OperationURLParameter>;
|
60 |
|
61 | /**
|
62 | * The parameters to the operation method that will be added to the constructed URL's query.
|
63 | */
|
64 | readonly queryParameters?: ReadonlyArray<OperationQueryParameter>;
|
65 |
|
66 | /**
|
67 | * The parameters to the operation method that will be converted to headers on the operation's
|
68 | * HTTP request.
|
69 | */
|
70 | readonly headerParameters?: ReadonlyArray<OperationParameter>;
|
71 |
|
72 | /**
|
73 | * The parameters to the operation method that will be used to create a formdata body for the
|
74 | * operation's HTTP request.
|
75 | */
|
76 | readonly formDataParameters?: ReadonlyArray<OperationParameter>;
|
77 |
|
78 | /**
|
79 | * The different types of responses that this operation can return based on what status code is
|
80 | * returned.
|
81 | */
|
82 | readonly responses: { [responseCode: string]: OperationResponse };
|
83 | }
|
84 |
|
85 | export function isStreamOperation(operationSpec: OperationSpec): boolean {
|
86 | let result = false;
|
87 | for (const statusCode in operationSpec.responses) {
|
88 | const operationResponse: OperationResponse = operationSpec.responses[statusCode];
|
89 | if (
|
90 | operationResponse.bodyMapper &&
|
91 | operationResponse.bodyMapper.type.name === MapperType.Stream
|
92 | ) {
|
93 | result = true;
|
94 | break;
|
95 | }
|
96 | }
|
97 | return result;
|
98 | }
|