operationSpec.ts 2.9 KB

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