APIs-guru/openapi-sampler

View on GitHub

Showing 26 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

      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

            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

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

                export function allOfSample(into, children, options, spec, context) {
                Severity: Minor
                Found in src/allOf.js - About 35 mins to fix

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

                  function defaultSample(min, max, _propertyName, pattern, enablePatterns = false) {
                  Severity: Minor
                  Found in src/samplers/string.js - About 35 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return traverseOneOrAnyOf(schema, firstOneOf)
                    Severity: Major
                    Found in src/traverse.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return (schema.maximum > 0) ? 0 : schema.maximum;
                      Severity: Major
                      Found in src/samplers/number.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return tryInferExample(schema) || allOfSample(
                              { ...schema, allOf: undefined },
                              schema.allOf,
                              options,
                              spec,
                        Severity: Major
                        Found in src/traverse.js - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language