{"id":16905117,"url":"https://github.com/hyperbrain/serverless-models-plugin","last_synced_at":"2025-03-22T10:31:10.451Z","repository":{"id":78212345,"uuid":"56439416","full_name":"HyperBrain/serverless-models-plugin","owner":"HyperBrain","description":"Model support for Serverless 0.5.x","archived":false,"fork":false,"pushed_at":"2017-05-29T19:21:52.000Z","size":26,"stargazers_count":25,"open_issues_count":4,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T10:21:28.140Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HyperBrain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-17T14:02:39.000Z","updated_at":"2023-11-06T04:46:31.000Z","dependencies_parsed_at":"2023-06-25T22:55:51.241Z","dependency_job_id":null,"html_url":"https://github.com/HyperBrain/serverless-models-plugin","commit_stats":{"total_commits":34,"total_committers":3,"mean_commits":"11.333333333333334","dds":"0.20588235294117652","last_synced_commit":"d25b05e364c6c674876213e90a63730dde766fdb"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HyperBrain%2Fserverless-models-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HyperBrain%2Fserverless-models-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HyperBrain%2Fserverless-models-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HyperBrain%2Fserverless-models-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HyperBrain","download_url":"https://codeload.github.com/HyperBrain/serverless-models-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244943732,"owners_count":20536290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T18:37:14.007Z","updated_at":"2025-03-22T10:31:10.428Z","avatar_url":"https://github.com/HyperBrain.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# serverless-models-plugin\n\n[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)\n\nThis plugin adds the missing model support to Serverless 0.5.x.\n\n## Overview\nThe plugin lets you define your models within your project.\nModels are important as soon as you play around with the mobile SDK's generated by AWS Gateway.\nThey define the typed results or inputs of your API definition and are mapped to classes in\nthe SDK's. One advantage is, that if a model is used in more than one endpoints of your API,\nor a model references other models for its sub-objects, the generated SDK uses exactly the\nsame class definition instance throughout the SDK.\n\nAs soon as you reference them within your endpoint definitions and deploy the endpiont, the needed\nmodels are uploaded to API Gateway. If the model already exists, the definition is updated.\n\n## Installation\n\n1. Install the plugin module\n   `npm install serverless-models-plugin` will install the latest version of the plugin.\n\n   If you want to debug, you also can reference the source repository at a specific version or branch\n   with `npm install https://github.com/HyperBrain/serverless-models-plugin#\u003ctag or branch name\u003e`\n\n2. Activate the plugin in your Serverless project\n   Add `serverless-models-plugin` to the plugins array in your `s-project.json`.\n   ```\n   {\n     \"name\": \"testp1\",\n     \"custom\": {},\n     \"plugins\": [\n       \"serverless-models-plugin\"\n     ]\n   }\n   ```\n\n## Usage\n### Model definition\nWithin anywhere of your Serverless project space you can create a `s-models.json` or `s-models.yaml` (both formats are\nsupported). Within this files define your models ( you can $ref models between s-models files).\n\n```\nfunctions/\n└── function1\n    ├── event.json\n    ├── handler.js\n    ├── s-function.json\n    └── s-models.json\n```\n\n_Example (YAML)_\n```\nmyModelOne:\n  '$schema': 'http://json-schema.org/draft-04/schema#'\n  type: object\n  properties:\n    myProp:\n      type: string\n    myProp2:\n      type: number\nmyModelTwo:\n  '$schema': 'http://json-schema.org/draft-04/schema#'\n  type: array\n  items:\n    type: string\n```\n\n_Example (JSON)_\n```\n{\n  \"myModelOne\": {\n    \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n    \"type\": \"object\",\n    \"properties\": {\n      \"myProp\": {\n        \"type\": \"string\"\n      },\n      \"myProp2\": {\n        \"type\": \"number\"\n      }\n    }\n  },\n  \"myModelTwo\": {\n    \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n    \"type\": \"array\",\n    \"items\": {\n      \"type\": \"string\"\n    }\n  }\n}\n```\n\n#### Model references\nModels can reference other models. You can do this easily by adding `$ref` properties that\nrefer to another defined model. The plugin will take care of including and deploying referenced\nmodels properly.\n\n_Example (YAML)_\n```\nmyModelOne:\n  '$schema': 'http://json-schema.org/draft-04/schema#'\n  type: object\n  properties:\n    myProp:\n      type: string\n    myProp2:\n      type: number\nmyModelTwo:\n  '$schema': 'http://json-schema.org/draft-04/schema#'\n  type: array\n  items:\n    $ref: myModelOne\n```\n\n_Example (JSON)_\n```\n{\n  \"myModelOne\": {\n    \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n    \"type\": \"object\",\n    \"properties\": {\n      \"myProp\": {\n        \"type\": \"string\"\n      },\n      \"myProp2\": {\n        \"type\": \"number\"\n      }\n    }\n  },\n  \"myModelTwo\": {\n    \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n    \"type\": \"array\",\n    \"items\": {\n      \"$ref\": \"myModelOne\"\n    }\n  }\n}\n```\n\n### Using models in endpoints\nIf you want to declare a response (output) or request (input) model for an endpoint, you just have \nto add it to your `s-function.json` accordingly (see requestModels and responseModels properties):\n\n```\n{\n  \"name\": \"testfct2\",\n  \"runtime\": \"nodejs\",\n  \"description\": \"Serverless Lambda function for project: testp1\",\n  \"customName\": false,\n  \"customRole\": false,\n  \"handler\": \"handler.handler\",\n  \"timeout\": 6,\n  \"memorySize\": 1024,\n  \"authorizer\": {},\n  \"custom\": {\n    \"excludePatterns\": []\n  },\n  \"endpoints\": [\n    {\n      \"path\": \"testfct2\",\n      \"method\": \"GET\",\n      \"type\": \"AWS\",\n      \"authorizationType\": \"none\",\n      \"authorizerFunction\": false,\n      \"apiKeyRequired\": false,\n      \"requestParameters\": {},\n      \"requestModels\": {\n        \"application/json\": \"myModelOne\"\n      },\n      \"requestTemplates\": {\n        \"application/json\": \"\"\n      },\n      \"responses\": {\n        \"400\": {\n          \"statusCode\": \"400\"\n        },\n        \"default\": {\n          \"statusCode\": \"200\",\n          \"responseParameters\": {},\n          \"responseModels\": {\n            \"application/json\": \"myModelTwo\"\n          },\n          \"responseTemplates\": {\n            \"application/json\": \"\"\n          }\n        }\n      }\n    }\n  ],\n  \"events\": [],\n  \"environment\": {\n    \"SERVERLESS_PROJECT\": \"${project}\",\n    \"SERVERLESS_STAGE\": \"${stage}\",\n    \"SERVERLESS_REGION\": \"${region}\"\n  },\n  \"vpc\": {\n    \"securityGroupIds\": [],\n    \"subnetIds\": []\n  }\n}\n```\n\n### Helper commands\nThe plugin also adds some new commands to Serverless: `sls models XXXXXX`\n\n#### list\nLists the defined model names\n\n#### show\nShows specified model definitions as JSON or YAML.\nUsage: `sls models show \u003cmodel names\u003e [--format json|yaml]`\n\n#### more to come\n\n## Releases\n\n### 1.1.0\n* s-models.[yaml|json] files are now used throughout the project hierarchy and merged on deploy.\n### 1.0.0\n* Initial release\n\n### 1.0.1\n* Documentation enhancements: issues #1, #2\n\n### 1.1.0\n* Documentation enhancements: issues #9\n* Added support for placing s-models within anywhere of the project's space","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperbrain%2Fserverless-models-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperbrain%2Fserverless-models-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperbrain%2Fserverless-models-plugin/lists"}