File parser.js
has 1198 lines of code (exceeds 250 allowed). Consider refactoring. Open
// The main Swagger parsing component that outputs refract.
import _ from 'lodash';
import { sep } from 'path';
import yaml from 'js-yaml';
Parser
has 46 functions (exceeds 20 allowed). Consider refactoring. Open
export default class Parser {
constructor({ minim, source, generateSourceMap }) {
// Parser options
this.minim = minim;
this.source = source;
Function parse
has 123 lines of code (exceeds 25 allowed). Consider refactoring. Open
parse(done) {
const {
Category, ParseResult, SourceMap,
} = this.minim.elements;
const swaggerParser = new SwaggerParser();
Function handleSwaggerExampleRequest
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleSwaggerExampleRequest(
transaction, methodValue, transitionParams, resourceParams,
requestContentType, responseContentType, contentTypeFromProduces,
) {
let contentType = requestContentType;
Function handleSwaggerMethod
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleSwaggerMethod(resource, href, resourceParams, methodValue, method) {
const { Copy, Transition } = this.minim.elements;
const transition = new Transition();
resource.content.push(transition);
Function convertParameterToElement
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
convertParameterToElement(parameter, setAttributes = false) {
const { Array: ArrayElement, Enum: EnumElement } = this.minim.elements;
const Type = this.typeForParameter(parameter);
const schema = this.schemaForParameterValue(parameter);
- Read upRead up
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 convertParameterToElement
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
convertParameterToElement(parameter, setAttributes = false) {
const { Array: ArrayElement, Enum: EnumElement } = this.minim.elements;
const Type = this.typeForParameter(parameter);
const schema = this.schemaForParameterValue(parameter);
Function handleSwaggerExampleResponse
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleSwaggerExampleResponse(
transaction, methodValue, responseValue,
statusCode, responseBody, contentType,
) {
const { Asset, Copy } = this.minim.elements;
Function handleSwaggerAuth
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleSwaggerAuth() {
const { Category, AuthScheme } = this.minim.elements;
const schemes = [];
if (this.swagger.securityDefinitions) {
Function handleSwaggerPath
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleSwaggerPath(pathValue, href) {
const { Copy, Resource } = this.minim.elements;
const resource = new Resource();
this.withPath('paths', href, () => {
Function ast
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
get ast() {
if (this.internalAST !== undefined) {
return this.internalAST;
}
- Read upRead up
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 handleSwaggerInfo
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleSwaggerInfo() {
const { Copy } = this.minim.elements;
if (this.swagger.info) {
this.withPath('info', () => {
Function convertValueToElement
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
convertValueToElement(value, schema) {
const validator = new ZSchema();
let element;
if (schema.type === 'file') {
- Read upRead up
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 oauthScopes
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
oauthScopes(element, items) {
const {
Member: MemberElement,
Array: ArrayElement,
String: StringElement,
Function ast
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
get ast() {
if (this.internalAST !== undefined) {
return this.internalAST;
}
Function useResourceGroups
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
useResourceGroups() {
const tags = [];
if (this.swagger.paths) {
_.forEach(this.swagger.paths, (path) => {
Function parse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
parse(done) {
const {
Category, ParseResult, SourceMap,
} = this.minim.elements;
const swaggerParser = new SwaggerParser();
- Read upRead up
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 updateResourceGroup
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
updateResourceGroup(name) {
const { Category, Copy } = this.minim.elements;
if (name) {
this.group = this.api.find(el => el.element === 'category' && el.classes.contains('resourceGroup') && el.title.toValue() === name).first;
- Read upRead up
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 too many return
statements within this function. Open
return done(exception, this.result);
Avoid too many return
statements within this function. Open
return _.forEach(paths, (pathValue, href) => {
nextTick(() => {
this.handleSwaggerPath(pathValue, href);
pendingPaths -= 1;
Function oauthTransitions
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
oauthTransitions(element, oauth) {
const { Transition } = this.minim.elements;
if (oauth.authorizationUrl) {
const transition = new Transition();
- Read upRead up
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 createSourceMap
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
createSourceMap(element, path, produceLineColumnAttributes) {
if (this.ast) {
const NumberElement = this.minim.elements.Number;
const SourceMap = this.minim.getElementClass('sourceMap');
const position = this.ast.getPosition(path);
- Read upRead up
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 gatherResponseContentTypes
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
gatherResponseContentTypes(methodValue, examples) {
let contentTypes = [];
if (examples && Object.keys(examples).length > 0) {
contentTypes = Object.keys(examples);
- Read upRead up
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 2 locations. Consider refactoring. Open
if (oauth.authorizationUrl) {
const transition = new Transition();
transition.relation = 'authorize';
transition.href = oauth.authorizationUrl;
- Read upRead up
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 149.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (oauth.tokenUrl) {
const transition = new Transition();
transition.relation = 'token';
transition.href = oauth.tokenUrl;
- Read upRead up
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 149.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
if (parameter.description) {
element.description = parameter.description;
if (this.generateSourceMap) {
this.createSourceMap(element.meta.get('description'), this.path.concat(['description']));
- Read upRead up
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 75.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
if (item.description) {
element.description = item.description;
if (this.generateSourceMap) {
this.createSourceMap(element.meta.get('description'), this.path.concat(['description']));
- Read upRead up
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 75.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
if (parameter.description) {
member.description = parameter.description;
if (this.generateSourceMap) {
this.createSourceMap(member.meta.get('description'), this.path.concat(['description']));
- Read upRead up
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 75.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76