-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from natura-cosmeticos/feature/handler-slug-case
feat(handler): added new rule and its handler for resources in paths not using spinal case
- Loading branch information
Showing
14 changed files
with
425 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
openapi: 3.0.1 | ||
servers: | ||
- url: 'https://api.geodatasource.com' | ||
info: | ||
contact: | ||
x-twitter: _geodatasource | ||
description: 'GeoDataSourceâ„¢ Web Service is a REST API enable user to lookup for a city by using latitude and longitude coordinate. It will return the result in either JSON or XML containing the information of country, region, city, latitude and longitude. Visit https://www.geodatasource.com/web-service for further information.' | ||
title: GeoDataSource Location Search | ||
version: '1.0' | ||
x-apisguru-categories: | ||
- location | ||
x-logo: | ||
url: 'https://api.apis.guru/v2/cache/logo/https_twitter.com__geodatasource_profile_image.png' | ||
x-origin: | ||
- converter: | ||
url: 'https://github.com/lucybot/api-spec-converter' | ||
version: 2.7.31 | ||
format: openapi | ||
url: 'https://app.swaggerhub.com/apiproxy/schema/file/geodatasource/geodatasource-location-search/1.0/swagger.yaml' | ||
version: '3.0' | ||
x-preferred: true | ||
x-providerName: geodatasource.com | ||
paths: | ||
/city-with-spinal-case: | ||
get: | ||
description: Get City name by using latitude and longitude | ||
parameters: | ||
- in: query | ||
name: key | ||
required: true | ||
schema: | ||
type: string | ||
- in: query | ||
name: lng | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: lat | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: format | ||
schema: | ||
enum: | ||
- json | ||
- xml | ||
type: string | ||
responses: | ||
'200': | ||
content: | ||
application/json; charset=utf-8: | ||
examples: | ||
'0': | ||
value: '{"country":"","region":"","city":"","latitude":"","longitude":""}' | ||
schema: | ||
type: string | ||
description: Get response from longitude latitude lookup |
95 changes: 95 additions & 0 deletions
95
src/__tests__/data/without-spinal-case-once-two-path/swagger.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
openapi: 3.0.1 | ||
servers: | ||
- url: "https://api.geodatasource.com/v1/abc/123/test" | ||
info: | ||
contact: | ||
x-twitter: _geodatasource | ||
description: "GeoDataSourceâ„¢ Web Service is a REST API enable user to lookup for a city by using latitude and longitude coordinate. It will return the result in either JSON or XML containing the information of country, region, city, latitude and longitude. Visit https://www.geodatasource.com/web-service for further information." | ||
title: GeoDataSource Location Search | ||
version: "1.0" | ||
x-apisguru-categories: | ||
- location | ||
x-logo: | ||
url: "https://api.apis.guru/v2/cache/logo/https_twitter.com__geodatasource_profile_image.png" | ||
x-origin: | ||
- converter: | ||
url: "https://github.com/lucybot/api-spec-converter" | ||
version: 2.7.31 | ||
format: openapi | ||
url: "https://app.swaggerhub.com/apiproxy/schema/file/geodatasource/geodatasource-location-search/1.0/swagger.yaml" | ||
version: "3.0" | ||
x-preferred: true | ||
x-providerName: geodatasource.com | ||
paths: | ||
/pathWithoutSpinalCase: | ||
get: | ||
description: Get City name by using latitude and longitude | ||
parameters: | ||
- in: query | ||
name: key | ||
required: true | ||
schema: | ||
type: string | ||
- in: query | ||
name: lng | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: lat | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: format | ||
schema: | ||
enum: | ||
- json | ||
- xml | ||
type: string | ||
responses: | ||
"200": | ||
content: | ||
application/json; charset=utf-8: | ||
examples: | ||
"0": | ||
value: '{"country":"","region":"","city":"","latitude":"","longitude":""}' | ||
schema: | ||
type: string | ||
description: Get response from longitude latitude lookup | ||
/anotherPathWithoutSpinalCase: | ||
get: | ||
description: Get City name by using latitude and longitude | ||
parameters: | ||
- in: query | ||
name: key | ||
required: true | ||
schema: | ||
type: string | ||
- in: query | ||
name: lng | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: lat | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: format | ||
schema: | ||
enum: | ||
- json | ||
- xml | ||
type: string | ||
responses: | ||
"200": | ||
content: | ||
application/json; charset=utf-8: | ||
examples: | ||
"0": | ||
value: '{"country":"","region":"","city":"","latitude":"","longitude":""}' | ||
schema: | ||
type: string | ||
description: Get response from longitude latitude lookup |
59 changes: 59 additions & 0 deletions
59
src/__tests__/data/without-spinal-case-twice-one-path/swagger.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
openapi: 3.0.1 | ||
servers: | ||
- url: 'https://api.geodatasource.com/v1/abc/123/test' | ||
info: | ||
contact: | ||
x-twitter: _geodatasource | ||
description: 'GeoDataSourceâ„¢ Web Service is a REST API enable user to lookup for a city by using latitude and longitude coordinate. It will return the result in either JSON or XML containing the information of country, region, city, latitude and longitude. Visit https://www.geodatasource.com/web-service for further information.' | ||
title: GeoDataSource Location Search | ||
version: '1.0' | ||
x-apisguru-categories: | ||
- location | ||
x-logo: | ||
url: 'https://api.apis.guru/v2/cache/logo/https_twitter.com__geodatasource_profile_image.png' | ||
x-origin: | ||
- converter: | ||
url: 'https://github.com/lucybot/api-spec-converter' | ||
version: 2.7.31 | ||
format: openapi | ||
url: 'https://app.swaggerhub.com/apiproxy/schema/file/geodatasource/geodatasource-location-search/1.0/swagger.yaml' | ||
version: '3.0' | ||
x-preferred: true | ||
x-providerName: geodatasource.com | ||
paths: | ||
/pathWithoutSpinalCase/anotherPathWithoutSpinalCase: | ||
get: | ||
description: Get City name by using latitude and longitude | ||
parameters: | ||
- in: query | ||
name: key | ||
required: true | ||
schema: | ||
type: string | ||
- in: query | ||
name: lng | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: lat | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: format | ||
schema: | ||
enum: | ||
- json | ||
- xml | ||
type: string | ||
responses: | ||
'200': | ||
content: | ||
application/json; charset=utf-8: | ||
examples: | ||
'0': | ||
value: '{"country":"","region":"","city":"","latitude":"","longitude":""}' | ||
schema: | ||
type: string | ||
description: Get response from longitude latitude lookup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
openapi: 3.0.1 | ||
servers: | ||
- url: 'https://api.geodatasource.com/v1/abc/123/test' | ||
info: | ||
contact: | ||
x-twitter: _geodatasource | ||
description: 'GeoDataSourceâ„¢ Web Service is a REST API enable user to lookup for a city by using latitude and longitude coordinate. It will return the result in either JSON or XML containing the information of country, region, city, latitude and longitude. Visit https://www.geodatasource.com/web-service for further information.' | ||
title: GeoDataSource Location Search | ||
version: '1.0' | ||
x-apisguru-categories: | ||
- location | ||
x-logo: | ||
url: 'https://api.apis.guru/v2/cache/logo/https_twitter.com__geodatasource_profile_image.png' | ||
x-origin: | ||
- converter: | ||
url: 'https://github.com/lucybot/api-spec-converter' | ||
version: 2.7.31 | ||
format: openapi | ||
url: 'https://app.swaggerhub.com/apiproxy/schema/file/geodatasource/geodatasource-location-search/1.0/swagger.yaml' | ||
version: '3.0' | ||
x-preferred: true | ||
x-providerName: geodatasource.com | ||
paths: | ||
/pathWithoutSpinalCase: | ||
get: | ||
description: Get City name by using latitude and longitude | ||
parameters: | ||
- in: query | ||
name: key | ||
required: true | ||
schema: | ||
type: string | ||
- in: query | ||
name: lng | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: lat | ||
required: true | ||
schema: | ||
type: number | ||
- in: query | ||
name: format | ||
schema: | ||
enum: | ||
- json | ||
- xml | ||
type: string | ||
responses: | ||
'200': | ||
content: | ||
application/json; charset=utf-8: | ||
examples: | ||
'0': | ||
value: '{"country":"","region":"","city":"","latitude":"","longitude":""}' | ||
schema: | ||
type: string | ||
description: Get response from longitude latitude lookup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import path from 'path'; | ||
import { parse } from '../../../index'; | ||
import { resourceSpinalCase } from '../../../rules/handlers/resource-spinal-case'; | ||
import { RuleFault } from '../../../rules/rule-fault'; | ||
|
||
describe('resourceSpinalCase function', () => { | ||
const apiWithoutErrors = path.join(__dirname, '..', '..', 'data', 'openapi-3.0', 'swagger.yml'); | ||
const apiWithSpinalCase = path.join(__dirname, '..', '..', 'data', 'with-spinal-case', 'swagger.yml'); | ||
const apiWithOneFaultAndOneError = path.join(__dirname, '..', '..', 'data', 'without-spinal-case', 'swagger.yml'); | ||
const apiWithOneFaultAndTwoErrors = path.join(__dirname, '..', '..', 'data', 'without-spinal-case-twice-one-path', 'swagger.yml'); | ||
const apiWithTwoFaultsOneErrorEach = path.join(__dirname, '..', '..', 'data', 'without-spinal-case-once-two-path', 'swagger.yml'); | ||
|
||
|
||
it('should have no faults', async () => { | ||
const faults: RuleFault[] = []; | ||
|
||
const api = await parse(apiWithoutErrors); | ||
|
||
resourceSpinalCase(api, faults); | ||
|
||
expect(faults.length).toBe(0); | ||
}); | ||
|
||
it('should have no faults with spinal case', async () => { | ||
const faults: RuleFault[] = []; | ||
|
||
const api = await parse(apiWithSpinalCase); | ||
|
||
resourceSpinalCase(api, faults); | ||
|
||
expect(faults.length).toBe(0); | ||
}); | ||
|
||
it('should have one fault with one error', async () => { | ||
const faults: RuleFault[] = []; | ||
|
||
const api = await parse(apiWithOneFaultAndOneError); | ||
|
||
resourceSpinalCase(api, faults); | ||
|
||
expect(faults.length).toBe(1); | ||
expect(faults[0].errors.length).toBe(1); | ||
}); | ||
|
||
it('should have one fault with two errors', async () => { | ||
const faults: RuleFault[] = []; | ||
|
||
const api = await parse(apiWithOneFaultAndTwoErrors); | ||
|
||
resourceSpinalCase(api, faults); | ||
|
||
expect(faults.length).toBe(1); | ||
expect(faults[0].errors.length).toBe(2); | ||
}); | ||
|
||
it('should have two faults with one error each', async () => { | ||
const faults: RuleFault[] = []; | ||
|
||
const api = await parse(apiWithTwoFaultsOneErrorEach); | ||
|
||
resourceSpinalCase(api, faults); | ||
|
||
expect(faults.length).toBe(2); | ||
expect(faults[0].errors.length).toBe(1); | ||
expect(faults[1].errors.length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.