serverless-openapi-documentation
serverless-openapi-documentation copied to clipboard
requestBody and requestModels not being generated.
i try to follow the example in the documentation. But i cant get the requestBody
, and requestModels
to generated in the documentation file.
service: hasuraLambda # NOTE: update this with your service name
provider:
name: aws
runtime: nodejs8.10
stage: ekyc-testing
region: ap-southeast-1
custom:
documentation:
version: '1.0.0'
title: 'EKMC API'
description: 'This APIs are EKYC and EKYM service serve for client.'
models:
- name: SuccessResponse
contentType: "application/json"
schema:
$schema: "http://json-schema.org/draft-04/schema#"
type: object
properties:
statusCode:
type: integer
message:
type: string
body:
type: object
- name: FailureResponse
contentType: "application/json"
schema:
$schema: "http://json-schema.org/draft-04/schema#"
type: object
properties:
statusCode:
type: integer
message:
type: string
body:
type: object
- name: EkycPostRequest
contentType: "application/json"
schema:
$schema: "http://json-schema.org/draft-04/schema#"
type: object
properties:
firstName:
type: string
lastName:
type: string
status:
type: string
functions:
ekyc-post:
handler: functions/Ekyc/post.handler
events:
- http:
path: ekyc
method: post
documentation:
tags: ['ekyc']
summary: "Post new record to server."
requestBody:
description: "Can insert an empty object. This will still create a new record inside the server."
requestModels:
application/json: "EkycPostRequest"
methodResponses:
- statusCode: '200'
responseBody:
description: "Successfully created new ekyc record in server."
responseModels:
application/json: SuccessResponse
- statusCode: '500'
responseBody:
description: "Can't create new ekyc record in server."
responseModels:
application/json: FailureResponse
plugins:
- serverless-offline
- serverless-mocha-plugin
- serverless-openapi-documentation
im not sure what went wrong. but the responseModels
work just fine.
THe project is kinda dead, and this bug has been reported couple of times but fixes are not approved and merged back. So there are couple of efforts to fix this issue and other issues in different folks.
The one I just created have this issue and other issues fixed. Please try it out :
https://github.com/kzhou57/serverless-openapi-documentation
And you can also the modify the package.json to point direct from my version :
"serverless-openapi-documentation": "github:kzhou57/serverless-openapi-documentation",
Thank you so much. It works like a clock now.
Glad it helps you .
@kzhou57 hi...so this solved things on my Mac machine. And im really grateful to u for that. But now i just got new laptop, and try to clone my repo back. When i run npm install
or yarn install
. Everything seems to work fine. But when i try starting my serverless application it gives me errors
Serverless Error ---------------------------------------
Serverless plugin "serverless-openapi-documentation" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file.
Stack Trace --------------------------------------------
ServerlessError: Serverless plugin "serverless-openapi-documentation" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file.
at plugins.forEach (C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\lib\classes\PluginManager.js:125:17)
at Array.forEach (<anonymous>)
at PluginManager.loadPlugins (C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\lib\classes\PluginManager.js:98:13)
at PluginManager.loadServicePlugins (C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\lib\classes\PluginManager.js:151:10)
at PluginManager.loadAllPlugins (C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\lib\classes\PluginManager.js:94:10)
at pluginManager.loadConfigFile.then.then (C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\lib\Serverless.js:72:26)
From previous event:
at Serverless.init (C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\lib\Serverless.js:70:8)
at initializeErrorReporter.then (C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\bin\serverless:42:21)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:120:23)
From previous event:
at C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\bin\serverless:28:46
at Object.<anonymous> (C:\Users\miike\Desktop\CRM-Node\node_modules\serverless\bin\serverless:65:4)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
OS: win32
Node Version: 10.15.3
Serverless Version: 1.41.1
Im not sure why this is happening. Looks like there's a conflict between the plugins. If i erase the plugin from package.json, and readded the official one. I can run the application just fine. This happened on both my linux and window 10.
Hi Mike,
it probably related to the npm version , the line
"serverless-openapi-documentation": "github:kzhou57/serverless-openapi-documentation",
in package json is requiring a version of npm > 5.0 .
Unfortunately if the npm didn't install my patch version correctly, it didn't report a failure, so later on when serverless trying to call the plugin, it said not found.
Please check the npm version,
npm -v will tell you.
my npm version is 6.9.0. and node is 10.15.3.
hmmm, it's interesting, can you check in your node_modules folder, does this file exists ?
node_modules/serverless-openapi-documentation/dist/index.js
The issue usually the error 'Serverless plugin "serverless-openapi-documentation" not found.' means node cannot find the installed package as a valid node component. If the above file not exists, it means it's the npm problem, which should compile the type script from github and setup the package correctly.
If the file exists, then it's a problem somewhere else.
i guess ure rite. I cant find the index.js. the compilation from typescript must've gone wrong somehow.
i think i figured out the problem. npm cant compile the source typescript file until i install typescript
as global npm package. Once i installed typescript
package, npm install
would install the package correctly, and compile the scripts in my linux. But on Window, it doesnt auto compiled. i have to go into the node_modules/serverless-openapi-documentation
and run tsc
command manually to compile souce files.
I am glad you figured it out.
@kzhou57 @Mike-Van
I fork your repo and i replaced yarn with npm because i had build issues building on server and i didnt want to install yarn.
I also published the package as serverless-openapi-documentation-v2
Cheers