matteozambon89/trailpack-swagger

View on GitHub

Showing 79 of 79 total issues

File SwaggerService.js has 1298 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * @Author: Matteo Zambon <Matteo>
 * @Date:   2017-04-13 06:55:18
 * @Last modified by:   Matteo
 * @Last modified time: 2017-07-30 01:06:47
Severity: Major
Found in api/services/SwaggerService.js - About 3 days to fix

    Function getPathModelByIdAndRelation has 146 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      getPathModelByIdAndRelation(paths, config, doc, modelName, modelRelation) {
        const pathItem = {}
        const pathId = standardBasePath +
                        '/' +
                        modelName.toLowerCase() +
    Severity: Major
    Found in api/services/SwaggerService.js - About 5 hrs to fix

      Function getBasePath has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
      Open

        getBasePath(config) {
          if (config.swagger.basePath) {
            return config.swagger.basePath
          }
          else if (config.footprints && config.footprints.prefix) {
      Severity: Minor
      Found in api/services/SwaggerService.js - About 5 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

      exports has 40 functions (exceeds 20 allowed). Consider refactoring.
      Open

      module.exports = class SwaggerService extends Service {
      
      // Example
      
        extractExampleDirective (propertyExample) {
      Severity: Minor
      Found in api/services/SwaggerService.js - About 5 hrs to fix

        Function getPathModelByIdAndRelationById has 120 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          getPathModelByIdAndRelationById(paths, config, doc, modelName, modelRelation) {
            const pathItem = {}
            const pathId = standardBasePath +
                            '/' +
                            modelName.toLowerCase() +
        Severity: Major
        Found in api/services/SwaggerService.js - About 4 hrs to fix

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

                else if (property.collection && property.through) {
                  const throughFilter = this.getModelNameFromModelMap(property.through)
          
                  prop['type'] = 'array'
                  prop['items'] = {
          Severity: Major
          Found in api/services/SwaggerService.js and 1 other location - About 4 hrs to fix
          api/services/SwaggerService.js on lines 495..554

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

          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 (property.collection && !property.through) {
                  const collectionFilter = this.getModelNameFromModelMap(property.collection)
          
                  prop['type'] = 'array'
                  prop['items'] = {
          Severity: Major
          Found in api/services/SwaggerService.js and 1 other location - About 4 hrs to fix
          api/services/SwaggerService.js on lines 514..554

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

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

            genPropertyExample (propertyExample, modelExample, withRel) {
              let example = null
          
              if (typeof propertyExample === 'string') {
                const directive = this.extractExampleDirective(propertyExample)
          Severity: Minor
          Found in api/services/SwaggerService.js - About 3 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 getResponses has 90 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            getResponses(config, doc) {
              const responses = {}
          
              responses['x-GenericSuccess'] = {
                description: 'Generic Successful Response',
          Severity: Major
          Found in api/services/SwaggerService.js - About 3 hrs to fix

            Function getPathModel has 88 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              getPathModel(paths, config, doc, modelName) {
                const pathItem = {}
                const pathId = standardBasePath + '/' + modelName.toLowerCase()
            
                pathItem.get = {}
            Severity: Major
            Found in api/services/SwaggerService.js - About 3 hrs to fix

              Function getDefinitionModel has 77 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                getDefinitionModel(config, doc, models, modelName) {
                  modelRelations[modelName] = []
                  modelPopulates[modelName] = []
              
                  // Get Models
              Severity: Major
              Found in api/services/SwaggerService.js - About 3 hrs to fix

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

                    pathItem.put.parameters.push({
                      name: 'data',
                      in: 'body',
                      description: 'Data to update a ' + inflect.titleize(modelRelation.property),
                      required: true,
                Severity: Major
                Found in api/services/SwaggerService.js and 2 other locations - About 3 hrs to fix
                api/services/SwaggerService.js on lines 1339..1348
                api/services/SwaggerService.js on lines 1372..1381

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

                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

                    pathItem.put.parameters.push({
                      name: 'data',
                      in: 'body',
                      description: 'Data to update a ' + inflect.titleize(modelRelation.property),
                      required: true,
                Severity: Major
                Found in api/services/SwaggerService.js and 2 other locations - About 3 hrs to fix
                api/services/SwaggerService.js on lines 1339..1348
                api/services/SwaggerService.js on lines 1490..1499

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

                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

                    pathItem.post.parameters.push({
                      name: 'data',
                      in: 'body',
                      description: 'Data to create a new ' + inflect.titleize(modelRelation.property),
                      required: true,
                Severity: Major
                Found in api/services/SwaggerService.js and 2 other locations - About 3 hrs to fix
                api/services/SwaggerService.js on lines 1372..1381
                api/services/SwaggerService.js on lines 1490..1499

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

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

                  getPathModelById(paths, config, doc, modelName) {
                    const pathItem = {}
                    const pathId = standardBasePath + '/' + modelName.toLowerCase() + '/{id}'
                
                    pathItem.get = {}
                Severity: Major
                Found in api/services/SwaggerService.js - About 2 hrs to fix

                  Function getDefinitionModel has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                  Open

                    getDefinitionModel(config, doc, models, modelName) {
                      modelRelations[modelName] = []
                      modelPopulates[modelName] = []
                  
                      // Get Models
                  Severity: Minor
                  Found in api/services/SwaggerService.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

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

                      pathItem.put.parameters.push({
                        name: 'data',
                        in: 'body',
                        description: 'Data to update a ' + inflect.titleize(modelName),
                        required: true,
                  Severity: Major
                  Found in api/services/SwaggerService.js and 2 other locations - About 2 hrs to fix
                  api/services/SwaggerService.js on lines 1132..1141
                  api/services/SwaggerService.js on lines 1152..1161

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

                  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

                      pathItem.post.parameters.push({
                        name: 'data',
                        in: 'body',
                        description: 'Data to create a new ' + inflect.titleize(modelName),
                        required: true,
                  Severity: Major
                  Found in api/services/SwaggerService.js and 2 other locations - About 2 hrs to fix
                  api/services/SwaggerService.js on lines 1152..1161
                  api/services/SwaggerService.js on lines 1224..1233

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

                  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

                      pathItem.put.parameters.push({
                        name: 'data',
                        in: 'body',
                        description: 'Data to create a new ' + inflect.titleize(modelName),
                        required: true,
                  Severity: Major
                  Found in api/services/SwaggerService.js and 2 other locations - About 2 hrs to fix
                  api/services/SwaggerService.js on lines 1132..1141
                  api/services/SwaggerService.js on lines 1224..1233

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

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

                    genResponseObject(httpCode, responseName, description) {
                      const responseObject = {}
                  
                      switch (httpCode) {
                      case '200':
                  Severity: Major
                  Found in api/services/SwaggerService.js - About 2 hrs to fix
                    Severity
                    Category
                    Status
                    Source
                    Language