Skip to content

Commit 8564c55

Browse files
authored
Merge pull request #297 from JaredCE/fix-apiGateway-schemas
Fix api gateway schemas
2 parents 851e319 + 2331081 commit 8564c55

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-openapi-documenter",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
55
"main": "index.js",
66
"keywords": [
@@ -46,7 +46,7 @@
4646
},
4747
"repository": {
4848
"type": "git",
49-
"url": "https://github.com/JaredCE/serverless-openapi-documenter.git"
49+
"url": "git+https://github.com/JaredCE/serverless-openapi-documenter.git"
5050
},
5151
"bugs": {
5252
"url": "https://github.com/JaredCE/serverless-openapi-documenter/issues"

‎src/definitionGenerator.js‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,10 @@ class DefinitionGenerator {
696696
return obj;
697697
}
698698

699+
schemaExistsInSchemaModels(model, currentContentType) {
700+
return currentContentType === model.name || currentContentType === model?.apiGatewayKey
701+
}
702+
699703
async createMediaTypeObject(models, type) {
700704
const mediaTypeObj = {};
701705
for (const mediaTypeDocumentation of this.schemaHandler.models) {
@@ -706,9 +710,11 @@ class DefinitionGenerator {
706710
}
707711

708712
for (const modelContentType in models) {
709-
let contentKey
713+
let contentKey;
714+
let modelName = mediaTypeDocumentation.name;
710715

711-
if (models[modelContentType] === mediaTypeDocumentation.name) {
716+
if (this.schemaExistsInSchemaModels(mediaTypeDocumentation, models[modelContentType])) {
717+
if (models[modelContentType] === mediaTypeDocumentation?.apiGatewayKey) { modelName = mediaTypeDocumentation.apiGatewayKey; }
712718
contentKey = modelContentType;
713719
}
714720

@@ -742,7 +748,7 @@ class DefinitionGenerator {
742748
}
743749

744750
const schemaRef = await this.schemaHandler
745-
.createSchema(mediaTypeDocumentation.name)
751+
.createSchema(modelName)
746752
.catch((err) => {
747753
throw err;
748754
});

‎src/schemaHandler.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ class SchemaHandler {
7575
const standardisedGatewayModels =
7676
Object.keys(this.apiGatewayModels).flatMap((key) => {
7777
const gatewayModel = this.apiGatewayModels[key];
78-
return standardModel(gatewayModel);
78+
const model = standardModel(gatewayModel);
79+
model.apiGatewayKey = key;
80+
return model;
7981
}) || [];
8082

8183
this.models = standardisedModels.concat(
@@ -86,7 +88,8 @@ class SchemaHandler {
8688

8789
async addModelsToOpenAPI() {
8890
for (const model of this.models) {
89-
const modelName = model.name;
91+
const modelName = model?.apiGatewayKey || model.name;
92+
9093
const schemas = []
9194
if (model.schema) {
9295
// const modelSchema = model.schema;

0 commit comments

Comments
 (0)