apiaryio/fury-adapter-swagger

View on GitHub
src/parser.js

Summary

Maintainability
F
1 wk
Test Coverage

File parser.js has 1198 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// The main Swagger parsing component that outputs refract.

import _ from 'lodash';
import { sep } from 'path';
import yaml from 'js-yaml';
Severity: Major
Found in src/parser.js - About 3 days to fix

    Parser has 46 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class Parser {
      constructor({ minim, source, generateSourceMap }) {
        // Parser options
        this.minim = minim;
        this.source = source;
    Severity: Minor
    Found in src/parser.js - About 6 hrs to fix

      Function parse has 123 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        parse(done) {
          const {
            Category, ParseResult, SourceMap,
          } = this.minim.elements;
          const swaggerParser = new SwaggerParser();
      Severity: Major
      Found in src/parser.js - About 4 hrs to fix

        Function handleSwaggerExampleRequest has 79 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          handleSwaggerExampleRequest(
            transaction, methodValue, transitionParams, resourceParams,
            requestContentType, responseContentType, contentTypeFromProduces,
          ) {
            let contentType = requestContentType;
        Severity: Major
        Found in src/parser.js - About 3 hrs to fix

          Function handleSwaggerMethod has 69 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            handleSwaggerMethod(resource, href, resourceParams, methodValue, method) {
              const { Copy, Transition } = this.minim.elements;
              const transition = new Transition();
          
              resource.content.push(transition);
          Severity: Major
          Found in src/parser.js - About 2 hrs to fix

            Function convertParameterToElement has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

              convertParameterToElement(parameter, setAttributes = false) {
                const { Array: ArrayElement, Enum: EnumElement } = this.minim.elements;
            
                const Type = this.typeForParameter(parameter);
                const schema = this.schemaForParameterValue(parameter);
            Severity: Minor
            Found in src/parser.js - About 2 hrs to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function convertParameterToElement has 67 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              convertParameterToElement(parameter, setAttributes = false) {
                const { Array: ArrayElement, Enum: EnumElement } = this.minim.elements;
            
                const Type = this.typeForParameter(parameter);
                const schema = this.schemaForParameterValue(parameter);
            Severity: Major
            Found in src/parser.js - About 2 hrs to fix

              Function handleSwaggerExampleResponse has 62 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                handleSwaggerExampleResponse(
                  transaction, methodValue, responseValue,
                  statusCode, responseBody, contentType,
                ) {
                  const { Asset, Copy } = this.minim.elements;
              Severity: Major
              Found in src/parser.js - About 2 hrs to fix

                Function handleSwaggerAuth has 59 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  handleSwaggerAuth() {
                    const { Category, AuthScheme } = this.minim.elements;
                    const schemes = [];
                
                    if (this.swagger.securityDefinitions) {
                Severity: Major
                Found in src/parser.js - About 2 hrs to fix

                  Function handleSwaggerPath has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    handleSwaggerPath(pathValue, href) {
                      const { Copy, Resource } = this.minim.elements;
                      const resource = new Resource();
                  
                      this.withPath('paths', href, () => {
                  Severity: Minor
                  Found in src/parser.js - About 1 hr to fix

                    Function ast has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                      get ast() {
                        if (this.internalAST !== undefined) {
                          return this.internalAST;
                        }
                    
                    
                    Severity: Minor
                    Found in src/parser.js - About 1 hr to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function handleSwaggerInfo has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      handleSwaggerInfo() {
                        const { Copy } = this.minim.elements;
                    
                        if (this.swagger.info) {
                          this.withPath('info', () => {
                    Severity: Minor
                    Found in src/parser.js - About 1 hr to fix

                      Function convertValueToElement has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                        convertValueToElement(value, schema) {
                          const validator = new ZSchema();
                          let element;
                      
                          if (schema.type === 'file') {
                      Severity: Minor
                      Found in src/parser.js - About 1 hr to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function oauthScopes has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        oauthScopes(element, items) {
                          const {
                            Member: MemberElement,
                            Array: ArrayElement,
                            String: StringElement,
                      Severity: Minor
                      Found in src/parser.js - About 1 hr to fix

                        Function ast has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          get ast() {
                            if (this.internalAST !== undefined) {
                              return this.internalAST;
                            }
                        
                        
                        Severity: Minor
                        Found in src/parser.js - About 1 hr to fix

                          Function useResourceGroups has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            useResourceGroups() {
                              const tags = [];
                          
                              if (this.swagger.paths) {
                                _.forEach(this.swagger.paths, (path) => {
                          Severity: Minor
                          Found in src/parser.js - About 1 hr to fix

                            Function parse has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                              parse(done) {
                                const {
                                  Category, ParseResult, SourceMap,
                                } = this.minim.elements;
                                const swaggerParser = new SwaggerParser();
                            Severity: Minor
                            Found in src/parser.js - About 45 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function updateResourceGroup has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              updateResourceGroup(name) {
                                const { Category, Copy } = this.minim.elements;
                            
                                if (name) {
                                  this.group = this.api.find(el => el.element === 'category' && el.classes.contains('resourceGroup') && el.title.toValue() === name).first;
                            Severity: Minor
                            Found in src/parser.js - About 35 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Avoid too many return statements within this function.
                            Open

                                    return done(exception, this.result);
                            Severity: Major
                            Found in src/parser.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                      return _.forEach(paths, (pathValue, href) => {
                                        nextTick(() => {
                                          this.handleSwaggerPath(pathValue, href);
                                          pendingPaths -= 1;
                              
                              
                              Severity: Major
                              Found in src/parser.js - About 30 mins to fix

                                Function oauthTransitions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  oauthTransitions(element, oauth) {
                                    const { Transition } = this.minim.elements;
                                
                                    if (oauth.authorizationUrl) {
                                      const transition = new Transition();
                                Severity: Minor
                                Found in src/parser.js - About 25 mins to fix

                                Cognitive Complexity

                                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                A method's cognitive complexity is based on a few simple rules:

                                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                • Code is considered more complex for each "break in the linear flow of the code"
                                • Code is considered more complex when "flow breaking structures are nested"

                                Further reading

                                Function createSourceMap has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  createSourceMap(element, path, produceLineColumnAttributes) {
                                    if (this.ast) {
                                      const NumberElement = this.minim.elements.Number;
                                      const SourceMap = this.minim.getElementClass('sourceMap');
                                      const position = this.ast.getPosition(path);
                                Severity: Minor
                                Found in src/parser.js - About 25 mins to fix

                                Cognitive Complexity

                                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                A method's cognitive complexity is based on a few simple rules:

                                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                • Code is considered more complex for each "break in the linear flow of the code"
                                • Code is considered more complex when "flow breaking structures are nested"

                                Further reading

                                Function gatherResponseContentTypes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  gatherResponseContentTypes(methodValue, examples) {
                                    let contentTypes = [];
                                
                                    if (examples && Object.keys(examples).length > 0) {
                                      contentTypes = Object.keys(examples);
                                Severity: Minor
                                Found in src/parser.js - About 25 mins to fix

                                Cognitive Complexity

                                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                A method's cognitive complexity is based on a few simple rules:

                                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                • Code is considered more complex for each "break in the linear flow of the code"
                                • Code is considered more complex when "flow breaking structures are nested"

                                Further reading

                                Similar blocks of code found in 2 locations. Consider refactoring.
                                Open

                                    if (oauth.authorizationUrl) {
                                      const transition = new Transition();
                                
                                      transition.relation = 'authorize';
                                      transition.href = oauth.authorizationUrl;
                                Severity: Major
                                Found in src/parser.js and 1 other location - About 5 hrs to fix
                                src/parser.js on lines 530..542

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 149.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 2 locations. Consider refactoring.
                                Open

                                    if (oauth.tokenUrl) {
                                      const transition = new Transition();
                                
                                      transition.relation = 'token';
                                      transition.href = oauth.tokenUrl;
                                Severity: Major
                                Found in src/parser.js and 1 other location - About 5 hrs to fix
                                src/parser.js on lines 516..528

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 149.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 3 locations. Consider refactoring.
                                Open

                                      if (parameter.description) {
                                        element.description = parameter.description;
                                
                                        if (this.generateSourceMap) {
                                          this.createSourceMap(element.meta.get('description'), this.path.concat(['description']));
                                Severity: Major
                                Found in src/parser.js and 2 other locations - About 2 hrs to fix
                                src/parser.js on lines 597..603
                                src/parser.js on lines 1467..1473

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 75.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 3 locations. Consider refactoring.
                                Open

                                          if (item.description) {
                                            element.description = item.description;
                                
                                            if (this.generateSourceMap) {
                                              this.createSourceMap(element.meta.get('description'), this.path.concat(['description']));
                                Severity: Major
                                Found in src/parser.js and 2 other locations - About 2 hrs to fix
                                src/parser.js on lines 1440..1446
                                src/parser.js on lines 1467..1473

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 75.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 3 locations. Consider refactoring.
                                Open

                                    if (parameter.description) {
                                      member.description = parameter.description;
                                
                                      if (this.generateSourceMap) {
                                        this.createSourceMap(member.meta.get('description'), this.path.concat(['description']));
                                Severity: Major
                                Found in src/parser.js and 2 other locations - About 2 hrs to fix
                                src/parser.js on lines 597..603
                                src/parser.js on lines 1440..1446

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 75.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                There are no issues that match your filters.

                                Category
                                Status