Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli/generators/openapi/spec-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ function buildMethodSpec(controllerSpec, op, options) {
methodParameters[methodName] = [];
if (parameters) {
parameters.forEach(param => {
methodParameters[methodName].push(param.name);
const {argName} = buildParameter(param, {});
methodParameters[methodName].push(argName);
});
}
if (op.spec.requestBody) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions packages/cli/test/fixtures/openapi/3.0/hyphenated-params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"openapi": "3.0.3",
"info": {
"title": "Hyphenated Properties API",
"version": "1.0.0"
},
"paths": {
"/customers": {
"get": {
"operationId": "getCustomers",
"summary": "List customers",
"parameters": [
{
"name": "limit-number",
"in": "query",
"description": "Maximum number of customers to return",
"required": false,
"schema": {
"type": "integer",
"default": 10
}
},
{
"name": "status-code",
"in": "query",
"description": "Filter by customer status",
"required": false,
"schema": {
"type": "string",
"enum": ["active", "inactive"]
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Customer"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Customer": {
"type": "object",
"properties": {
"customer-id": {
"type": "string",
"example": "cust_001"
},
"first-name": {
"type": "string",
"example": "John"
},
"last-name": {
"type": "string",
"example": "Doe"
}
},
"required": [
"customer-id",
"first-name"
]
}
}
}
}
31 changes: 30 additions & 1 deletion packages/cli/test/unit/openapi/controller-spec.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
const json5 = require('json5');
const {loadAndBuildSpec} = require('../../../generators/openapi/spec-loader');
const path = require('path');

const {expectToMatchSnapshot} = require('../../snapshots');
const assert = require('assert');

describe('openapi to controllers/models', () => {
const customer = path.join(
Expand All @@ -24,3 +24,32 @@ describe('openapi to controllers/models', () => {
);
});
});

describe('openapi to controllers with hyphenated parameters', () => {
const hyphenSpec = path.join(
__dirname,
'../../fixtures/openapi/3.0/hyphenated-params.json',
);

it('generates correct parameter bindings for hyphenated names', async () => {
const spec = await loadAndBuildSpec(hyphenSpec);
const controllerSpecsString = json5.stringify(spec.controllerSpecs);

assert(
controllerSpecsString.includes('limitNumber'),
'Expected controllerSpecsString to include limitNumber',
);
assert(
controllerSpecsString.includes('statusCode'),
'Expected controllerSpecsString to include statusCode',
);
assert(
!controllerSpecsString.includes('limit-number,'),
'Expected controllerSpecsString not to include raw limit-number',
);
assert(
!controllerSpecsString.includes('status-code,'),
'Expected controllerSpecsString not to include raw status-code',
);
});
});
Loading