Reputation: 58
I am currently seeking professional solutions for consolidating my JSON schemas. The objective is to retrieve schemas from the resources folder and merge them into a singular schema, while also reconfiguring references using Java.
For instance, I possess multiple schemas, each containing references to other schemas. My objective is to consolidate these schemas, incorporating references with their corresponding definitions during the merging process.
e.g
ClientInTestAlliance.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ClientInTestAlliance",
"description": "Representation of an inTest alliance state. Alliances allow players to join forces and win the Test together. Also called Coalitions in the Test UI.",
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.UltInTestAlliance",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"allianceID": {
"type": "integer",
"description": "The id of the inTest alliance",
"required": true
},
"leaderID": {
"type": "integer",
"description": "The player id of the leader of the inTest alliance",
"required": true
},
"chatCode": {
"type": "string",
"description": "The chat code of the inTest alliance. Used to identify inTest alliance's chat room.",
"required": true
},
"members":{
"type": "object",
"description": "The members of the inTest alliance. The key is the player id of the member.",
"additionalProperties": {
"$ref": "./ClientInTestAllianceMember.json"
},
"required": true,
"existingJavaType": "java.util.Map<Integer, ClientInTestAllianceMember>"
},
"logMessages":{
"type": "array",
"description": "The messages about important events in the inTest alliance, e.g. leader change, member leave, etc. The newest messages are at the end of the list.",
"items": {
"$ref": "./ClientInTestAllianceLogMessage.json"
}
},
"applicants":{
"type": "array",
"description": "The applicants of the inTest alliance.",
"items": {
"$ref": "./ClientInTestAllianceApplicant.json"
}
},
"invitations":{
"type": "array",
"description": "The invitations to the inTest alliance.",
"items": {
"$ref": "./ClientInTestAllianceInvitation.json"
}
}
},
"additionalProperties": false
}
ClientInTestAllianceApplicant.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ClientInTestAllianceApplicant",
"description": "Representation of an inTest alliance applicant",
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.UltInTestAllianceApplicant",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"playerID": {
"type": "integer",
"description": "The player ID of the applicant",
"required": true
},
"timeStamp": {
"type": "integer",
"description": "The timestamp when application was made (in milliseconds since epoch)",
"required": true
}
},
"additionalProperties": false
}
ClientInTestAllianceInvitation.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ClientInTestAllianceInvitation",
"description": "Representation of an alliance invitation",
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.FrontendInTestAllianceInvitation",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"invitingPlayerID": {
"type": "integer",
"descrition": "The ID of the player who sent the invitation",
"required": true
},
"invitedPlayerID": {
"type": "integer",
"description": "The ID of the player who received the invitation",
"required": true
},
"timeStamp": {
"type": "integer",
"description": "The time at which the invitation was sent (in milliseconds since epoch)",
"required": true
}
},
"additionalProperties": false
}
ClientInTestAllianceLogMessage.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ClientInTestAllianceLogMessage",
"description": "Representation of a log message about an alliance action",
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.UltInTestAllianceLogMessage",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"logDate": {
"type": "integer",
"description": "Server time when the action was created (in milliseconds since epoch)",
"required": true
},
"playerID": {
"type": "integer",
"description": "The player who did the action",
"required": true
},
"targetPlayerID": {
"type": "integer",
"description": "The player who was the target of the action. Could be zero if a player left the alliance by himself",
"required": true
},
"inTestAllianceAction": {
"type": "integer",
"description": "The type of action. See the server class UltInTestAllianceAction to know the possible values",
"required": true
}
},
"additionalProperties": false
}
ClientInTestAllianceMember.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ClientInTestAllianceMember",
"description": "Represents a member of an alliance",
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.UltInTestAllianceMember",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"playerID": {
"type": "integer",
"descrition": "The player ID of the member",
"required": true
},
"joinDate": {
"type": "integer",
"description": "The date the member joined the alliance",
"required": true
}
},
"additionalProperties": false
}
and i want output like this
unified_client_json_schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"definitions": {
"UltInGameAlliance": {
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.UltInGameAlliance",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"allianceID": {
"type": "integer",
"description": "The id of the in-game alliance",
"required": true
},
"leaderID": {
"type": "integer",
"description": "The player id of the leader of the in-game alliance",
"required": true
},
"chatCode": {
"type": "string",
"description": "The chat code of the in-game alliance. Used to identify in-game alliance's chat room.",
"required": true
},
"members": {
"type": "object",
"description": "The members of the in-game alliance. The key is the player id of the member.",
"additionalProperties": {
"$ref": "#/definitions/ClientInGameAllianceMember"
},
"required": true,
"existingJavaType": "java.util.Map<Integer, ClientInGameAllianceMember>"
},
"logMessages": {
"type": "array",
"description": "The messages about important events in the in-game alliance, e.g., leader change, member leave, etc. The newest messages are at the end of the list.",
"items": {
"$ref": "#/definitions/ClientInGameAllianceLogMessage"
}
},
"applicants": {
"type": "array",
"description": "The applicants of the in-game alliance.",
"items": {
"$ref": "#/definitions/ClientInGameAllianceApplicant"
}
},
"invitations": {
"type": "array",
"description": "The invitations to the in-game alliance.",
"items": {
"$ref": "#/definitions/ClientInGameAllianceInvitation"
}
}
},
"additionalProperties": false
},
"ClientInGameAllianceApplicant": {
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.UltInGameAllianceApplicant",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"playerID": {
"type": "integer",
"description": "The player ID of the applicant",
"required": true
},
"timeStamp": {
"type": "integer",
"description": "The timestamp when the application was made (in milliseconds since epoch)",
"required": true
}
},
"additionalProperties": false
},
"ClientInGameAllianceInvitation": {
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.FrontendInGameAllianceInvitation",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"invitingPlayerID": {
"type": "integer",
"description": "The ID of the player who sent the invitation",
"required": true
},
"invitedPlayerID": {
"type": "integer",
"description": "The ID of the player who received the invitation",
"required": true
},
"timeStamp": {
"type": "integer",
"description": "The time at which the invitation was sent (in milliseconds since epoch)",
"required": true
}
},
"additionalProperties": false
},
"ClientInGameAllianceLogMessage": {
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.UltInGameAllianceLogMessage",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"logDate": {
"type": "integer",
"description": "Server time when the action was created (in milliseconds since epoch)",
"required": true
},
"playerID": {
"type": "integer",
"description": "The player who did the action",
"required": true
},
"targetPlayerID": {
"type": "integer",
"description": "The player who was the target of the action. Could be zero if a player left the alliance by himself",
"required": true
},
"inGameAllianceAction": {
"type": "integer",
"description": "The type of action. See the server class UltInGameAllianceAction to know the possible values",
"required": true
}
},
"additionalProperties": false
},
"ClientInGameAllianceMember": {
"type": "object",
"properties": {
"@c": {
"type": "string",
"const": "ultshared.UltInGameAllianceMember",
"description": "The class describing the json object",
"required": true,
"javaName": "jsonTypeId"
},
"playerID": {
"type": "integer",
"description": "The player ID of the member",
"required": true
},
"joinDate": {
"type": "integer",
"description": "The date the member joined the alliance",
"required": true
}
},
"additionalProperties": false
}
}
}
Upvotes: 0
Views: 417
Reputation: 3219
if you are using the OpenAPI description as the entry point, Redocly can easily handle this request with their Bundle cli command.
redocly bundle --dereference <openapi.json> --output <path/to/output> --ext json
Upvotes: 0