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

refactor: cleaning up the messy getSchema library and other improvements #581

Merged
merged 7 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
28 changes: 28 additions & 0 deletions __tests__/__datasets__/callbacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@
"{$request.multipleMethod.queryUrl}": {
"summary": "[common] callback summary",
"description": "[common] callback description",
"parameters": [
{
"in": "query",
"name": "queryParam",
"schema": {
"type": "string"
},
"required": true
}
],
"post": {
"requestBody": {
"description": "Callback payload",
Expand All @@ -103,6 +113,24 @@
}
},
"get": {
"parameters": [
{
"in": "query",
"name": "queryParam",
"schema": {
"type": "string"
},
"required": true
},
{
"in": "query",
"name": "anotherQueryParam",
"schema": {
"type": "string"
},
"required": true
}
],
"responses": {
"200": {
"description": "callback successfully processed",
Expand Down
35 changes: 35 additions & 0 deletions __tests__/__datasets__/petstore-nondereferenced.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"openapi": "3.1.0",
"info": {
"title": "testing",
"version": "1.0.0"
},
"paths": {
"/anything": {
"post": {
"requestBody": {
"$ref": "#/components/requestBodies/Pet"
}
}
}
},
"components": {
"requestBodies": {
"Pet": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
},
"required": true
}
},
"schemas": {
"Pet": {
"type": "string"
}
}
}
}
253 changes: 49 additions & 204 deletions __tests__/__snapshots__/operation.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,160 +5,53 @@ Array [
Object {
"label": "Body Params",
"schema": Object {
"$ref": "#/components/schemas/Pet",
Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored the test that this snapshot is part of to dereference the petstore first, so these refs are no longer getting added into compiled JSON Schema.

"$schema": "http://json-schema.org/draft-04/schema#",
"components": Object {
"requestBodies": Object {
"Pet": Object {
"content": Object {
"application/json": Object {
"schema": Object {
"$ref": "#/components/schemas/Pet",
},
},
"application/xml": Object {
"schema": Object {
"$ref": "#/components/schemas/Pet",
},
},
"properties": Object {
"category": Object {
"properties": Object {
"id": Object {
"format": "int64",
"maximum": 9223372036854776000,
"minimum": -9223372036854776000,
"type": "integer",
},
"description": "Pet object that needs to be added to the store",
"required": true,
},
"UserArray": Object {
"content": Object {
"application/json": Object {
"schema": Object {
"items": Object {
"$ref": "#/components/schemas/User",
},
"type": "array",
},
},
"name": Object {
"type": "string",
},
"description": "List of user object",
"required": true,
},
"type": "object",
"x-readme-ref-name": "Category",
},
"schemas": Object {
"ApiResponse": Object {
"properties": Object {
"code": Object {
"format": "int32",
"maximum": 2147483647,
"minimum": -2147483648,
"type": "integer",
},
"message": Object {
"type": "string",
},
"type": Object {
"type": "string",
},
},
"type": "object",
},
"Category": Object {
"properties": Object {
"id": Object {
"format": "int64",
"maximum": 9223372036854776000,
"minimum": -9223372036854776000,
"type": "integer",
},
"name": Object {
"type": "string",
},
},
"type": "object",
},
"Order": Object {
"properties": Object {
"complete": Object {
"default": false,
"type": "boolean",
},
"id": Object {
"format": "int64",
"maximum": 9223372036854776000,
"minimum": -9223372036854776000,
"type": "integer",
},
"petId": Object {
"format": "int64",
"maximum": 9223372036854776000,
"minimum": -9223372036854776000,
"type": "integer",
},
"quantity": Object {
"format": "int32",
"maximum": 2147483647,
"minimum": -2147483648,
"type": "integer",
},
"shipDate": Object {
"format": "date-time",
"type": "string",
},
"status": Object {
"description": "Order Status",
"enum": Array [
"placed",
"approved",
"delivered",
],
"type": "string",
},
},
"type": "object",
},
"Pet": Object {
"properties": Object {
"category": Object {
"$ref": "#/components/schemas/Category",
},
"id": Object {
"format": "int64",
"maximum": 9223372036854776000,
"minimum": -9223372036854776000,
"readOnly": true,
"type": "integer",
},
"name": Object {
"examples": Array [
"doggie",
],
"type": "string",
},
"photoUrls": Object {
"items": Object {
"type": "string",
},
"type": "array",
},
"status": Object {
"description": "pet status in the store",
"enum": Array [
"available",
"pending",
"sold",
],
"type": "string",
},
"tags": Object {
"items": Object {
"$ref": "#/components/schemas/Tag",
},
"type": "array",
},
},
"required": Array [
"name",
"photoUrls",
],
"type": "object",
"id": Object {
"format": "int64",
"maximum": 9223372036854776000,
"minimum": -9223372036854776000,
"readOnly": true,
"type": "integer",
},
"name": Object {
"examples": Array [
"doggie",
],
"type": "string",
},
"photoUrls": Object {
"items": Object {
"type": "string",
},
"Tag": Object {
"type": "array",
},
"status": Object {
"description": "pet status in the store",
"enum": Array [
"available",
"pending",
"sold",
],
"type": "string",
},
"tags": Object {
"items": Object {
"properties": Object {
"id": Object {
"format": "int64",
Expand All @@ -171,65 +64,17 @@ Array [
},
},
"type": "object",
"x-readme-ref-name": "Tag",
},
"User": Object {
"properties": Object {
"email": Object {
"type": "string",
},
"firstName": Object {
"type": "string",
},
"id": Object {
"format": "int64",
"maximum": 9223372036854776000,
"minimum": -9223372036854776000,
"type": "integer",
},
"lastName": Object {
"type": "string",
},
"password": Object {
"type": "string",
},
"phone": Object {
"type": "string",
},
"userStatus": Object {
"description": "User Status",
"format": "int32",
"maximum": 2147483647,
"minimum": -2147483648,
"type": "integer",
},
"username": Object {
"type": "string",
},
},
"type": "object",
},
},
"securitySchemes": Object {
"api_key": Object {
"in": "header",
"name": "api_key",
"type": "apiKey",
},
"petstore_auth": Object {
"_key": "petstore_auth",
"flows": Object {
"implicit": Object {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"scopes": Object {
"read:pets": "read your pets",
"write:pets": "modify pets in your account",
},
},
},
"type": "oauth2",
},
"type": "array",
},
},
"required": Array [
"name",
"photoUrls",
],
"type": "object",
"x-readme-ref-name": "Pet",
},
"type": "body",
},
Expand Down
1 change: 0 additions & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import serverVariables from './__datasets__/server-variables.json';
test('should export utils', () => {
expect(utils).toStrictEqual({
findSchemaDefinition: expect.any(Function),
getSchema: expect.any(Function),
jsonSchemaTypes: expect.any(Object),
matchesMimeType: expect.any(Object),
});
Expand Down
Loading