Skip to content

Commit

Permalink
Merge e52e57a into f09d866
Browse files Browse the repository at this point in the history
  • Loading branch information
appcoders committed Dec 13, 2018
2 parents f09d866 + e52e57a commit 0d2c0d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/cli/generators/openapi/schema-helper.js
Expand Up @@ -160,7 +160,13 @@ function mapObjectType(schema, options) {
);
// The property name might have chars such as `-`
const propName = escapePropertyOrMethodName(p);

let propDecoration = `@property({name: '${p}'})`;

if (required.includes(p)) {
propDecoration = `@property({name: '${p}', required: true})`;
}

if (propertyType.itemType && propertyType.itemType.kind === 'class') {
// Use `@property.array` for array types
propDecoration = `@property.array(${
Expand Down
Expand Up @@ -71,7 +71,10 @@ describe('openapi-generator specific files', function() {
assert.file(newPetModel);
assert.fileContent(newPetModel, `export class NewPet {`);
assert.fileContent(newPetModel, `@model({name: 'NewPet'})`);
assert.fileContent(newPetModel, `@property({name: 'name'})`);
assert.fileContent(
newPetModel,
`@property({name: 'name', required: true})`,
);
assert.fileContent(newPetModel, `name: string;`);
assert.fileContent(newPetModel, `@property({name: 'tag'})`);
assert.fileContent(newPetModel, `tag?: string`);
Expand Down
Expand Up @@ -69,7 +69,10 @@ describe('openapi-generator specific files', () => {
assert.fileContent(newPetModel, `export class NewPet {`);
assert.fileContent(newPetModel, `constructor(data?: Partial<NewPet>) {`);
assert.fileContent(newPetModel, `@model({name: 'NewPet'})`);
assert.fileContent(newPetModel, `@property({name: 'name'})`);
assert.fileContent(
newPetModel,
`@property({name: 'name', required: true})`,
);
assert.fileContent(newPetModel, `name: string;`);
assert.fileContent(newPetModel, `@property({name: 'tag'})`);
assert.fileContent(newPetModel, `tag?: string`);
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/test/unit/openapi/schema-model.unit.js
Expand Up @@ -109,7 +109,7 @@ describe('schema to model', () => {
{
name: 'criteria',
signature: "criteria: string = '*:*';",
decoration: "@property({name: 'criteria'})",
decoration: "@property({name: 'criteria', required: true})",
description:
'Uses Lucene Query Syntax in the format of propertyName:value, ' +
'propertyName:[num1 TO num2] and date range format: ' +
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('schema to model', () => {
{
name: 'name',
signature: 'name: string;',
decoration: "@property({name: 'name'})",
decoration: "@property({name: 'name', required: true})",
},
{
name: 'tag',
Expand All @@ -208,7 +208,7 @@ describe('schema to model', () => {
{
name: 'id',
signature: 'id: number;',
decoration: "@property({name: 'id'})",
decoration: "@property({name: 'id', required: true})",
},
],
signature: '{\n id: number;\n}',
Expand All @@ -228,7 +228,7 @@ describe('schema to model', () => {
{
name: 'name',
signature: 'name: string;',
decoration: "@property({name: 'name'})",
decoration: "@property({name: 'name', required: true})",
},
{
name: 'tag',
Expand All @@ -251,12 +251,12 @@ describe('schema to model', () => {
{
name: 'code',
signature: 'code: number;',
decoration: "@property({name: 'code'})",
decoration: "@property({name: 'code', required: true})",
},
{
name: 'message',
signature: 'message: string;',
decoration: "@property({name: 'message'})",
decoration: "@property({name: 'message', required: true})",
},
],
imports: [],
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('schema to model', () => {
{
name: 'id',
signature: 'id: number;',
decoration: "@property({name: 'id'})",
decoration: "@property({name: 'id', required: true})",
},
{
name: 'first-name',
Expand Down

0 comments on commit 0d2c0d1

Please sign in to comment.