handleSwaggerMethod(resource, href, resourceParams, methodValue, method) {
    const { Copy, Transition } = this.namespace.elements;
    const transition = new Transition();

    resource.content.push(transition);

    this.withPath(method, () => {
      const schemes = this.handleSwaggerTransitionAuth(methodValue);

      this.validateProduces(methodValue.produces);
      this.validateConsumes(methodValue.consumes);

      this.handleExternalDocs(transition, methodValue.externalDocs);

      const transitionParams = methodValue.parameters || [];

      const queryParams = transitionParams.filter(parameter => parameter.in === 'query');

      // Here we generate a URI template specific to this transition. If it
      // is different from the resource URI template, then we set the
      // transition's `href` attribute.
      const hrefForTransition = uriTemplate(this.basePath, href, resourceParams, queryParams);

      if (hrefForTransition !== resource.href.toValue()) {
        transition.href = hrefForTransition;
      }

      if (methodValue.summary) {
        this.withPath('summary', () => {
          transition.title = methodValue.summary;

          if (this.generateSourceMap) {
            this.createSourceMap(transition.meta.get('title'), this.path);
          }

          return transition.meta.get('title');
        });
      }

      if (methodValue.description) {
        this.withPath('description', () => {
          const description = new Copy(methodValue.description);
          transition.push(description);

          if (this.generateSourceMap) {
            this.createSourceMap(description, this.path);
          }

          return description;
        });
      }

      if (methodValue.operationId) {
        // TODO: Add a source map?
        transition.id = methodValue.operationId;
      }

      // For each uriParameter, create an hrefVariable
      const methodHrefVariables = this.createHrefVariables(transitionParams);
      if (methodHrefVariables) {
        transition.hrefVariables = methodHrefVariables;
      }

      // Currently, default responses are not supported in API Description format
      const relevantResponses = _.chain(methodValue.responses)
        .omit('default')
        .omitBy(isExtension)
        .value();

      if (methodValue.responses && methodValue.responses.default) {
        this.withPath('responses', 'default', (path) => {
          this.createAnnotation(
            annotations.DATA_LOST, path,
            'Default response is not yet supported'
          );
        });
      }

      if (_.keys(relevantResponses).length === 0) {
        if (transitionParams.filter(p => p.in === 'body').length) {
          // Create an empty successful response so that the request/response
          // pair gets properly generated. In the future we may want to
          // refactor the code below as this is a little weird.
          relevantResponses.null = {};
        } else {
          this.createTransaction(transition, method, schemes);
        }
      }

      // Transactions are created for each response in the document
      _.forOwn(relevantResponses, (responseValue, statusCode) => {
        this.handleSwaggerResponse(
          transition, method, methodValue,
          transitionParams, responseValue, statusCode,
          schemes, resourceParams
        );
      });

      this.handleSwaggerVendorExtensions(transition, methodValue);

      return transition;
    });
  }
// Convert a Swagger method into a Refract transition.
Convert a Swagger method into a Refract transition.
Convert a Swagger method into a Refract transition .
handleSwaggerMethod(resource, href, resourceParams, methodValue, method) {
    const { Copy, Transition } = this.namespace.elements;
    const transition = new Transition();
    resource.content.push(transition);
    this.withPath(method, () => {
      const schemes = this.handleSwaggerTransitionAuth(methodValue);
      this.validateProduces(methodValue.produces);
      this.validateConsumes(methodValue.consumes);
      this.handleExternalDocs(transition, methodValue.externalDocs);
      const transitionParams = methodValue.parameters || [];
      const queryParams = transitionParams.filter(parameter => parameter.in === 'query');
      const hrefForTransition = uriTemplate(this.basePath, href, resourceParams, queryParams);
      if (hrefForTransition !== resource.href.toValue()) {
        transition.href = hrefForTransition;
      }
      if (methodValue.summary) {
        this.withPath('summary', () => {
          transition.title = methodValue.summary;
          if (this.generateSourceMap) {
            this.createSourceMap(transition.meta.get('title'), this.path);
          }
          return transition.meta.get('title');
        });
      }
      if (methodValue.description) {
        this.withPath('description', () => {
          const description = new Copy(methodValue.description);
          transition.push(description);
          if (this.generateSourceMap) {
            this.createSourceMap(description, this.path);
          }
          return description;
        });
      }
      if (methodValue.operationId) {
        transition.id = methodValue.operationId;
      }
      const methodHrefVariables = this.createHrefVariables(transitionParams);
      if (methodHrefVariables) {
        transition.hrefVariables = methodHrefVariables;
      }
      const relevantResponses = _.chain(methodValue.responses)
        .omit('default')
        .omitBy(isExtension)
        .value();
      if (methodValue.responses && methodValue.responses.default) {
        this.withPath('responses', 'default', (path) => {
          this.createAnnotation(
            annotations.DATA_LOST, path,
            'Default response is not yet supported'
          );
        });
      }
      if (_.keys(relevantResponses).length === 0) {
        if (transitionParams.filter(p => p.in === 'body').length) {
          relevantResponses.null = {};
        } else {
          this.createTransaction(transition, method, schemes);
        }
      }
      _.forOwn(relevantResponses, (responseValue, statusCode) => {
        this.handleSwaggerResponse(
          transition, method, methodValue,
          transitionParams, responseValue, statusCode,
          schemes, resourceParams
        );
      });
      this.handleSwaggerVendorExtensions(transition, methodValue);
      return transition;
    });
  }
handleSwaggerMethod ( resource , href , resourceParams , methodValue , method ) { const { Copy , Transition } = this . namespace . elements ; const transition = new Transition ( ) ; resource . content . push ( transition ) ; this . withPath ( method , ( ) => { const schemes = this . handleSwaggerTransitionAuth ( methodValue ) ; this . validateProduces ( methodValue . produces ) ; this . validateConsumes ( methodValue . consumes ) ; this . handleExternalDocs ( transition , methodValue . externalDocs ) ; const transitionParams = methodValue . parameters || [ ] ; const queryParams = transitionParams . filter ( parameter => parameter . in === 'query' ) ; const hrefForTransition = uriTemplate ( this . basePath , href , resourceParams , queryParams ) ; if ( hrefForTransition !== resource . href . toValue ( ) ) { transition . href = hrefForTransition ; } if ( methodValue . summary ) { this . withPath ( 'summary' , ( ) => { transition . title = methodValue . summary ; if ( this . generateSourceMap ) { this . createSourceMap ( transition . meta . get ( 'title' ) , this . path ) ; } return transition . meta . get ( 'title' ) ; } ) ; } if ( methodValue . description ) { this . withPath ( 'description' , ( ) => { const description = new Copy ( methodValue . description ) ; transition . push ( description ) ; if ( this . generateSourceMap ) { this . createSourceMap ( description , this . path ) ; } return description ; } ) ; } if ( methodValue . operationId ) { transition . id = methodValue . operationId ; } const methodHrefVariables = this . createHrefVariables ( transitionParams ) ; if ( methodHrefVariables ) { transition . hrefVariables = methodHrefVariables ; } const relevantResponses = _ . chain ( methodValue . responses ) . omit ( 'default' ) . omitBy ( isExtension ) . value ( ) ; if ( methodValue . responses && methodValue . responses . default ) { this . withPath ( 'responses' , 'default' , ( path ) => { this . createAnnotation ( annotations . DATA_LOST , path , 'Default response is not yet supported' ) ; } ) ; } if ( _ . keys ( relevantResponses ) . length === 0 ) { if ( transitionParams . filter ( p => p . in === 'body' ) . length ) { relevantResponses . null = { } ; } else { this . createTransaction ( transition , method , schemes ) ; } } _ . forOwn ( relevantResponses , ( responseValue , statusCode ) => { this . handleSwaggerResponse ( transition , method , methodValue , transitionParams , responseValue , statusCode , schemes , resourceParams ) ; } ) ; this . handleSwaggerVendorExtensions ( transition , methodValue ) ; return transition ; } ) ; }
Convert a Swagger method into a Refract transition.
Convert a Swagger method into a Refract transition .
// Here we generate a URI template specific to this transition. If it // is different from the resource URI template, then we set the // transition's `href` attribute. // TODO: Add a source map? // For each uriParameter, create an hrefVariable // Currently, default responses are not supported in API Description format // Create an empty successful response so that the request/response // pair gets properly generated. In the future we may want to // refactor the code below as this is a little weird. // Transactions are created for each response in the document