-
Notifications
You must be signed in to change notification settings - Fork 75
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
Added support for operationId and handlers path #204
Open
sgermain06
wants to merge
1
commit into
krakenjs:master
Choose a base branch
from
sgermain06:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -36,10 +36,21 @@ const create = async function (server, { api, basedir, cors, vhost, handlers, ex | |
|
||
for (const [path, operations] of Object.entries(api.paths)) { | ||
const pathnames = Utils.unsuffix(path, '/').split('/').slice(1).join(SEPARATOR); | ||
const hapiHandler = operations['x-hapi-handler']; | ||
|
||
for (const [method, operation] of Object.entries(operations)) { | ||
const pathsearch = `${pathnames}${SEPARATOR}${method}`; | ||
const handler = Hoek.reach(handlers, pathsearch, { separator: SEPARATOR }); | ||
const operationId = operation.operationId; | ||
const hapiHandlerMethod = `${hapiHandler}${SEPARATOR}${method}`; | ||
const hapiHandlerOperationId = `${hapiHandler}${SEPARATOR}${operationId}`; | ||
const pathsearchMethod = `${pathnames}${SEPARATOR}${method}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const pathSearchOperationId = `${pathnames}${SEPARATOR}${operationId}`; | ||
// Give precedence to operationId over method and give precedence to hapiHandler over path. | ||
const handler = | ||
Hoek.reach(handlers, hapiHandlerOperationId, { separator: SEPARATOR }) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we are searching for `xxx/Undefined; most of the time and do a disk access |
||
Hoek.reach(handlers, pathSearchOperationId, { separator: SEPARATOR }) || | ||
Hoek.reach(handlers, hapiHandlerMethod, { separator: SEPARATOR }) || | ||
Hoek.reach(handlers, pathsearchMethod, { separator: SEPARATOR }); | ||
|
||
const xoptions = operation['x-hapi-options'] || {}; | ||
|
||
if (!handler) { | ||
|
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,258 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"version": "1.0.0", | ||
"title": "Swagger Petstore (Simple)", | ||
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", | ||
"termsOfService": "http://helloreverb.com/terms/", | ||
"contact": { | ||
"name": "Swagger API team", | ||
"email": "[email protected]", | ||
"url": "http://swagger.io" | ||
}, | ||
"license": { | ||
"name": "MIT", | ||
"url": "http://opensource.org/licenses/MIT" | ||
} | ||
}, | ||
"host": "petstore.swagger.io", | ||
"basePath": "/v1/petstore", | ||
"schemes": [ | ||
"http" | ||
], | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"paths": { | ||
"/firstPet": { | ||
"x-hapi-handler": "pets", | ||
"get": { | ||
"description": "Returns all pets from the system that the user has access to", | ||
"operationId": "getFirstPet", | ||
"produces": [ | ||
"application/json", | ||
"application/xml", | ||
"text/xml", | ||
"text/html" | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "pet response", | ||
"schema": { | ||
"$ref": "#/definitions/pet" | ||
} | ||
}, | ||
"default": { | ||
"description": "unexpected error", | ||
"schema": { | ||
"$ref": "#/definitions/errorModel" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/pets": { | ||
"x-hapi-handler": "pets", | ||
"get": { | ||
"description": "Returns all pets from the system that the user has access to", | ||
"operationId": "findPets", | ||
"produces": [ | ||
"application/json", | ||
"application/xml", | ||
"text/xml", | ||
"text/html" | ||
], | ||
"parameters": [ | ||
{ | ||
"name": "tags", | ||
"in": "query", | ||
"description": "tags to filter by", | ||
"required": false, | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"collectionFormat": "multi" | ||
}, | ||
{ | ||
"name": "limit", | ||
"in": "query", | ||
"description": "maximum number of results to return", | ||
"required": false, | ||
"type": "integer", | ||
"format": "int32" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "pet response", | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/pet" | ||
} | ||
} | ||
}, | ||
"default": { | ||
"description": "unexpected error", | ||
"schema": { | ||
"$ref": "#/definitions/errorModel" | ||
} | ||
} | ||
} | ||
}, | ||
"post": { | ||
"description": "Creates a new pet in the store. Duplicates are allowed", | ||
"operationId": "addPet", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"parameters": [ | ||
{ | ||
"name": "pet", | ||
"in": "body", | ||
"description": "Pet to add to the store", | ||
"required": true, | ||
"schema": { | ||
"$ref": "#/definitions/newPet" | ||
} | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "pet response", | ||
"schema": { | ||
"$ref": "#/definitions/pet" | ||
} | ||
}, | ||
"default": { | ||
"description": "unexpected error", | ||
"schema": { | ||
"$ref": "#/definitions/errorModel" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/pets/{id}": { | ||
"x-hapi-handler": "pets", | ||
"get": { | ||
"description": "Returns a user based on a single ID, if the user does not have access to the pet", | ||
"operationId": "findPetById", | ||
"produces": [ | ||
"application/json", | ||
"application/xml", | ||
"text/xml", | ||
"text/html" | ||
], | ||
"parameters": [ | ||
{ | ||
"name": "id", | ||
"in": "path", | ||
"description": "ID of pet to fetch", | ||
"required": true, | ||
"type": "integer", | ||
"format": "int64" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "pet response", | ||
"schema": { | ||
"$ref": "#/definitions/pet" | ||
} | ||
}, | ||
"default": { | ||
"description": "unexpected error", | ||
"schema": { | ||
"$ref": "#/definitions/errorModel" | ||
} | ||
} | ||
} | ||
}, | ||
"delete": { | ||
"description": "deletes a single pet based on the ID supplied", | ||
"operationId": "deletePet", | ||
"parameters": [ | ||
{ | ||
"name": "id", | ||
"in": "path", | ||
"description": "ID of pet to delete", | ||
"required": true, | ||
"type": "integer", | ||
"format": "int64" | ||
} | ||
], | ||
"responses": { | ||
"204": { | ||
"description": "pet deleted" | ||
}, | ||
"default": { | ||
"description": "unexpected error", | ||
"schema": { | ||
"$ref": "#/definitions/errorModel" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"pet": { | ||
"type": "object", | ||
"required": [ | ||
"id", | ||
"name" | ||
], | ||
"properties": { | ||
"id": { | ||
"type": "integer", | ||
"format": "int64" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"tag": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"newPet": { | ||
"type": "object", | ||
"required": [ | ||
"name" | ||
], | ||
"properties": { | ||
"id": { | ||
"type": "integer", | ||
"format": "int64" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"tag": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"errorModel": { | ||
"type": "object", | ||
"required": [ | ||
"code", | ||
"message" | ||
], | ||
"properties": { | ||
"code": { | ||
"type": "integer", | ||
"format": "int32" | ||
}, | ||
"message": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the handler in case of x-hapi-handler is already set few lines before, this is probably a bug as we probably wanted precedence of x-hapi-handler over a path but now we do it twice.