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

fix: refactoring allOf schemas to be pre-merged when we generate JSON Schema #579

Merged
merged 8 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,39 @@
"root": true,
"plugins": ["jsdoc"],
"rules": {
"@typescript-eslint/consistent-type-imports": "error",
// Disable requiring return types because it's too easy to broaden them by accident.
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off", // Until we have better types everywhere this is fine.
"@typescript-eslint/no-var-requires": "off",

"camelcase": "off",

// Though we aren't requiring JSDoc blocks to be present, if they are they should be properly formatted.
"jsdoc/require-jsdoc": "off",

"max-classes-per-file": "off",
"no-console": "off",
"no-param-reassign": "off",

"no-use-before-define": ["error", { "classes": false }],

"no-underscore-dangle": ["error", {
"allow": ["_key"]
}]
}],

"no-use-before-define": ["error", { "classes": false }]
},
"overrides": [
{
"files": ["*.js"],
"rules": {
// Since we're loading the TS rule up at the top for everything this rule gets triggered on JS files.
"@typescript-eslint/no-var-requires": "off",

"jsdoc/check-types": "off",
"jsdoc/require-returns-description": "off"
}
},
{
"files": ["src/cli/*.js", "src/cli/commands/*.js", "src/cli/lib/*.js"],
"rules": {
"no-console": "off"
}
},
{
"files": "*.ts",
"rules": {
Expand Down
28 changes: 28 additions & 0 deletions __tests__/__datasets__/parameters-common.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{
"in": "path",
"name": "id",
"description": "ID parameter",
"schema": {
"type": "number"
},
Expand Down Expand Up @@ -54,6 +55,33 @@
}
}
}
},
"/anything/{id}/override": {
"summary": "This path item has a common parameter that's overridden by the more specific operation.",
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of pet to return",
"schema": {
"type": "string"
},
"required": true
}
],
"get": {
"parameters": [
{
"name": "id",
"in": "path",
"description": "A comma-separated list of pet IDs",
"schema": {
"type": "string"
},
"required": true
}
]
}
}
},
"components": {
Expand Down
106 changes: 106 additions & 0 deletions __tests__/__datasets__/polymorphism-quirks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"openapi": "3.0.0",
"info": {
"title": "Polymorhism quirks",
"version": "1.0.0"
},
"servers": [
{
"url": "https://httpbin.org"
}
],
"paths": {
"/allof-with-empty-object-property": {
"post": {
"description": "Within the allOf of this requestBody there is a `data` object property that has no schema.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/api.WithdrawalRequest"
},
{
"type": "object",
"properties": {
"token": {
"allOf": [
{
"$ref": "#/components/schemas/core.Token"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/components/schemas/core.TokenData"
}
}
}
]
}
}
}
]
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
}
},
"components": {
"schemas": {
"api.WithdrawalRequest": {
"type": "object",
"required": [
"amount",
"token",
"user"
],
"properties": {
"amount": {
"type": "string"
},
"token": {
"$ref": "#/components/schemas/core.Token"
},
"user": {
"type": "string"
}
}
},
"core.TokenData": {
"type": "object",
"properties": {
"decimals": {
"type": "integer",
"example": 18
},
"token_address": {
"type": "string"
},
"token_id": {
"type": "string",
"example": "200"
}
}
},
"core.Token": {
"type": "object",
"properties": {
"data": {},
"type": {
"type": "string"
}
}
}
}
}
}
2 changes: 0 additions & 2 deletions __tests__/__datasets__/schema-deprecated.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,9 @@
"deprecated": true,
"allOf": [
{
"title": "option 1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed these because they were always going to be merged into a single title property.

"$ref": "#/components/schemas/StatusWrapper"
},
{
"title": "option 2",
"$ref": "#/components/schemas/StatusWrapper"
}
]
Expand Down
Loading