BigstickCarpet/swagger-express-middleware

View on GitHub

Showing 68 of 68 total issues

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

  if (range) {
    if (parsedValue < range.min || parsedValue > range.max) {
      throw ono({ status: 400 }, '"%s" is not a valid %s. Must be between %d and %d',
        propPath || parsedValue, schema.format, range.min, range.max);
    }
Severity: Major
Found in lib/helpers/json-schema.js and 1 other location - About 1 hr to fix
lib/helpers/json-schema.js on lines 291..296

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

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 (range) {
    if (parsedValue < range.min || parsedValue > range.max) {
      throw ono({ status: 400 }, '"%s" is not a valid %s. Must be between %d and %d',
        propPath || value, schema.format, range.min, range.max);
    }
Severity: Major
Found in lib/helpers/json-schema.js and 1 other location - About 1 hr to fix
lib/helpers/json-schema.js on lines 240..245

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

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 corsHeaders has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function corsHeaders (req, res, next) {
  // Get the default CORS response headers as specified in the Swagger API
  let responseHeaders = getResponseHeaders(req);

  // Set each CORS header
Severity: Minor
Found in lib/cors.js - About 1 hr to fix

    Function mockResponse has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function mockResponse (req, res, next) {
        if (util.isSwaggerRequest(req) && !isDisabled()) {
          let response;
    
          // Is there already a statusCode? (perhaps set by third-party middleware)
    Severity: Minor
    Found in lib/mock/index.js - About 1 hr to fix

      Function http401 has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function http401 (req, res, next) {
        if (util.isSwaggerRequest(req) && req.swagger.security.length > 0) {
          let securityTypes = [];
      
          util.debug("Validating security requirements");
      Severity: Minor
      Found in lib/request-validator.js - About 1 hr to fix

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

        function parseParameter (param, value, schema) {
          if (value === undefined) {
            if (param.required) {
              // The parameter is required, but was not provided, so throw a 400 error
              let errCode = 400;
        Severity: Minor
        Found in lib/param-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 requestMetadata has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        function requestMetadata (context, router) {
          router = router || context.router;
        
          return [
            swaggerMetadata,
        Severity: Minor
        Found in lib/request-metadata.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 deleteCollection has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function deleteCollection (req, res, next, dataStore) {
          dataStore.getCollection(req.path, (err, resources) => {
            if (err) {
              next(err);
            }
        Severity: Minor
        Found in lib/mock/query-collection.js - About 1 hr to fix

          Function sendFile has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function sendFile (req, res, next, file) {
            if (file instanceof Buffer) {
              setContentType(req, res, ["application/octet-stream", "*/*"]);
          
              // `file` is the file's contents
          Severity: Minor
          Found in lib/mock/index.js - About 1 hr to fix

            Function parseFile has a Cognitive Complexity of 11 (exceeds 5 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

            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 Middleware has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            function Middleware (sharedRouter) {
              sharedRouter = util.isExpressRouter(sharedRouter) ? sharedRouter : undefined;
            
              let self = this;
              let context = new MiddlewareContext(sharedRouter);
            Severity: Minor
            Found in lib/middleware.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 getResourceNameByName has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            function getResourceNameByName (data, schema) {
              /** @name PropertyInfo */
              let propInfo = {
                name: "",
                schema: {
            Severity: Minor
            Found in lib/mock/edit-collection.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 generateMultipartFormDataMiddleware has 31 lines of code (exceeds 25 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 1 hr to fix

              Function getResourceNameByName has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function getResourceNameByName (data, schema) {
                /** @name PropertyInfo */
                let propInfo = {
                  name: "",
                  schema: {
              Severity: Minor
              Found in lib/mock/edit-collection.js - About 1 hr to fix

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

                    if (arguments.length === 1 && !util.isExpressRouter(router) && !util.isExpressRoutingOptions(router)) {
                      // Shift arguments
                      options = router;
                      router = sharedRouter;
                    }
                Severity: Major
                Found in lib/middleware.js and 1 other location - About 1 hr to fix
                lib/middleware.js on lines 136..140

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

                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

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

                    if (arguments.length === 1 && !util.isExpressRouter(router) && !util.isExpressRoutingOptions(router)) {
                      // Shift arguments
                      options = router;
                      router = sharedRouter;
                    }
                Severity: Major
                Found in lib/middleware.js and 1 other location - About 1 hr to fix
                lib/middleware.js on lines 87..91

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

                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 queryResource has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function queryResource (req, res, next, dataStore) {
                  let resource = new Resource(req.path);
                
                  dataStore.get(resource, (err, result) => {
                    if (err) {
                Severity: Minor
                Found in lib/mock/query-resource.js - About 1 hr to fix

                  Function sampleDate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function sampleDate (schema) {
                    let min, max;
                    if (schema.minimum !== undefined) {
                      min = parseInt(new Date(schema.minimum).valueOf()) + (schema.exclusiveMinimum ? 1 : 0);
                    }
                  Severity: Minor
                  Found in lib/helpers/json-schema.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 createResources has a Cognitive Complexity of 10 (exceeds 5 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

                  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 http415 has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function http415 (req, res, next) {
                    if (util.isSwaggerRequest(req)) {
                      // Only validate the Content-Type if there's body content
                      if (!_.isEmpty(req.body)) {
                        // Get the MIME types that this operation consumes
                  Severity: Minor
                  Found in lib/request-validator.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

                  Severity
                  Category
                  Status
                  Source
                  Language