Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/prettier #97

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"trailingComma": "es5"
}
8 changes: 2 additions & 6 deletions __tests__/lib/find-schema-definition.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const findSchemaDefinition = require('../../src/lib/find-schema-definition');

test('should throw an error if there is an invalid ref', () => {
expect(() => findSchemaDefinition('some-other-ref', {})).toThrow(
/Could not find a definition for/,
);
expect(() => findSchemaDefinition('some-other-ref', {})).toThrow(/Could not find a definition for/);
});

test('should throw an error if there is a missing ref', () => {
expect(() => findSchemaDefinition('#/components/schemas/user', {})).toThrow(
/Could not find a definition for/,
);
expect(() => findSchemaDefinition('#/components/schemas/user', {})).toThrow(/Could not find a definition for/);
});
12 changes: 6 additions & 6 deletions __tests__/lib/get-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('should return the first type if there is content', () => {
},
},
},
}),
})
).toStrictEqual({ type: 'application/json', schema });

expect(
Expand All @@ -30,7 +30,7 @@ test('should return the first type if there is content', () => {
},
},
},
}),
})
).toStrictEqual({ type: 'text/xml', schema });
});

Expand Down Expand Up @@ -58,8 +58,8 @@ test('should look up the schema if it looks like the first $ref is a request bod
components: {
requestBodies: { schema: { content: { 'application/json': { schema: { $ref } } } } },
},
},
).schema.$ref,
}
).schema.$ref
).toStrictEqual($ref);
});

Expand All @@ -71,7 +71,7 @@ test('should return the inline schema from request body object', () => {
},
{
components: { requestBodies: { schema: { content: { 'application/json': { schema } } } } },
},
).schema,
}
).schema
).toStrictEqual(schema);
});
46 changes: 23 additions & 23 deletions __tests__/lib/parameters-to-json-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('parameter type support and sorting', () => {
expect(
jsonschema.map(js => {
return js.type;
}),
})
).toStrictEqual(['path', 'query', 'cookie', 'formData', 'header']);
});

Expand All @@ -55,7 +55,7 @@ describe('parameter type support and sorting', () => {
expect(
jsonschema.map(js => {
return js.type;
}),
})
).toStrictEqual(['path', 'query', 'body', 'cookie', 'header']);
});
});
Expand All @@ -76,8 +76,8 @@ test('it should work for request body inline (json)', () => {
},
},
},
{},
),
{}
)
).toStrictEqual([
{
label: 'Body Params',
Expand Down Expand Up @@ -108,8 +108,8 @@ test('it should work for request body inline (formData)', () => {
},
},
},
{},
),
{}
)
).toStrictEqual([
{
label: 'Form Data',
Expand Down Expand Up @@ -138,7 +138,7 @@ test('should pass through enum', () => {
},
},
],
}),
})
).toStrictEqual([
{
label: 'Headers',
Expand Down Expand Up @@ -170,7 +170,7 @@ test('should pass through defaults', () => {
},
},
],
}),
})
).toStrictEqual([
{
label: 'Headers',
Expand Down Expand Up @@ -201,7 +201,7 @@ test('it should pass through type for non-body parameters', () => {
},
},
],
})[0].schema.properties.checkbox.type,
})[0].schema.properties.checkbox.type
).toBe('boolean');
});

Expand All @@ -220,7 +220,7 @@ test('it should pass through type for non-body parameters that are arrays', () =
},
},
],
})[0].schema.properties.options.type,
})[0].schema.properties.options.type
).toBe('array');
});

Expand All @@ -237,7 +237,7 @@ test('it should pass through format', () => {
},
},
],
})[0].schema.properties.checkbox.format,
})[0].schema.properties.checkbox.format
).toBe('int32');
});

Expand All @@ -254,7 +254,7 @@ test('it should pass through description', () => {
},
},
],
}),
})
).toStrictEqual([
{
label: 'Headers',
Expand Down Expand Up @@ -289,8 +289,8 @@ test('it should work for top-level request body $ref', () => {
},
},
},
},
),
}
)
).toStrictEqual([
{
type: 'body',
Expand Down Expand Up @@ -339,8 +339,8 @@ test('it should pull out schemas from `components/requestBodies`', () => {
$ref: '#/components/requestBodies/Pet',
},
},
oas,
),
oas
)
).toStrictEqual([
{
type: 'body',
Expand Down Expand Up @@ -370,7 +370,7 @@ test('it should pass false value as default parameter', () => {
},
},
],
})[0].schema.properties.check,
})[0].schema.properties.check
).toStrictEqual({ default: false, type: 'boolean' });
});

Expand All @@ -397,8 +397,8 @@ test('it should fetch $ref parameters', () => {
},
],
},
oas,
)[0].schema.properties.param,
oas
)[0].schema.properties.param
).toStrictEqual(oas.components.parameters.Param.schema);
});

Expand Down Expand Up @@ -431,8 +431,8 @@ test('it should fetch parameters that have a child $ref', () => {
},
],
},
oas,
)[0].schema.properties.param.items,
oas
)[0].schema.properties.param.items
).toStrictEqual(oas.components.schemas.string_enum);
});

Expand All @@ -456,7 +456,7 @@ test('it should add common parameter to path params', () => {
parametersToJsonSchema({
path: '/pet/{petId}',
oas,
})[0].schema.properties.petId.description,
})[0].schema.properties.petId.description
).toBe(oas.paths['/pet/{petId}'].parameters[0].description);
});

Expand Down Expand Up @@ -488,6 +488,6 @@ test('it should override path-level parameters on the operation level', () => {
},
],
oas,
})[0].schema.properties.petId.description,
})[0].schema.properties.petId.description
).toBe('A comma-separated list of pet IDs');
});
12 changes: 4 additions & 8 deletions __tests__/lib/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('utils.js', function() {
},
{
dir: path.join(__dirname, 'fixtures', 'yaml'),
},
}
);
});
});
Expand All @@ -30,7 +30,7 @@ describe('utils.js', function() {
},
{
dir: path.join(__dirname, 'fixtures', 'json'),
},
}
);
});
});
Expand Down Expand Up @@ -58,15 +58,11 @@ describe('utils.js', function() {
});

it('bad json file is not swagger', function() {
expect(utils.isSwagger(path.join(__dirname, 'fixtures', 'yaml', 'notthefile.json'))).toBe(
false,
);
expect(utils.isSwagger(path.join(__dirname, 'fixtures', 'yaml', 'notthefile.json'))).toBe(false);
});

it('bad yaml file is not swagger', function() {
expect(utils.isSwagger(path.join(__dirname, 'fixtures', 'json', 'wrongfile.yaml'))).toBe(
false,
);
expect(utils.isSwagger(path.join(__dirname, 'fixtures', 'json', 'wrongfile.yaml'))).toBe(false);
});
});
});
38 changes: 15 additions & 23 deletions __tests__/oas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,68 +47,60 @@ describe('server variables', () => {
expect(
new Oas({
servers: [{ url: 'https://example.com/{path}', variables: { path: { default: 'path' } } }],
}).url(),
}).url()
).toBe('https://example.com/path');
});

it('should use user variables over defaults', () => {
expect(
new Oas(
{
servers: [
{ url: 'https://{username}.example.com', variables: { username: { default: 'demo' } } },
],
servers: [{ url: 'https://{username}.example.com', variables: { username: { default: 'demo' } } }],
},
{ username: 'domh' },
).url(),
{ username: 'domh' }
).url()
).toBe('https://domh.example.com');
});

it('should fetch user variables from keys array', () => {
expect(
new Oas(
{
servers: [
{ url: 'https://{username}.example.com', variables: { username: { default: 'demo' } } },
],
servers: [{ url: 'https://{username}.example.com', variables: { username: { default: 'demo' } } }],
},
{ keys: [{ name: 1, username: 'domh' }] },
).url(),
{ keys: [{ name: 1, username: 'domh' }] }
).url()
).toBe('https://domh.example.com');
});

it.skip('should fetch user variables from selected app', () => {
expect(
new Oas(
{
servers: [
{ url: 'https://{username}.example.com', variables: { username: { default: 'demo' } } },
],
servers: [{ url: 'https://{username}.example.com', variables: { username: { default: 'demo' } } }],
},
{
keys: [
{ name: 1, username: 'domh' },
{ name: 2, username: 'readme' },
],
},
2,
).url(),
2
).url()
).toBe('https://readme.example.com');
});

// Test encodeURI
it('should pass through if no default set', () => {
expect(new Oas({ servers: [{ url: 'https://example.com/{path}' }] }).url()).toBe(
'https://example.com/{path}',
);
expect(new Oas({ servers: [{ url: 'https://example.com/{path}' }] }).url()).toBe('https://example.com/{path}');
});
});

test('should be able to access properties on oas', () => {
expect(
new Oas({
info: { version: '1.0' },
}).info.version,
}).info.version
).toBe('1.0');
});

Expand All @@ -128,7 +120,7 @@ describe('operation.getSecurity()', () => {
},
})
.operation('/things', 'post')
.getSecurity(),
.getSecurity()
).toBe(security);
});

Expand All @@ -144,7 +136,7 @@ describe('operation.getSecurity()', () => {
security,
})
.operation('/things', 'post')
.getSecurity(),
.getSecurity()
).toBe(security);
});

Expand All @@ -159,7 +151,7 @@ describe('operation.getSecurity()', () => {
},
})
.operation('/things', 'post')
.getSecurity(),
.getSecurity()
).toStrictEqual([]);
});
});
Expand Down
Loading