APIs-guru/openapi-sampler

View on GitHub

Showing 35 of 35 total issues

Function regexSample has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
Open

export function regexSample(pattern) {
  let isCaseInsensitive = false;

  if (pattern instanceof RegExp) {
    isCaseInsensitive = pattern.flags.includes('i');
Severity: Minor
Found in src/samplers/string-regex.js - About 1 day 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 sampleNumber has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

export function sampleNumber(schema) {
  let res = 0;
  if (schema.type === 'number' && (schema.format === 'float' || schema.format === 'double')) {
    res = 0.1;
  }
Severity: Minor
Found in src/samplers/number.js - About 7 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 traverse has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

export function traverse(schema, options, spec, context) {
  // checking circular JS references by checking context
  // because context is passed only when traversing through nested objects happens
  if (context) {
    if (seenSchemasStack.includes(schema)) return getResultForCircular(inferType(schema));
Severity: Minor
Found in src/traverse.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

Function regexSample has 139 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function regexSample(pattern) {
  let isCaseInsensitive = false;

  if (pattern instanceof RegExp) {
    isCaseInsensitive = pattern.flags.includes('i');
Severity: Major
Found in src/samplers/string-regex.js - About 5 hrs to fix

    Function traverse has 108 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function traverse(schema, options, spec, context) {
      // checking circular JS references by checking context
      // because context is passed only when traversing through nested objects happens
      if (context) {
        if (seenSchemasStack.includes(schema)) return getResultForCircular(inferType(schema));
    Severity: Major
    Found in src/traverse.js - About 4 hrs to fix

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

            for (let i = 65; i <= 90; i++) {
              index = rangeCodes.indexOf(i);
              if (index > -1) {
                rangeCodes.splice(index, 1);
                continue;
      Severity: Major
      Found in src/samplers/string-regex.js and 1 other location - About 2 hrs to fix
      src/samplers/string-regex.js on lines 281..289

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

      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

            for (let i = 48; i <= 57; i++) {
              index = rangeCodes.indexOf(i);
              if (index > -1) {
                rangeCodes.splice(index, 1);
                continue;
      Severity: Major
      Found in src/samplers/string-regex.js and 1 other location - About 2 hrs to fix
      src/samplers/string-regex.js on lines 292..300

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

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

      export function allOfSample(into, children, options, spec, context) {
        let res = traverse(into, options, spec);
        const subSamples = [];
      
        for (let subSchema of children) {
      Severity: Minor
      Found in src/allOf.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 sampleObject has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function sampleObject(schema, options = {}, spec, context) {
        let res = {};
        const depth = (context && context.depth || 1);
      
        if (schema && typeof schema.properties === 'object') {
      Severity: Minor
      Found in src/samplers/object.js - About 1 hr to fix

        Function sampleObject has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        export function sampleObject(schema, options = {}, spec, context) {
          let res = {};
          const depth = (context && context.depth || 1);
        
          if (schema && typeof schema.properties === 'object') {
        Severity: Minor
        Found in src/samplers/object.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 sampleNumber has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function sampleNumber(schema) {
          let res = 0;
          if (schema.type === 'number' && (schema.format === 'float' || schema.format === 'double')) {
            res = 0.1;
          }
        Severity: Minor
        Found in src/samplers/number.js - About 1 hr to fix

          Function exports has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports = function (config) {
              function configureLocalBrowsers() {
                let isMac     = /^darwin/.test(process.platform),
                    isWindows = /^win/.test(process.platform),
                    isLinux   = !(isMac || isWindows);
          Severity: Minor
          Found in karma.conf.js - About 1 hr to fix

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

                pattern =
                  pattern.slice(0, token.index) +
                  token[1].repeat(repetitions) +
                  pattern.slice(token.index + token[0].length);
            Severity: Major
            Found in src/samplers/string-regex.js and 2 other locations - About 1 hr to fix
            src/samplers/string-regex.js on lines 209..212
            src/samplers/string-regex.js on lines 350..353

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

            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 3 locations. Consider refactoring.
            Open

                pattern =
                  pattern.slice(0, token.index) +
                  token[1].repeat(repetitions) +
                  pattern.slice(token.index + token[0].length);
            Severity: Major
            Found in src/samplers/string-regex.js and 2 other locations - About 1 hr to fix
            src/samplers/string-regex.js on lines 209..212
            src/samplers/string-regex.js on lines 338..341

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

            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 3 locations. Consider refactoring.
            Open

                pattern =
                  pattern.slice(0, token.index) +
                  token[1].repeat(repetitions) +
                  pattern.slice(token.index + token[0].length);
            Severity: Major
            Found in src/samplers/string-regex.js and 2 other locations - About 1 hr to fix
            src/samplers/string-regex.js on lines 338..341
            src/samplers/string-regex.js on lines 350..353

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

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

            function getRepetitionsBasedOnQuantifierParameters(
              quantifierSymbol,
              quantifierMin,
              quantifierMax
            ) {
            Severity: Minor
            Found in src/samplers/string-regex.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 getRepetitionsBasedOnQuantifierParameters has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function getRepetitionsBasedOnQuantifierParameters(
              quantifierSymbol,
              quantifierMin,
              quantifierMax
            ) {
            Severity: Minor
            Found in src/samplers/string-regex.js - About 1 hr to fix

              Function inferType has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              export function inferType(schema) {
                if (schema.type !== undefined) {
                  return Array.isArray(schema.type) ? schema.type.length === 0 ? null : schema.type[0] : schema.type;
                }
                const keywords = Object.keys(schemaKeywordTypes);
              Severity: Minor
              Found in src/infer.js - About 55 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 sampleArray has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              export function sampleArray(schema, options = {}, spec, context) {
                const depth = (context && context.depth || 1);
              
                let arrayLength = Math.min(schema.maxItems != undefined ? schema.maxItems : Infinity, schema.minItems || 1);
                // for the sake of simplicity, we're treating `contains` in a similar way to `items`
              Severity: Minor
              Found in src/samplers/array.js - About 55 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 (isCaseInsensitive && isNaN(Number(String.fromCharCode(i)))) {
                          const ch = String.fromCharCode(i);
                          rangeCodes.push(ch.toUpperCase().charCodeAt(0));
                          rangeCodes.push(ch.toLowerCase().charCodeAt(0));
                        } else {
              Severity: Major
              Found in src/samplers/string-regex.js - About 45 mins to fix
                Severity
                Category
                Status
                Source
                Language