Skip to content

Commit

Permalink
fix(): preserve order of properties in schema definition #1277
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Mar 11, 2022
1 parent e96fec3 commit 8b31897
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/storages/type-metadata.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class TypeMetadataStorageHost {
private properties = new Array<PropertyMetadata>();

addPropertyMetadata(metadata: PropertyMetadata) {
this.properties.push(metadata);
this.properties.unshift(metadata);
}

addSchemaMetadata(metadata: SchemaMetadata) {
Expand Down
20 changes: 20 additions & 0 deletions tests/e2e/schema-definitions.factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ class ExampleClass {
describe('DefinitionsFactory', () => {
it('should generate a valid schema definition', () => {
const definition = DefinitionsFactory.createForClass(ExampleClass);

expect(Object.keys(definition)).toEqual([
'objectId',
'name',
'buffer',
'decimal',
'mixed',
'expiresAt',
'map',
'isEnabled',
'number',
'ref',
'child',
'child2',
'nodes',
'customArray',
'customObject',
'any',
'array',
]);
expect(definition).toEqual({
objectId: {
type: mongoose.Schema.Types.ObjectId,
Expand Down

0 comments on commit 8b31897

Please sign in to comment.