async getOperationSchema()

in libs/logic-apps-shared/src/designer-client-services/lib/base/appService.ts [44:132]


  async getOperationSchema(
    swaggerUrl: string,
    operationId: string,
    isInput: boolean,
    supportsAuthenticationParameter: boolean
  ): Promise<any> {
    if (!swaggerUrl) {
      return Promise.resolve();
    }
    const swagger = await this.fetchAppServiceApiSwagger(swaggerUrl);
    if (!operationId) {
      return Promise.resolve();
    }
    const operation = swagger.getOperationByOperationId(operationId);
    if (!operation) {
      throw new Error('Operation not found');
    }

    const intl = getIntl();
    const paths = swagger.api.paths[operation.path];
    const rawOperation = paths[operation.method];
    const schema = { type: 'object', properties: {} as any, required: [] as string[] };

    if (isInput) {
      const element = document.createElement('a');
      element.href = swaggerUrl;

      const scheme = swagger.api.schemes?.at(-1) || 'https';
      const host = swagger.api.host || element.host;
      const baseUrl = `${scheme}://${host}`;
      schema.properties = {
        method: { type: 'string', default: operation.method, 'x-ms-visibility': 'hideInUI', title: 'Method' },
        uri: {
          type: 'string',
          title: 'URI',
          default: swagger.api.basePath ? `${baseUrl}${swagger.api.basePath}${operation.path}` : `${baseUrl}${operation.path}`,
          'x-ms-visibility': 'hideInUI',
          'x-ms-serialization': { property: { type: 'pathtemplate', parameterReference: 'inputs.operationDetails.pathParameters' } },
        },
      };
      schema.required = ['method', 'uri'];
      for (const parameter of rawOperation.parameters ?? []) {
        this._addParameterInSchema(schema, parameter);
      }

      if (supportsAuthenticationParameter) {
        schema.properties['authentication'] = {
          type: 'object',
          title: intl.formatMessage({ defaultMessage: 'Authentication', id: 'ewGciu', description: 'Title for authentication parameter' }),
          description: intl.formatMessage({
            defaultMessage: 'Enter JSON object of authentication parameter',
            id: '6c1ffO',
            description: 'Description for authentication parameter',
          }),
          'x-ms-visibility': 'advanced',
          'x-ms-editor': 'authentication',
          'x-ms-editor-options': {
            supportedAuthTypes: ['None', 'Basic', 'ClientCertificate', 'ActiveDirectoryOAuth', 'Raw', 'ManagedServiceIdentity'],
          },
        };
      }
    } else {
      const { responses } = rawOperation;
      let response: any = {};

      if (responses[ResponseCodes.$200]) {
        response = responses[ResponseCodes.$200];
      } else if (responses[ResponseCodes.$201]) {
        response = responses[ResponseCodes.$201];
      } else if (responses[ResponseCodes.$default]) {
        response = responses[ResponseCodes.$default];
      }

      if (response.schema) {
        schema.properties['body'] = {
          title: intl.formatMessage({ defaultMessage: 'Body', id: 'VZh+w2', description: 'Title for body outputs' }),
          ...response.schema,
        };
      }
      if (response.headers) {
        schema.properties['headers'] = {
          title: intl.formatMessage({ defaultMessage: 'Headers', id: 'voRDKP', description: 'Title for header outputs' }),
          ...response.headers,
        };
      }
    }

    return schema;
  }