Spring Boot 将JSON模式合并为一个模式,包括在Java中重写引用

kyks70gy  于 2024-01-06  发布在  Spring
关注(0)|答案(1)|浏览(206)

我目前正在寻求专业的解决方案来整合我的JSON模式。目标是从resources文件夹中检索模式并将其合并为单一模式,同时使用Java重新配置引用。
例如,我拥有多个模式,每个模式都包含对其他模式的引用,我的目标是合并这些模式,在合并过程中将引用与它们相应的定义合并。
例如
ClientInTestAlliance.json

  1. {
  2. "$schema": "https://json-schema.org/draft/2020-12/schema",
  3. "title": "ClientInTestAlliance",
  4. "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.",
  5. "type": "object",
  6. "properties": {
  7. "@c": {
  8. "type": "string",
  9. "const": "ultshared.UltInTestAlliance",
  10. "description": "The class describing the json object",
  11. "required": true,
  12. "javaName": "jsonTypeId"
  13. },
  14. "allianceID": {
  15. "type": "integer",
  16. "description": "The id of the inTest alliance",
  17. "required": true
  18. },
  19. "leaderID": {
  20. "type": "integer",
  21. "description": "The player id of the leader of the inTest alliance",
  22. "required": true
  23. },
  24. "chatCode": {
  25. "type": "string",
  26. "description": "The chat code of the inTest alliance. Used to identify inTest alliance's chat room.",
  27. "required": true
  28. },
  29. "members":{
  30. "type": "object",
  31. "description": "The members of the inTest alliance. The key is the player id of the member.",
  32. "additionalProperties": {
  33. "$ref": "./ClientInTestAllianceMember.json"
  34. },
  35. "required": true,
  36. "existingJavaType": "java.util.Map<Integer, ClientInTestAllianceMember>"
  37. },
  38. "logMessages":{
  39. "type": "array",
  40. "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.",
  41. "items": {
  42. "$ref": "./ClientInTestAllianceLogMessage.json"
  43. }
  44. },
  45. "applicants":{
  46. "type": "array",
  47. "description": "The applicants of the inTest alliance.",
  48. "items": {
  49. "$ref": "./ClientInTestAllianceApplicant.json"
  50. }
  51. },
  52. "invitations":{
  53. "type": "array",
  54. "description": "The invitations to the inTest alliance.",
  55. "items": {
  56. "$ref": "./ClientInTestAllianceInvitation.json"
  57. }
  58. }
  59. },
  60. "additionalProperties": false
  61. }

字符串
ClientInTestAllianceApplicant.json

  1. {
  2. "$schema": "https://json-schema.org/draft/2020-12/schema",
  3. "title": "ClientInTestAllianceApplicant",
  4. "description": "Representation of an inTest alliance applicant",
  5. "type": "object",
  6. "properties": {
  7. "@c": {
  8. "type": "string",
  9. "const": "ultshared.UltInTestAllianceApplicant",
  10. "description": "The class describing the json object",
  11. "required": true,
  12. "javaName": "jsonTypeId"
  13. },
  14. "playerID": {
  15. "type": "integer",
  16. "description": "The player ID of the applicant",
  17. "required": true
  18. },
  19. "timeStamp": {
  20. "type": "integer",
  21. "description": "The timestamp when application was made (in milliseconds since epoch)",
  22. "required": true
  23. }
  24. },
  25. "additionalProperties": false
  26. }


ClientInTestAllianceInvitation.json

  1. {
  2. "$schema": "https://json-schema.org/draft/2020-12/schema",
  3. "title": "ClientInTestAllianceInvitation",
  4. "description": "Representation of an alliance invitation",
  5. "type": "object",
  6. "properties": {
  7. "@c": {
  8. "type": "string",
  9. "const": "ultshared.FrontendInTestAllianceInvitation",
  10. "description": "The class describing the json object",
  11. "required": true,
  12. "javaName": "jsonTypeId"
  13. },
  14. "invitingPlayerID": {
  15. "type": "integer",
  16. "descrition": "The ID of the player who sent the invitation",
  17. "required": true
  18. },
  19. "invitedPlayerID": {
  20. "type": "integer",
  21. "description": "The ID of the player who received the invitation",
  22. "required": true
  23. },
  24. "timeStamp": {
  25. "type": "integer",
  26. "description": "The time at which the invitation was sent (in milliseconds since epoch)",
  27. "required": true
  28. }
  29. },
  30. "additionalProperties": false
  31. }


ClientInTestAllianceLogMessage.json

  1. {
  2. "$schema": "https://json-schema.org/draft/2020-12/schema",
  3. "title": "ClientInTestAllianceLogMessage",
  4. "description": "Representation of a log message about an alliance action",
  5. "type": "object",
  6. "properties": {
  7. "@c": {
  8. "type": "string",
  9. "const": "ultshared.UltInTestAllianceLogMessage",
  10. "description": "The class describing the json object",
  11. "required": true,
  12. "javaName": "jsonTypeId"
  13. },
  14. "logDate": {
  15. "type": "integer",
  16. "description": "Server time when the action was created (in milliseconds since epoch)",
  17. "required": true
  18. },
  19. "playerID": {
  20. "type": "integer",
  21. "description": "The player who did the action",
  22. "required": true
  23. },
  24. "targetPlayerID": {
  25. "type": "integer",
  26. "description": "The player who was the target of the action. Could be zero if a player left the alliance by himself",
  27. "required": true
  28. },
  29. "inTestAllianceAction": {
  30. "type": "integer",
  31. "description": "The type of action. See the server class UltInTestAllianceAction to know the possible values",
  32. "required": true
  33. }
  34. },
  35. "additionalProperties": false
  36. }


ClientInTestAllianceMember.json

  1. {
  2. "$schema": "https://json-schema.org/draft/2020-12/schema",
  3. "title": "ClientInTestAllianceMember",
  4. "description": "Represents a member of an alliance",
  5. "type": "object",
  6. "properties": {
  7. "@c": {
  8. "type": "string",
  9. "const": "ultshared.UltInTestAllianceMember",
  10. "description": "The class describing the json object",
  11. "required": true,
  12. "javaName": "jsonTypeId"
  13. },
  14. "playerID": {
  15. "type": "integer",
  16. "descrition": "The player ID of the member",
  17. "required": true
  18. },
  19. "joinDate": {
  20. "type": "integer",
  21. "description": "The date the member joined the alliance",
  22. "required": true
  23. }
  24. },
  25. "additionalProperties": false
  26. }


我想要这样的输出
unified_client_json_schema.json

  1. {
  2. "$schema": "https://json-schema.org/draft/2020-12/schema",
  3. "definitions": {
  4. "UltInGameAlliance": {
  5. "type": "object",
  6. "properties": {
  7. "@c": {
  8. "type": "string",
  9. "const": "ultshared.UltInGameAlliance",
  10. "description": "The class describing the json object",
  11. "required": true,
  12. "javaName": "jsonTypeId"
  13. },
  14. "allianceID": {
  15. "type": "integer",
  16. "description": "The id of the in-game alliance",
  17. "required": true
  18. },
  19. "leaderID": {
  20. "type": "integer",
  21. "description": "The player id of the leader of the in-game alliance",
  22. "required": true
  23. },
  24. "chatCode": {
  25. "type": "string",
  26. "description": "The chat code of the in-game alliance. Used to identify in-game alliance's chat room.",
  27. "required": true
  28. },
  29. "members": {
  30. "type": "object",
  31. "description": "The members of the in-game alliance. The key is the player id of the member.",
  32. "additionalProperties": {
  33. "$ref": "#/definitions/ClientInGameAllianceMember"
  34. },
  35. "required": true,
  36. "existingJavaType": "java.util.Map<Integer, ClientInGameAllianceMember>"
  37. },
  38. "logMessages": {
  39. "type": "array",
  40. "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.",
  41. "items": {
  42. "$ref": "#/definitions/ClientInGameAllianceLogMessage"
  43. }
  44. },
  45. "applicants": {
  46. "type": "array",
  47. "description": "The applicants of the in-game alliance.",
  48. "items": {
  49. "$ref": "#/definitions/ClientInGameAllianceApplicant"
  50. }
  51. },
  52. "invitations": {
  53. "type": "array",
  54. "description": "The invitations to the in-game alliance.",
  55. "items": {
  56. "$ref": "#/definitions/ClientInGameAllianceInvitation"
  57. }
  58. }
  59. },
  60. "additionalProperties": false
  61. },
  62. "ClientInGameAllianceApplicant": {
  63. "type": "object",
  64. "properties": {
  65. "@c": {
  66. "type": "string",
  67. "const": "ultshared.UltInGameAllianceApplicant",
  68. "description": "The class describing the json object",
  69. "required": true,
  70. "javaName": "jsonTypeId"
  71. },
  72. "playerID": {
  73. "type": "integer",
  74. "description": "The player ID of the applicant",
  75. "required": true
  76. },
  77. "timeStamp": {
  78. "type": "integer",
  79. "description": "The timestamp when the application was made (in milliseconds since epoch)",
  80. "required": true
  81. }
  82. },
  83. "additionalProperties": false
  84. },
  85. "ClientInGameAllianceInvitation": {
  86. "type": "object",
  87. "properties": {
  88. "@c": {
  89. "type": "string",
  90. "const": "ultshared.FrontendInGameAllianceInvitation",
  91. "description": "The class describing the json object",
  92. "required": true,
  93. "javaName": "jsonTypeId"
  94. },
  95. "invitingPlayerID": {
  96. "type": "integer",
  97. "description": "The ID of the player who sent the invitation",
  98. "required": true
  99. },
  100. "invitedPlayerID": {
  101. "type": "integer",
  102. "description": "The ID of the player who received the invitation",
  103. "required": true
  104. },
  105. "timeStamp": {
  106. "type": "integer",
  107. "description": "The time at which the invitation was sent (in milliseconds since epoch)",
  108. "required": true
  109. }
  110. },
  111. "additionalProperties": false
  112. },
  113. "ClientInGameAllianceLogMessage": {
  114. "type": "object",
  115. "properties": {
  116. "@c": {
  117. "type": "string",
  118. "const": "ultshared.UltInGameAllianceLogMessage",
  119. "description": "The class describing the json object",
  120. "required": true,
  121. "javaName": "jsonTypeId"
  122. },
  123. "logDate": {
  124. "type": "integer",
  125. "description": "Server time when the action was created (in milliseconds since epoch)",
  126. "required": true
  127. },
  128. "playerID": {
  129. "type": "integer",
  130. "description": "The player who did the action",
  131. "required": true
  132. },
  133. "targetPlayerID": {
  134. "type": "integer",
  135. "description": "The player who was the target of the action. Could be zero if a player left the alliance by himself",
  136. "required": true
  137. },
  138. "inGameAllianceAction": {
  139. "type": "integer",
  140. "description": "The type of action. See the server class UltInGameAllianceAction to know the possible values",
  141. "required": true
  142. }
  143. },
  144. "additionalProperties": false
  145. },
  146. "ClientInGameAllianceMember": {
  147. "type": "object",
  148. "properties": {
  149. "@c": {
  150. "type": "string",
  151. "const": "ultshared.UltInGameAllianceMember",
  152. "description": "The class describing the json object",
  153. "required": true,
  154. "javaName": "jsonTypeId"
  155. },
  156. "playerID": {
  157. "type": "integer",
  158. "description": "The player ID of the member",
  159. "required": true
  160. },
  161. "joinDate": {
  162. "type": "integer",
  163. "description": "The date the member joined the alliance",
  164. "required": true
  165. }
  166. },
  167. "additionalProperties": false
  168. }
  169. }
  170. }

rlcwz9us

rlcwz9us1#

如果你使用OpenAPI描述作为入口点,Redocly可以很容易地用他们的Bundle命令来处理这个请求。
第一个月

相关问题