Skip to content

Commit

Permalink
feat(schema-builder.ts): added sorting of key on toSchema()
Browse files Browse the repository at this point in the history
  • Loading branch information
ryparker committed Jan 1, 2021
1 parent cf7db91 commit 39e964b
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 161 deletions.
8 changes: 4 additions & 4 deletions examples/schemas/auth.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"maxProperties": 5,
"minProperties": 5,
"properties": {
"username": {
"type": "string",
Expand Down Expand Up @@ -38,7 +40,5 @@
"token_type",
"username"
],
"additionalProperties": false,
"maxProperties": 5,
"minProperties": 5
"type": "object"
}
8 changes: 4 additions & 4 deletions examples/schemas/document.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"maxProperties": 42,
"minProperties": 42,
"properties": {
"id": {
"type": "number",
Expand Down Expand Up @@ -1248,7 +1250,5 @@
"version",
"vet"
],
"additionalProperties": false,
"maxProperties": 42,
"minProperties": 42
"type": "object"
}
8 changes: 4 additions & 4 deletions examples/schemas/profile.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"maxProperties": 6,
"minProperties": 6,
"properties": {
"username": {
"type": "string",
Expand Down Expand Up @@ -62,7 +64,5 @@
"role",
"username"
],
"additionalProperties": false,
"maxProperties": 6,
"minProperties": 6
"type": "object"
}
8 changes: 4 additions & 4 deletions examples/schemas/readme1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"maxProperties": 2,
"minProperties": 2,
"properties": {
"token": {
"type": "string",
Expand All @@ -20,7 +22,5 @@
"role",
"token"
],
"additionalProperties": false,
"maxProperties": 2,
"minProperties": 2
"type": "object"
}
8 changes: 4 additions & 4 deletions examples/schemas/readme2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"maxProperties": 2,
"minProperties": 2,
"properties": {
"token": {
"type": "string",
Expand All @@ -20,7 +22,5 @@
"role",
"token"
],
"additionalProperties": false,
"maxProperties": 2,
"minProperties": 2
"type": "object"
}
10 changes: 5 additions & 5 deletions examples/schemas/readme3.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "/user server response",
"additionalProperties": false,
"description": "/user server response",
"type": "object",
"maxProperties": 2,
"minProperties": 2,
"properties": {
"token": {
"type": "string",
Expand All @@ -22,7 +23,6 @@
"role",
"token"
],
"additionalProperties": false,
"maxProperties": 2,
"minProperties": 2
"title": "/user server response",
"type": "object"
}
8 changes: 4 additions & 4 deletions examples/schemas/user.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"maxProperties": 23,
"minProperties": 23,
"properties": {
"userRole": {
"type": "array",
Expand Down Expand Up @@ -206,7 +208,5 @@
"username",
"vetTechId"
],
"additionalProperties": false,
"maxProperties": 23,
"minProperties": 23
"type": "object"
}
10 changes: 5 additions & 5 deletions examples/schemas/user1&2.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "/user response",
"additionalProperties": false,
"description": "User data from server.",
"type": "object",
"maxProperties": 24,
"minProperties": 23,
"properties": {
"userRole": {
"type": "array",
Expand Down Expand Up @@ -244,7 +245,6 @@
"userRole",
"username"
],
"additionalProperties": false,
"maxProperties": 24,
"minProperties": 23
"title": "/user response",
"type": "object"
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,17 @@
"yargs-parser": "^13.1.2"
},
"dependencies": {
"lodash": "^4.17.20"
"lodash": "^4.17.20",
"sort-keys": "^4.2.0"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@types/lodash": "^4.14.165",
"@types/node": "^14.14.14",
"@types/lodash": "^4.14.167",
"@types/node": "^14.14.19",
"ajv": "6.12.4",
"ava": "^3.14.0",
"ava": "^3.15.0",
"commitizen": "^4.2.2",
"conventional-changelog-conventionalcommits": "^4.5.0",
"cz-conventional-changelog": "3.3.0",
Expand All @@ -109,7 +110,7 @@
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"semantic-release": "^17.3.0",
"semantic-release": "^17.3.1",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"xo": "^0.36.1"
Expand Down
3 changes: 2 additions & 1 deletion src/schema-builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {SchemaNode} from './schema-node';
import sortKeys from 'sort-keys';

export default class SchemaBuilder {
private schemaUri: string;
Expand Down Expand Up @@ -27,7 +28,7 @@ export default class SchemaBuilder {

public toSchema() {
const schema = this.baseSchema();
return {...schema, ...this.rootNode.toSchema()};
return sortKeys({...schema, ...this.rootNode.toSchema()});
}

public toPrettySchema() {
Expand Down
Loading

0 comments on commit 39e964b

Please sign in to comment.