Skip to content

Commit

Permalink
fix(cli): handle object extensions and literals for json schema (#4961)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Oct 21, 2024
1 parent a381d5f commit 7a5f1c5
Show file tree
Hide file tree
Showing 48 changed files with 1,262 additions and 211 deletions.
9 changes: 9 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
- changelogEntry:
- summary: |
Improved JSON Schema generation for object extensions and const values:
- Object extensions are now properly represented using `allOf` in the JSON Schema
- Literal values (string and boolean) are now correctly represented using `const` in the JSON Schema
type: internal
irVersion: 53
version: 0.45.0-rc9

- changelogEntry:
- summary: |
Add `#!/usr/bin/env node` to the CLI to prevent runtime errors.
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/fern-definition/ir-to-jsonschema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/project-loader": "workspace:*",
"@fern-api/ir-generator": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
"@fern-api/project-loader": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@types/ajv": "^1.0.0",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"json-schema": "^0.4.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"type": "object",
"allOf": [
{
"$ref": "#/definitions/Parent"
}
],
"properties": {
"child": {
"type": "string"
Expand All @@ -8,5 +13,17 @@
"required": [
"child"
],
"definitions": {}
"definitions": {
"Parent": {
"type": "object",
"properties": {
"parent": {
"type": "string"
}
},
"required": [
"parent"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
}
},
"definitions": {
"RootType": {
"type": "object",
"properties": {
"s": {
"type": "string"
}
},
"required": [
"s"
]
},
"a.A": {
"type": "object",
"properties": {}
"allOf": [
{
"$ref": "#/definitions/RootType"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"type": "object",
"properties": {},
"definitions": {}
"allOf": [
{
"$ref": "#/definitions/RootType"
}
],
"definitions": {
"RootType": {
"type": "object",
"properties": {
"s": {
"type": "string"
}
},
"required": [
"s"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"type": "object",
"properties": {},
"definitions": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
}
},
"definitions": {
"RootType": {
"type": "object",
"properties": {
"s": {
"type": "string"
}
},
"required": [
"s"
]
},
"a.A": {
"type": "object",
"properties": {}
"allOf": [
{
"$ref": "#/definitions/RootType"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"type": "object",
"properties": {},
"definitions": {}
"allOf": [
{
"$ref": "#/definitions/RootType"
}
],
"definitions": {
"RootType": {
"type": "object",
"properties": {
"s": {
"type": "string"
}
},
"required": [
"s"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"type": "object",
"properties": {},
"definitions": {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"type": "object",
"properties": {},
"definitions": {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"type": "object",
"properties": {},
"definitions": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
],
"definitions": {
"a.aa.A": {
"type": "object",
"properties": {}
"type": "object"
},
"a.aa.B": {
"type": "object",
"properties": {}
"type": "object"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
],
"definitions": {
"a.aa.A": {
"type": "object",
"properties": {}
"type": "object"
},
"a.aa.B": {
"type": "object",
"properties": {}
"type": "object"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"type": "object",
"allOf": [
{
"$ref": "#/definitions/types.Movie"
}
],
"properties": {
"cast": {
"type": "array",
Expand All @@ -11,5 +16,67 @@
"required": [
"cast"
],
"definitions": {}
"definitions": {
"types.MovieId": {
"type": "string"
},
"commons.types.Tag": {
"type": "string"
},
"types.Movie": {
"type": "object",
"properties": {
"id": {
"$ref": "#/definitions/types.MovieId"
},
"prequel": {
"$ref": "#/definitions/types.MovieId"
},
"title": {
"type": "string"
},
"from": {
"type": "string"
},
"rating": {
"type": "number"
},
"type": {
"const": "movie"
},
"tag": {
"$ref": "#/definitions/commons.types.Tag"
},
"book": {
"type": "string"
},
"metadata": {
"type": "object",
"additionalProperties": {
"type": [
"string",
"number",
"boolean",
"object",
"array",
"null"
]
}
},
"revenue": {
"type": "integer"
}
},
"required": [
"id",
"title",
"from",
"rating",
"type",
"tag",
"metadata",
"revenue"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
"type": "number"
},
"type": {
"const": {
"string": "movie",
"type": "string"
}
"const": "movie"
},
"tag": {
"$ref": "#/definitions/commons.types.Tag"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"type": "object",
"allOf": [
{
"$ref": "#/definitions/Docs"
}
],
"properties": {
"name": {
"type": "string"
Expand All @@ -8,5 +13,17 @@
"required": [
"name"
],
"definitions": {}
"definitions": {
"Docs": {
"type": "object",
"properties": {
"docs": {
"type": "string"
}
},
"required": [
"docs"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"type": "object",
"allOf": [
{
"$ref": "#/definitions/Docs"
}
],
"properties": {
"raw": {
"type": "string"
Expand All @@ -8,5 +13,17 @@
"required": [
"raw"
],
"definitions": {}
"definitions": {
"Docs": {
"type": "object",
"properties": {
"docs": {
"type": "string"
}
},
"required": [
"docs"
]
}
}
}
Loading

0 comments on commit 7a5f1c5

Please sign in to comment.