Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feature): Add support for default values and validation rules #3640

Merged
merged 23 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a27eaa9
(feature): Add support for default values and validation rules
amckinney May 16, 2024
41f277b
fix fern.schema.json
abvthecity May 17, 2024
5f5439b
Refactor with default/validation on every type reference
amckinney May 17, 2024
63616cc
Fix example validation and update snapshots
amckinney May 17, 2024
f78e9b3
Add better validation test definition
amckinney May 17, 2024
e095e11
Fix OpenAPI -> Fern IR for optionals
amckinney May 17, 2024
876b660
Fix aliases and unions
amckinney May 17, 2024
bdddcd0
Add validation rules on alias
amckinney May 17, 2024
6996cbb
Pick out the default property for type aliases
amckinney May 17, 2024
56d0679
Add another test for OpenAPI aliases
amckinney May 17, 2024
bfefba4
Update snapshots with latest behavior
amckinney May 17, 2024
9fe9dd8
Run 'yarn format:fix'
amckinney May 17, 2024
27393c4
Improve 'fern write-definition' output format
amckinney May 17, 2024
0ac59de
Update JSON schema files
amckinney May 17, 2024
5e83f88
Add validation test definition to all seed generators
amckinney May 17, 2024
4ae2ecc
Merge branch 'main' into amckinney/validation
amckinney May 17, 2024
dab0b5b
Update ruby-model and java-sdk snapshots
amckinney May 17, 2024
a3f5be7
Add 'fern check' rule
amckinney May 20, 2024
7e20d6d
Refactor 'fern write-definition' to exclude default and validation
amckinney May 20, 2024
e695553
Add explicit check for file, bytes, and text
amckinney May 20, 2024
5ad7c5e
Merge branch 'main' into amckinney/validation
amckinney May 20, 2024
e53200b
Fix 'fern check' rule
amckinney May 20, 2024
3df35e5
Update seed snapshots
amckinney May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 42 additions & 1 deletion fern.schema.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@
"type": "object",
"properties": {
"type": { "type": "string" },
"default": {},
"validation": {
"anyOf": [
{
"type": "object",
"properties": {
"minLength": { "type": "number" },
"maxLength": { "type": "number" },
"pattern": { "type": "string" },
"format": { "type": "string" }
},
"additionalProperties": false
},
{
"type": "object",
"properties": {
"min": { "type": "number" },
"max": { "type": "number" },
"exclusiveMin": { "type": "boolean" },
"exclusiveMax": { "type": "boolean" },
"multipleOf": { "type": "number" }
},
"additionalProperties": false
}
]
},
"docs": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs"
},
Expand Down Expand Up @@ -210,7 +236,10 @@
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/audiences"
},
"examples": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/examples" },
"type": { "type": "string" }
"type": { "type": "string" },
"validation": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties/anyOf/1/properties/validation"
}
},
"required": ["type"],
"additionalProperties": false
Expand Down Expand Up @@ -322,6 +351,10 @@
"type": "object",
"properties": {
"type": { "type": "string" },
"default": {},
"validation": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties/anyOf/1/properties/validation"
},
"docs": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs" }
},
"required": ["type"],
Expand Down Expand Up @@ -352,6 +385,10 @@
"type": "object",
"properties": {
"type": { "type": "string" },
"default": {},
"validation": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties/anyOf/1/properties/validation"
},
"docs": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs" },
"availability": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/availability"
Expand Down Expand Up @@ -413,6 +450,10 @@
"type": "object",
"properties": {
"type": { "type": "string" },
"default": {},
"validation": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties/anyOf/1/properties/validation"
},
"docs": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs"
},
Expand Down
104 changes: 94 additions & 10 deletions fern.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@
"type": "object",
"properties": {
"type": { "type": "string" },
"default": {},
"validation": {
"anyOf": [
{
"type": "object",
"properties": {
"minLength": { "type": "number" },
"maxLength": { "type": "number" },
"pattern": { "type": "string" },
"format": { "type": "string" }
},
"additionalProperties": false
},
{
"type": "object",
"properties": {
"min": { "type": "number" },
"max": { "type": "number" },
"exclusiveMin": { "type": "boolean" },
"exclusiveMax": { "type": "boolean" },
"multipleOf": { "type": "number" }
},
"additionalProperties": false
}
]
},
"docs": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs"
},
Expand Down Expand Up @@ -210,7 +236,10 @@
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/audiences"
},
"examples": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/examples" },
"type": { "type": "string" }
"type": { "type": "string" },
"validation": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties/anyOf/1/properties/validation"
}
},
"required": ["type"],
"additionalProperties": false
Expand Down Expand Up @@ -322,6 +351,10 @@
"type": "object",
"properties": {
"type": { "type": "string" },
"default": {},
"validation": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties/anyOf/1/properties/validation"
},
"docs": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs" }
},
"required": ["type"],
Expand Down Expand Up @@ -352,6 +385,10 @@
"type": "object",
"properties": {
"type": { "type": "string" },
"default": {},
"validation": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties/anyOf/1/properties/validation"
},
"docs": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs" },
"availability": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/availability"
Expand Down Expand Up @@ -413,6 +450,10 @@
"type": "object",
"properties": {
"type": { "type": "string" },
"default": {},
"validation": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/properties/additionalProperties/anyOf/1/properties/validation"
},
"docs": {
"$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs"
},
Expand Down Expand Up @@ -506,7 +547,8 @@
"properties": {
"docs": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs" },
"type": { "type": "string" },
"property": { "type": "string" }
"property": { "type": "string" },
"status-code": { "type": "number" }
},
"required": ["type"],
"additionalProperties": false
Expand Down Expand Up @@ -574,14 +616,52 @@
"$ref": "#/properties/service/properties/endpoints/additionalProperties/properties/examples/items/properties/path-parameters/additionalProperties"
},
"response": {
"type": "object",
"properties": {
"error": { "type": "string" },
"body": {
"$ref": "#/properties/service/properties/endpoints/additionalProperties/properties/examples/items/properties/path-parameters/additionalProperties"
"anyOf": [
{
"type": "object",
"properties": {
"error": { "type": "string" },
"body": {
"$ref": "#/properties/service/properties/endpoints/additionalProperties/properties/examples/items/properties/path-parameters/additionalProperties"
}
},
"additionalProperties": false
},
{
"type": "object",
"properties": {
"stream": {
"type": "array",
"items": {
"$ref": "#/properties/service/properties/endpoints/additionalProperties/properties/examples/items/properties/path-parameters/additionalProperties"
}
}
},
"required": ["stream"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"stream": {
"type": "array",
"items": {
"type": "object",
"properties": {
"event": { "type": "string" },
"data": {
"$ref": "#/properties/service/properties/endpoints/additionalProperties/properties/examples/items/properties/path-parameters/additionalProperties"
}
},
"required": ["event"],
"additionalProperties": false
}
}
},
"required": ["stream"],
"additionalProperties": false
}
},
"additionalProperties": false
]
},
"code-samples": {
"type": "array",
Expand Down Expand Up @@ -918,7 +998,11 @@
"properties": {
"docs": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/docs" },
"status-code": { "type": "number" },
"type": { "type": "string" }
"type": { "type": "string" },
"examples": {
"type": "array",
"items": { "$ref": "#/properties/types/additionalProperties/anyOf/1/anyOf/0/properties/examples/items" }
}
},
"required": ["status-code"],
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,22 @@ exports[`dependencies correctly incorporates dependencies 1`] = `
"_type": "primitive",
"primitive": {
"v1": "STRING",
"v2": null
"v2": {
"type": "string",
"default": null,
"validation": null
}
}
},
"resolvedType": {
"_type": "primitive",
"primitive": {
"v1": "STRING",
"v2": null
"v2": {
"type": "string",
"default": null,
"validation": null
}
}
}
},
Expand Down Expand Up @@ -193,14 +201,22 @@ exports[`dependencies correctly incorporates dependencies 1`] = `
"_type": "primitive",
"primitive": {
"v1": "INTEGER",
"v2": null
"v2": {
"type": "integer",
"default": null,
"validation": null
}
}
},
"resolvedType": {
"_type": "primitive",
"primitive": {
"v1": "INTEGER",
"v2": null
"v2": {
"type": "integer",
"default": null,
"validation": null
}
}
}
},
Expand Down Expand Up @@ -320,14 +336,22 @@ exports[`dependencies correctly incorporates dependencies 1`] = `
"_type": "primitive",
"primitive": {
"v1": "STRING",
"v2": null
"v2": {
"type": "string",
"default": null,
"validation": null
}
}
},
"resolvedType": {
"_type": "primitive",
"primitive": {
"v1": "STRING",
"v2": null
"v2": {
"type": "string",
"default": null,
"validation": null
}
}
}
},
Expand Down Expand Up @@ -815,4 +839,4 @@ exports[`dependencies correctly incorporates dependencies 1`] = `
}"
`;

exports[`dependencies file dependencies 1`] = `2671214`;
exports[`dependencies file dependencies 1`] = `2695212`;
Loading
Loading