BigstickCarpet/swagger-express-middleware

View on GitHub

Showing 68 of 68 total issues

Function serveRawSwaggerFiles has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  function serveRawSwaggerFiles (req, res, next) {
    if (req.method === "GET" || req.method === "HEAD") {
      let configPath = getConfiguredPath(options.rawFilesPath);
      configPath = util.normalizePath(configPath, router);
      let reqPath = util.normalizePath(req.path, router);
Severity: Minor
Found in lib/file-server.js - About 1 hr to fix

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

    function parseFile (schema, value, propPath) {
      // Handle missing, required, and default
      value = getValueToValidate(schema, value);
    
      // Parse the value
    Severity: Minor
    Found in lib/helpers/json-schema.js - About 1 hr to fix

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

      function createResources (req) {
        let resources = [],
            body = req.body,
            schema = util.getRequestSchema(req.swagger.path, req.swagger.operation);
      
      
      Severity: Minor
      Found in lib/mock/edit-collection.js - About 1 hr to fix

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

            else {
              // Response body is the entire collection (new, edited, and old)
              dataStore.getCollection(req.path, (err, collection) => {
                res.body = _.map(collection, "data");
                next(err);
        Severity: Major
        Found in lib/mock/edit-collection.js and 1 other location - About 1 hr to fix
        lib/mock/edit-resource.js on lines 118..124

        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 55.

        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

            else if (res.swagger.isCollection) {
              // Response body is the entire collection
              dataStore.getCollection(resource.collection, (err, collection) => {
                res.body = _.map(collection, "data");
                next(err);
        Severity: Major
        Found in lib/mock/edit-resource.js and 1 other location - About 1 hr to fix
        lib/mock/edit-collection.js on lines 353..359

        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 55.

        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

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

        function sampleNumber (schema) {
          let min, max;
          if (schema.minimum !== undefined) {
            min = parseFloat(schema.minimum) + (schema.exclusiveMinimum ? EPSILON : 0);
          }
        Severity: Minor
        Found in lib/helpers/json-schema.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

        Avoid deeply nested control flow statements.
        Open

                    if (req.method === "POST" || req.method === "PUT") {
                      res.status(201);
                    }
                    else if (req.method === "DELETE" && !responses[0].api.schema) {
                      res.status(204);
        Severity: Major
        Found in lib/mock/index.js - About 45 mins to fix

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

            res.swagger.location = _.isArray(req.body) ? collection : resources[0].toString();
          Severity: Minor
          Found in lib/mock/edit-collection.js and 1 other location - About 45 mins to fix
          lib/mock/edit-collection.js on lines 74..74

          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 50.

          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

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

          function generateMultipartFormDataMiddleware (options) {
            options.allowAll = options.allowAll === undefined ? true : options.allowAll;
          
            if (options.inMemory && options.storage === undefined) {
              options.storage = multer.memoryStorage();
          Severity: Minor
          Found in lib/request-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

          Avoid deeply nested control flow statements.
          Open

                        if (req.cookies.swagger === undefined) {
                          res.cookie("swagger", _.uniqueId("random") + _.random(99999999999.9999));
                        }
                        else {
                          res.cookie("swagger", req.cookies.swagger);
          Severity: Major
          Found in lib/mock/index.js - About 45 mins to fix

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

              if (schema.maxItems !== undefined) {
                maxItems = parseInt(schema.maxItems);
              }
              else {
                maxItems = Math.max(50, minItems);
            Severity: Minor
            Found in lib/helpers/json-schema.js and 1 other location - About 45 mins to fix
            lib/helpers/json-schema.js on lines 384..389

            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 50.

            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 (schema.maxLength !== undefined) {
                maxLength = parseInt(schema.maxLength);
              }
              else {
                maxLength = Math.max(50, minLength);
            Severity: Minor
            Found in lib/helpers/json-schema.js and 1 other location - About 45 mins to fix
            lib/helpers/json-schema.js on lines 477..482

            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 50.

            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

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

            function sampleInteger (schema) {
              let min, max;
              if (schema.minimum !== undefined) {
                min = parseInt(schema.minimum) + (schema.exclusiveMinimum ? 1 : 0);
              }
            Severity: Minor
            Found in lib/helpers/json-schema.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 mockResponseBody has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            function mockResponseBody (req, res, next) {
              if (res.swagger) {
                if (res.swagger.isEmpty) {
                  // There is no response schema, so send an empty response
                  util.debug("%s %s does not have a response schema. Sending an empty response", req.method, req.path);
            Severity: Minor
            Found in lib/mock/index.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 merge has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            Resource.prototype.merge = function (other) {
              this.modifiedOn = new Date();
            
              let otherData = other ? other instanceof Resource ? other.data : other : other;
            
            
            Severity: Minor
            Found in lib/data-store/resource.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

            Avoid deeply nested control flow statements.
            Open

                          if (_.isDate(sample)) {
                            res.set(name, util.rfc1123(sample));
                          }
                          else {
                            res.set(name, _(sample).toString());
            Severity: Major
            Found in lib/mock/index.js - About 45 mins to fix

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

                res.swagger.location = _.isArray(req.body) ? collection : resources[0].toString();
              Severity: Minor
              Found in lib/mock/edit-collection.js and 1 other location - About 45 mins to fix
              lib/mock/edit-collection.js on lines 41..41

              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 50.

              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

              Function pathParamMiddleware has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                function pathParamMiddleware (req, res, next, value, name) {
              Severity: Minor
              Found in lib/path-parser.js - About 35 mins to fix

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

                function responseIsCollection (req) {
                  let getter = req.swagger.path.get || req.swagger.path.head;
                  if (getter) {
                    let responses = util.getResponsesBetween(getter, 200, 299);
                    if (responses.length > 0) {
                Severity: Minor
                Found in lib/mock/semantic-request.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

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

                function getValueToValidate (schema, value) {
                  // Is the value empty?
                  if (value === undefined || value === "" ||
                    (schema.type === "object" && _.isObject(value) && _.isEmpty(value))) {
                
                
                Severity: Minor
                Found in lib/helpers/json-schema.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

                Severity
                Category
                Status
                Source
                Language