From 828eaf9d675c99042bef1df17f428b86785898ce Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Fri, 6 Sep 2024 11:36:37 -0400 Subject: [PATCH 1/3] fix(cli): handle parsing json schema type arrays from openapi specs --- .../__test__/__snapshots__/ada.test.ts.snap | 733 +++++++ .../src/__test__/ada.test.ts | 5 + .../src/__test__/fixtures/ada/openapi.json | 892 +++++++++ .../__test__/__snapshots__/ada.test.ts.snap | 1708 +++++++++++++++++ .../openapi-parser/src/__test__/ada.test.ts | 5 + .../src/__test__/fixtures/ada/openapi.json | 892 +++++++++ .../src/schema/convertSchemas.ts | 9 + 7 files changed, 4244 insertions(+) create mode 100644 packages/cli/openapi-ir-to-fern/src/__test__/__snapshots__/ada.test.ts.snap create mode 100644 packages/cli/openapi-ir-to-fern/src/__test__/ada.test.ts create mode 100644 packages/cli/openapi-ir-to-fern/src/__test__/fixtures/ada/openapi.json create mode 100644 packages/cli/openapi-parser/src/__test__/__snapshots__/ada.test.ts.snap create mode 100644 packages/cli/openapi-parser/src/__test__/ada.test.ts create mode 100644 packages/cli/openapi-parser/src/__test__/fixtures/ada/openapi.json diff --git a/packages/cli/openapi-ir-to-fern/src/__test__/__snapshots__/ada.test.ts.snap b/packages/cli/openapi-ir-to-fern/src/__test__/__snapshots__/ada.test.ts.snap new file mode 100644 index 00000000000..1e10cbe80b3 --- /dev/null +++ b/packages/cli/openapi-ir-to-fern/src/__test__/__snapshots__/ada.test.ts.snap @@ -0,0 +1,733 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`open api parser > ada > docs 1`] = ` +{ + "definitionFiles": { + "endUsers.yml": { + "imports": { + "root": "__package__.yml", + }, + "service": { + "auth": false, + "base-path": "", + "endpoints": { + "getEndUserById": { + "auth": true, + "display-name": "Get an end user by ID", + "docs": "Get a specific end user", + "errors": [ + "root.GetEndUserByIdRequestUnauthorizedError", + "root.GetEndUserByIdRequestNotFoundError", + "root.GetEndUserByIdRequestTooManyRequestsError", + "root.GetEndUserByIdRequestInternalServerError", + ], + "examples": [ + { + "path-parameters": { + "end_user_id": "end_user_id", + }, + "response": { + "body": { + "key": "value", + }, + }, + }, + ], + "method": "GET", + "pagination": undefined, + "path": "/end-users/v1/{end_user_id}", + "path-parameters": { + "end_user_id": { + "docs": "The end_user_id", + "type": "string", + }, + }, + "response": { + "docs": "OK", + "type": "root.EndUser", + }, + }, + "getEndUsers": { + "auth": true, + "display-name": "Get multiple end users by ID", + "docs": "Get multiple end users", + "errors": [ + "root.GetEndUsersRequestBadRequestError", + "root.GetEndUsersRequestUnauthorizedError", + "root.GetEndUsersRequestTooManyRequestsError", + "root.GetEndUsersRequestInternalServerError", + ], + "examples": [ + { + "response": { + "body": { + "key": "value", + }, + }, + }, + ], + "method": "GET", + "pagination": undefined, + "path": "/end-users/v1", + "request": { + "name": "GetEndUsersRequest", + "query-parameters": { + "cursor": { + "docs": "The end user ID that marks the start or beginning of the returned profile records.", + "type": "optional", + }, + "limit": { + "docs": "The number of end user profile records to return", + "type": "optional", + }, + }, + }, + "response": { + "docs": "OK", + "type": "root.EndUsers", + }, + }, + "updateEndUserById": { + "auth": true, + "display-name": "Update an end user by ID", + "docs": "Update an end user. Request data is limited to 4KB in size total.", + "errors": [ + "root.UpdateEndUserByIdRequestBadRequestError", + "root.UpdateEndUserByIdRequestUnauthorizedError", + "root.UpdateEndUserByIdRequestNotFoundError", + "root.UpdateEndUserByIdRequestContentTooLargeError", + "root.UpdateEndUserByIdRequestTooManyRequestsError", + "root.UpdateEndUserByIdRequestInternalServerError", + ], + "method": "PATCH", + "pagination": undefined, + "path": "/end-users/v1/{end_user_id}", + "path-parameters": { + "end_user_id": { + "docs": "The end_user_id", + "type": "string", + }, + }, + "request": { + "body": "root.EndUserRequest", + }, + "response": { + "docs": "OK", + "type": "root.EndUser", + }, + }, + }, + "source": { + "openapi": "ada/openapi.json", + }, + }, + }, + }, + "packageMarkerFile": { + "errors": { + "GetEndUserByIdRequestInternalServerError": { + "docs": "Internal Server Error", + "examples": [ + { + "docs": undefined, + "name": "InternalServerError", + "value": { + "errors": [ + { + "details": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e", + "msg": "internal_server_error", + }, + ], + }, + }, + ], + "status-code": 500, + "type": "Errors", + }, + "GetEndUserByIdRequestNotFoundError": { + "docs": "Not Found", + "examples": [ + { + "docs": undefined, + "name": "NotFoundError", + "value": { + "errors": [ + { + "details": "The requested resource with ID 5f7e0e2c1e7c7e000f0f9c3a was not found", + "msg": "resource_not_found", + }, + ], + }, + }, + ], + "status-code": 404, + "type": "Errors", + }, + "GetEndUserByIdRequestTooManyRequestsError": { + "docs": "Too Many Requests", + "examples": [ + { + "docs": undefined, + "name": "TooManyRequestsError", + "value": { + "errors": [ + { + "details": "50 requests allowed per second", + "msg": "rate_limit_exceeded", + }, + ], + }, + }, + ], + "status-code": 429, + "type": "Errors", + }, + "GetEndUserByIdRequestUnauthorizedError": { + "docs": "Unauthorized", + "examples": [ + { + "docs": undefined, + "name": "UnauthorizedError", + "value": { + "errors": [ + { + "details": "You are not authorized to access this resource", + "msg": "unauthorized", + }, + ], + }, + }, + ], + "status-code": 401, + "type": "Errors", + }, + "GetEndUsersRequestBadRequestError": { + "docs": "Bad Request", + "examples": [ + { + "docs": undefined, + "name": "BadRequestError", + "value": { + "errors": [ + { + "details": "{'profile': {'system_properties': ['Unknown field.']}}", + "msg": "bad_request", + }, + ], + }, + }, + ], + "status-code": 400, + "type": "Errors", + }, + "GetEndUsersRequestInternalServerError": { + "docs": "Internal Server Error", + "examples": [ + { + "docs": undefined, + "name": "InternalServerError", + "value": { + "errors": [ + { + "details": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e", + "msg": "internal_server_error", + }, + ], + }, + }, + ], + "status-code": 500, + "type": "Errors", + }, + "GetEndUsersRequestTooManyRequestsError": { + "docs": "Too Many Requests", + "examples": [ + { + "docs": undefined, + "name": "TooManyRequestsError", + "value": { + "errors": [ + { + "details": "50 requests allowed per second", + "msg": "rate_limit_exceeded", + }, + ], + }, + }, + ], + "status-code": 429, + "type": "Errors", + }, + "GetEndUsersRequestUnauthorizedError": { + "docs": "Unauthorized", + "examples": [ + { + "docs": undefined, + "name": "UnauthorizedError", + "value": { + "errors": [ + { + "details": "You are not authorized to access this resource", + "msg": "unauthorized", + }, + ], + }, + }, + ], + "status-code": 401, + "type": "Errors", + }, + "UpdateEndUserByIdRequestBadRequestError": { + "docs": "Bad Request", + "examples": [ + { + "docs": undefined, + "name": "BadRequestError", + "value": { + "errors": [ + { + "details": "{'profile': {'system_properties': ['Unknown field.']}}", + "msg": "bad_request", + }, + ], + }, + }, + ], + "status-code": 400, + "type": "Errors", + }, + "UpdateEndUserByIdRequestContentTooLargeError": { + "docs": "Content Too Large", + "examples": [ + { + "docs": undefined, + "name": "ContentTooLargeError", + "value": { + "errors": [ + { + "details": "Maximum request size of 4.0 MB exceeded. Content length: 5.0 MB.", + "msg": "content_too_large", + }, + ], + }, + }, + ], + "status-code": 413, + "type": "Errors", + }, + "UpdateEndUserByIdRequestInternalServerError": { + "docs": "Internal Server Error", + "examples": [ + { + "docs": undefined, + "name": "InternalServerError", + "value": { + "errors": [ + { + "details": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e", + "msg": "internal_server_error", + }, + ], + }, + }, + ], + "status-code": 500, + "type": "Errors", + }, + "UpdateEndUserByIdRequestNotFoundError": { + "docs": "Not Found", + "examples": [ + { + "docs": undefined, + "name": "NotFoundError", + "value": { + "errors": [ + { + "details": "The requested resource with ID 5f7e0e2c1e7c7e000f0f9c3a was not found", + "msg": "resource_not_found", + }, + ], + }, + }, + ], + "status-code": 404, + "type": "Errors", + }, + "UpdateEndUserByIdRequestTooManyRequestsError": { + "docs": "Too Many Requests", + "examples": [ + { + "docs": undefined, + "name": "TooManyRequestsError", + "value": { + "errors": [ + { + "details": "50 requests allowed per second", + "msg": "rate_limit_exceeded", + }, + ], + }, + }, + ], + "status-code": 429, + "type": "Errors", + }, + "UpdateEndUserByIdRequestUnauthorizedError": { + "docs": "Unauthorized", + "examples": [ + { + "docs": undefined, + "name": "UnauthorizedError", + "value": { + "errors": [ + { + "details": "You are not authorized to access this resource", + "msg": "unauthorized", + }, + ], + }, + }, + ], + "status-code": 401, + "type": "Errors", + }, + }, + "types": { + "EndUser": "unknown", + "EndUserCreatedWebhookPayload": { + "docs": undefined, + "properties": { + "data": "optional", + "timestamp": "optional", + "type": "optional", + }, + "source": { + "openapi": "ada/openapi.json", + }, + }, + "EndUserRequest": "unknown", + "EndUserUpdatedWebhookPayload": { + "docs": undefined, + "properties": { + "data": "optional", + "timestamp": "optional", + "type": "optional", + }, + "source": { + "openapi": "ada/openapi.json", + }, + }, + "EndUsers": "unknown", + "Error": "unknown", + "Errors": "unknown", + }, + }, + "rootApiFile": { + "auth": "BearerAuthScheme", + "auth-schemes": { + "BearerAuthScheme": { + "scheme": "bearer", + }, + }, + "default-environment": "Default", + "display-name": "End Users API", + "environments": { + "Default": "https://example.ada.support/api", + }, + "error-discrimination": { + "strategy": "status-code", + }, + "name": "api", + }, +} +`; + +exports[`open api parser > ada > simple 1`] = ` +{ + "definitionFiles": { + "endUsers.yml": { + "imports": { + "root": "__package__.yml", + }, + "service": { + "auth": false, + "base-path": "", + "endpoints": { + "getEndUserById": { + "auth": true, + "display-name": "Get an end user by ID", + "docs": "Get a specific end user", + "errors": [ + "root.UnauthorizedError", + "root.NotFoundError", + "root.TooManyRequestsError", + "root.InternalServerError", + ], + "examples": [ + { + "path-parameters": { + "end_user_id": "end_user_id", + }, + "response": { + "body": { + "key": "value", + }, + }, + }, + ], + "method": "GET", + "pagination": undefined, + "path": "/end-users/v1/{end_user_id}", + "path-parameters": { + "end_user_id": { + "docs": "The end_user_id", + "type": "string", + }, + }, + "response": { + "docs": "OK", + "type": "root.EndUser", + }, + }, + "getEndUsers": { + "auth": true, + "display-name": "Get multiple end users by ID", + "docs": "Get multiple end users", + "errors": [ + "root.BadRequestError", + "root.UnauthorizedError", + "root.TooManyRequestsError", + "root.InternalServerError", + ], + "examples": [ + { + "response": { + "body": { + "key": "value", + }, + }, + }, + ], + "method": "GET", + "pagination": undefined, + "path": "/end-users/v1", + "request": { + "name": "GetEndUsersRequest", + "query-parameters": { + "cursor": { + "docs": "The end user ID that marks the start or beginning of the returned profile records.", + "type": "optional", + }, + "limit": { + "docs": "The number of end user profile records to return", + "type": "optional", + }, + }, + }, + "response": { + "docs": "OK", + "type": "root.EndUsers", + }, + }, + "updateEndUserById": { + "auth": true, + "display-name": "Update an end user by ID", + "docs": "Update an end user. Request data is limited to 4KB in size total.", + "errors": [ + "root.BadRequestError", + "root.UnauthorizedError", + "root.NotFoundError", + "root.ContentTooLargeError", + "root.TooManyRequestsError", + "root.InternalServerError", + ], + "method": "PATCH", + "pagination": undefined, + "path": "/end-users/v1/{end_user_id}", + "path-parameters": { + "end_user_id": { + "docs": "The end_user_id", + "type": "string", + }, + }, + "request": { + "body": "root.EndUserRequest", + }, + "response": { + "docs": "OK", + "type": "root.EndUser", + }, + }, + }, + "source": { + "openapi": "ada/openapi.json", + }, + }, + }, + }, + "packageMarkerFile": { + "errors": { + "BadRequestError": { + "docs": "Bad Request", + "examples": [ + { + "docs": undefined, + "name": "BadRequestError", + "value": { + "errors": [ + { + "details": "{'profile': {'system_properties': ['Unknown field.']}}", + "msg": "bad_request", + }, + ], + }, + }, + ], + "status-code": 400, + "type": "Errors", + }, + "ContentTooLargeError": { + "docs": "Content Too Large", + "examples": [ + { + "docs": undefined, + "name": "ContentTooLargeError", + "value": { + "errors": [ + { + "details": "Maximum request size of 4.0 MB exceeded. Content length: 5.0 MB.", + "msg": "content_too_large", + }, + ], + }, + }, + ], + "status-code": 413, + "type": "Errors", + }, + "InternalServerError": { + "docs": "Internal Server Error", + "examples": [ + { + "docs": undefined, + "name": "InternalServerError", + "value": { + "errors": [ + { + "details": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e", + "msg": "internal_server_error", + }, + ], + }, + }, + ], + "status-code": 500, + "type": "Errors", + }, + "NotFoundError": { + "docs": "Not Found", + "examples": [ + { + "docs": undefined, + "name": "NotFoundError", + "value": { + "errors": [ + { + "details": "The requested resource with ID 5f7e0e2c1e7c7e000f0f9c3a was not found", + "msg": "resource_not_found", + }, + ], + }, + }, + ], + "status-code": 404, + "type": "Errors", + }, + "TooManyRequestsError": { + "docs": "Too Many Requests", + "examples": [ + { + "docs": undefined, + "name": "TooManyRequestsError", + "value": { + "errors": [ + { + "details": "50 requests allowed per second", + "msg": "rate_limit_exceeded", + }, + ], + }, + }, + ], + "status-code": 429, + "type": "Errors", + }, + "UnauthorizedError": { + "docs": "Unauthorized", + "examples": [ + { + "docs": undefined, + "name": "UnauthorizedError", + "value": { + "errors": [ + { + "details": "You are not authorized to access this resource", + "msg": "unauthorized", + }, + ], + }, + }, + ], + "status-code": 401, + "type": "Errors", + }, + }, + "types": { + "EndUser": "unknown", + "EndUserCreatedWebhookPayload": { + "docs": undefined, + "properties": { + "data": "optional", + "timestamp": "optional", + "type": "optional", + }, + "source": { + "openapi": "ada/openapi.json", + }, + }, + "EndUserRequest": "unknown", + "EndUserUpdatedWebhookPayload": { + "docs": undefined, + "properties": { + "data": "optional", + "timestamp": "optional", + "type": "optional", + }, + "source": { + "openapi": "ada/openapi.json", + }, + }, + "EndUsers": "unknown", + "Error": "unknown", + "Errors": "unknown", + }, + }, + "rootApiFile": { + "auth": "BearerAuthScheme", + "auth-schemes": { + "BearerAuthScheme": { + "scheme": "bearer", + }, + }, + "default-environment": "Default", + "display-name": "End Users API", + "environments": { + "Default": "https://example.ada.support/api", + }, + "error-discrimination": { + "strategy": "status-code", + }, + "name": "api", + }, +} +`; diff --git a/packages/cli/openapi-ir-to-fern/src/__test__/ada.test.ts b/packages/cli/openapi-ir-to-fern/src/__test__/ada.test.ts new file mode 100644 index 00000000000..5c2aa8ff8e4 --- /dev/null +++ b/packages/cli/openapi-ir-to-fern/src/__test__/ada.test.ts @@ -0,0 +1,5 @@ +import { testConvertOpenAPI } from "./testConvertOpenApi"; + +describe("open api parser", () => { + testConvertOpenAPI("ada", "openapi.json"); +}); diff --git a/packages/cli/openapi-ir-to-fern/src/__test__/fixtures/ada/openapi.json b/packages/cli/openapi-ir-to-fern/src/__test__/fixtures/ada/openapi.json new file mode 100644 index 00000000000..302ed03d19f --- /dev/null +++ b/packages/cli/openapi-ir-to-fern/src/__test__/fixtures/ada/openapi.json @@ -0,0 +1,892 @@ +{ + "info": { + "title": "End Users API", + "version": "1.0.0", + "description": "test" + }, + "tags": [{ + "name": "End Users API", + "description": "test" + }], + "paths": { + "/end-users/v1/{end_user_id}": { + "get": { + "operationId": "getEndUserById", + "summary": "Get an end user by ID", + "description": "Get a specific end user", + "security": [{ + "BearerAuth": [] + }], + "tags": ["End users"], + "parameters": [{ + "in": "path", + "name": "end_user_id", + "schema": { + "type": "string" + }, + "required": true, + "description": "The end_user_id" + }], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUser" + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "UnauthorizedError": { + "$ref": "#/components/examples/UnauthorizedError" + } + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "NotFoundError": { + "$ref": "#/components/examples/NotFoundError" + } + } + } + } + }, + "429": { + "description": "Too Many Requests", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "TooManyRequestsError": { + "$ref": "#/components/examples/TooManyRequestsError" + } + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "InternalServerError": { + "$ref": "#/components/examples/InternalServerError" + } + } + } + } + } + } + }, + "patch": { + "operationId": "updateEndUserById", + "summary": "Update an end user by ID", + "description": "Update an end user. Request data is limited to 4KB in size total.", + "security": [{ + "BearerAuth": [] + }], + "tags": ["End users"], + "parameters": [{ + "in": "path", + "name": "end_user_id", + "schema": { + "type": "string" + }, + "required": true, + "description": "The end_user_id" + }], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUserRequest" + } + } + } + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUser" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "BadRequestError": { + "$ref": "#/components/examples/BadRequestError" + } + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "UnauthorizedError": { + "$ref": "#/components/examples/UnauthorizedError" + } + } + } + } + }, + "413": { + "description": "Content Too Large", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "ContentTooLargeError": { + "$ref": "#/components/examples/ContentTooLargeError" + } + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "NotFoundError": { + "$ref": "#/components/examples/NotFoundError" + } + } + } + } + }, + "429": { + "description": "Too Many Requests", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "TooManyRequestsError": { + "$ref": "#/components/examples/TooManyRequestsError" + } + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "InternalServerError": { + "$ref": "#/components/examples/InternalServerError" + } + } + } + } + } + } + } + }, + "/end-users/v1": { + "get": { + "operationId": "getEndUsers", + "summary": "Get multiple end users by ID", + "description": "Get multiple end users", + "security": [{ + "BearerAuth": [] + }], + "tags": ["End users"], + "parameters": [{ + "in": "query", + "name": "cursor", + "description": "The end user ID that marks the start or beginning of the returned profile records.", + "schema": { + "type": "string", + "examples": ["65a17e3f43bec88e2792d0eb"] + }, + "required": false + }, { + "in": "query", + "name": "limit", + "description": "The number of end user profile records to return", + "schema": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "examples": [8] + }, + "required": false + }], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUsers" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "BadRequestError": { + "$ref": "#/components/examples/BadRequestError" + } + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "UnauthorizedError": { + "$ref": "#/components/examples/UnauthorizedError" + } + } + } + } + }, + "429": { + "description": "Too Many Requests", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "TooManyRequestsError": { + "$ref": "#/components/examples/TooManyRequestsError" + } + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "InternalServerError": { + "$ref": "#/components/examples/InternalServerError" + } + } + } + } + } + } + } + }, + "/end-users/v1/spec": {}, + "/end-users/v1/docs": {} + }, + "openapi": "3.1.0", + "components": { + "schemas": { + "EndUser": { + "type": ["object"], + "properties": { + "end_user_id": { + "type": ["string"], + "readOnly": true, + "description": "The unique Ada-generated ID for the end user", + "examples": ["5f7e0e2c1e7c7e000f0f9c3a"] + }, + "profile": { + "description": "The end user's profile information", + "type": ["object"], + "properties": { + "first_name": { + "type": ["string", "null"], + "description": "The end user's first name", + "examples": ["Ada"] + }, + "last_name": { + "type": ["string", "null"], + "description": "The end user's last name", + "examples": ["Lovelace"] + }, + "email": { + "type": ["string", "null"], + "description": "The end user's email address", + "examples": ["ada.lovelace@ada.cx"] + }, + "language": { + "type": ["string", "null"], + "description": "The end user's language in BCP 47 format", + "examples": ["en-US"] + }, + "metadata": { + "type": ["object"], + "description": "A dictionary of arbitrary key, value pairs assigned to the end user - `metadata` keys may only be of type: `string` - `metadata` values may only be one of type: `string`, `boolean`, or `integer` ", + "examples": [{ + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }], + "additionalProperties": {} + }, + "system_properties": { + "type": ["object"], + "description": "Read-only profile information set by Ada", + "properties": { + "user_agent": { + "type": ["string", "null"], + "description": "The end user's browser user-agent information captured by Ada", + "examples": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"], + "readOnly": true + }, + "device": { + "type": ["string", "null"], + "description": "The end user's device information captured by Ada", + "examples": ["macos"], + "readOnly": true + }, + "browser": { + "type": ["string", "null"], + "description": "The end user's browser information captured by Ada", + "examples": ["Chrome"], + "readOnly": true + }, + "browser_version": { + "type": ["string", "null"], + "description": "The end user's browser version captured by Ada", + "examples": ["119.0.0.0"], + "readOnly": true + }, + "introshown": { + "type": ["boolean", "null"], + "description": "Whether the introductory message of a campaign has been displayed to the end user", + "examples": [false], + "readOnly": true + }, + "last_answer_id": { + "type": ["string", "null"], + "description": "The ID for the last answer displayed to the end user during a conversation", + "examples": ["650071321ef45533437f6f29"], + "readOnly": true + }, + "last_question_asked": { + "type": ["string", "null"], + "description": "The last question asked by the end user", + "examples": ["What is my account balance?"], + "readOnly": true + }, + "sunshine_first_message_id": { + "type": ["string", "null"], + "description": "The ID for the first message sent to the end user via Sunshine Conversations", + "examples": ["65736922f17d0bf841d8eeb4"], + "readOnly": true + }, + "sunshine_conversation_id": { + "type": ["string", "null"], + "description": "The ID for the Sunshine Conversation for this end user", + "examples": ["12345abc"], + "readOnly": true + }, + "sunshine_end_user_channel": { + "type": ["string", "null"], + "description": "The channel used to communicate with the end user via Sunshine Conversations", + "examples": ["whatsapp"], + "readOnly": true + }, + "sunshine_signed_up_at": { + "type": ["string", "null"], + "description": "The date the end user signed up for Sunshine Conversations", + "examples": ["2023-12-08T19:06:04.890000"], + "readOnly": true + }, + "sunshine_user_id": { + "type": ["string", "null"], + "description": "The Sunshine Conversations user ID for the end user", + "examples": ["5f7e0e2c1e7c7e000f0f9c3a"], + "readOnly": true + } + } + } + } + }, + "created_at": { + "type": ["string"], + "readOnly": true, + "description": "The date and time the end user was created", + "examples": ["2023-12-08T19:06:04.890000"] + }, + "updated_at": { + "type": ["string"], + "readOnly": true, + "description": "The date and time the end user was updated", + "examples": ["2023-12-08T19:06:04.890000"] + } + }, + "examples": [{ + "end_user_id": "5f7e0e2c1e7c7e000f0f9c3a", + "profile": { + "first_name": "Ada", + "last_name": "Lovelace", + "email": "ada.lovelace@ada.cx", + "language": "en-US", + "metadata": { + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }, + "system_properties": { + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", + "device": "macos", + "browser": "Chrome", + "browser_version": "119.0.0.0", + "introshown": false, + "last_answer_id": "650071321ef45533437f6f29", + "last_question_asked": "What is my account balance?", + "sunshine_first_message_id": "65736922f17d0bf841d8eeb4", + "sunshine_conversation_id": "12345abc", + "sunshine_end_user_channel": "whatsapp", + "sunshine_signed_up_at": "2023-12-08T19:06:04.890000", + "sunshine_user_id": "5f7e0e2c1e7c7e000f0f9c3a" + } + }, + "created_at": "2023-12-08T19:06:04.890000", + "updated_at": "2023-12-08T19:06:04.890000" + }] + }, + "EndUserRequest": { + "type": ["object"], + "required": ["profile"], + "properties": { + "profile": { + "description": "The end user's profile information", + "type": ["object"], + "properties": { + "first_name": { + "type": ["string", "null"], + "description": "The end user's first name", + "examples": ["Ada"] + }, + "last_name": { + "type": ["string", "null"], + "description": "The end user's last name", + "examples": ["Lovelace"] + }, + "email": { + "type": ["string", "null"], + "description": "The end user's email address", + "examples": ["ada.lovelace@ada.cx"] + }, + "language": { + "type": ["string", "null"], + "description": "The end user's language in BCP 47 format", + "examples": ["en-US"] + }, + "metadata": { + "type": ["object", "null"], + "description": "A dictionary of arbitrary key, value pairs assigned to the end user - `metadata` keys may only be of type: `string` - `metadata` values may only be one of type: `string`, `boolean`, or `integer` ", + "examples": [{ + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }], + "additionalProperties": {} + } + } + } + }, + "examples": [{ + "profile": { + "first_name": "Ada", + "last_name": "Lovelace", + "email": "ada.lovelace@ada.cx", + "language": "en-US", + "metadata": { + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + } + } + }] + }, + "Error": { + "type": ["object"], + "properties": { + "msg": { + "type": ["string"], + "description": "The error message", + "examples": ["resource_not_found"] + }, + "details": { + "type": ["string"], + "description": "Extra information about the error", + "examples": ["The requested resource with ID was not found"] + } + }, + "examples": [{ + "msg": "resource_not_found", + "details": "The requested resource with ID 123456abcdef was not found" + }], + "required": ["details", "msg"] + }, + "Errors": { + "type": ["object"], + "properties": { + "errors": { + "type": ["array"], + "description": "A list of errors", + "items": { + "$ref": "#/components/schemas/Error" + } + } + }, + "required": ["errors"] + }, + "EndUsers": { + "type": ["object"], + "properties": { + "end_users": { + "type": ["array"], + "description": "List of end user profiles", + "items": { + "$ref": "#/components/schemas/EndUser" + } + }, + "meta": { + "description": "Metadata returned with the results including but not limited to a link to the next page of data", + "type": ["object"], + "properties": { + "next_page_url": { + "type": ["string"], + "format": "url", + "description": "Link to the next page of data using a cursor value", + "examples": ["https://example.ada.support/api/end-users/v1?cursor=65a17e3f43bec88e2792d0eb"] + } + } + } + } + }, + "EndUserCreatedWebhookPayload": { + "properties": { + "type": { + "type": ["string"], + "readOnly": false, + "description": "The webhook event type description", + "examples": ["v1.end_user.created"] + }, + "timestamp": { + "type": ["string"], + "readOnly": false, + "description": "The timestamp for when the event was generated. Uses millisecond precision to help with event ordering needs.", + "examples": ["2024-01-17T22:23:35.835"] + }, + "data": { + "type": ["object"], + "description": "The webhook event data", + "allOf": [{ + "$ref": "#/components/schemas/EndUser" + }, { + "type": ["object"], + "properties": { + "end_user_id": { + "type": ["string"], + "description": "The unique Ada-generated ID for the end user", + "examples": ["5f7e0e2c1e7c7e000f0f9c3a"], + "readOnly": false + }, + "created_at": { + "type": ["string"], + "description": "The date and time the end user was created", + "examples": ["2023-12-08T19:06:02.000000"], + "readOnly": false + }, + "updated_at": { + "type": ["string"], + "description": "The date and time the end user was updated", + "examples": ["2023-12-08T19:06:04.890000"], + "readOnly": false + } + } + }] + } + }, + "examples": [{ + "type": "v1.end_user.created", + "timestamp": "2024-01-17T22:23:35.835", + "data": { + "end_user_id": "5f7e0e2c1e7c7e000f0f9c3a", + "profile": { + "first_name": "Ada", + "last_name": "Lovelace", + "email": "ada.lovelace@ada.cx", + "language": "en-US", + "metadata": { + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }, + "system_properties": { + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", + "device": "macos", + "browser": "Chrome", + "browser_version": "119.0.0.0", + "introshown": false, + "last_answer_id": "650071321ef45533437f6f29", + "last_question_asked": "What is my account balance?", + "sunshine_first_message_id": "65736922f17d0bf841d8eeb4", + "sunshine_conversation_id": "12345abc", + "sunshine_end_user_channel": "whatsapp", + "sunshine_signed_up_at": "2023-12-08T19:06:04.890000", + "sunshine_user_id": "5f7e0e2c1e7c7e000f0f9c3a" + } + }, + "created_at": "2023-12-08T19:06:04.890000", + "updated_at": "2023-12-08T19:06:04.890000" + } + }] + }, + "EndUserUpdatedWebhookPayload": { + "properties": { + "type": { + "type": ["string"], + "readOnly": false, + "description": "The webhook event type description", + "examples": ["v1.end_user.updated"] + }, + "timestamp": { + "type": ["string"], + "readOnly": false, + "description": "The timestamp for when the event was generated. Uses millisecond precision to help with event ordering needs.", + "examples": ["2024-01-17T22:23:35.835"] + }, + "data": { + "type": ["object"], + "description": "The webhook event data", + "allOf": [{ + "$ref": "#/components/schemas/EndUser" + }, { + "type": ["object"], + "properties": { + "end_user_id": { + "type": ["string"], + "description": "The unique Ada-generated ID for the end user", + "examples": ["5f7e0e2c1e7c7e000f0f9c3a"], + "readOnly": false + }, + "created_at": { + "type": ["string"], + "description": "The date and time the end user was created", + "examples": ["2023-12-08T19:06:02.000000"], + "readOnly": false + }, + "updated_at": { + "type": ["string"], + "description": "The date and time the end user was updated", + "examples": ["2023-12-08T19:06:04.890000"], + "readOnly": false + } + } + }] + } + }, + "examples": [{ + "type": "v1.end_user.updated", + "timestamp": "2024-01-17T22:23:35.835", + "data": { + "end_user_id": "5f7e0e2c1e7c7e000f0f9c3a", + "profile": { + "first_name": "Ada", + "last_name": "Lovelace", + "email": "ada.lovelace@ada.cx", + "language": "en-US", + "metadata": { + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }, + "system_properties": { + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", + "device": "macos", + "browser": "Chrome", + "browser_version": "119.0.0.0", + "introshown": false, + "last_answer_id": "650071321ef45533437f6f29", + "last_question_asked": "What is my account balance?", + "sunshine_first_message_id": "65736922f17d0bf841d8eeb4", + "sunshine_conversation_id": "12345abc", + "sunshine_end_user_channel": "whatsapp", + "sunshine_signed_up_at": "2023-12-08T19:06:04.890000", + "sunshine_user_id": "5f7e0e2c1e7c7e000f0f9c3a" + } + }, + "created_at": "2023-12-08T19:06:04.890000", + "updated_at": "2023-12-08T19:06:04.890000" + } + }] + } + }, + "examples": { + "BadRequestError": { + "value": { + "errors": [{ + "msg": "bad_request", + "details": "{'profile': {'system_properties': ['Unknown field.']}}" + }] + } + }, + "NotFoundError": { + "value": { + "errors": [{ + "msg": "resource_not_found", + "details": "The requested resource with ID 5f7e0e2c1e7c7e000f0f9c3a was not found" + }] + } + }, + "UnauthorizedError": { + "value": { + "errors": [{ + "msg": "unauthorized", + "details": "You are not authorized to access this resource" + }] + } + }, + "ContentTooLargeError": { + "value": { + "errors": [{ + "msg": "content_too_large", + "details": "Maximum request size of 4.0 MB exceeded. Content length: 5.0 MB." + }] + } + }, + "TooManyRequestsError": { + "value": { + "errors": [{ + "msg": "rate_limit_exceeded", + "details": "50 requests allowed per second" + }] + } + }, + "InternalServerError": { + "value": { + "errors": [{ + "msg": "internal_server_error", + "details": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e" + }] + } + } + }, + "securitySchemes": { + "BearerAuth": { + "type": "http", + "scheme": "bearer" + } + } + }, + "webhooks": { + "v1.end_user.created": { + "post": { + "summary": "End user created webhook", + "description": "A webhook sent when a new end user is created", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUserCreatedWebhookPayload" + } + } + } + }, + "responses": { + "200": { + "description": "Return a 200 status to indicate that the data was received successfully" + } + }, + "tags": ["Webhooks"] + } + }, + "v1.end_user.updated": { + "post": { + "summary": "End user updated webhook", + "description": "A webhook sent when an end user is updated", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUserUpdatedWebhookPayload" + } + } + } + }, + "responses": { + "200": { + "description": "Return a 200 status to indicate that the data was received successfully" + } + }, + "tags": ["Webhooks"] + } + } + }, + "servers": [{ + "url": "https://{handle}.ada.support/api", + "variables": { + "handle": { + "default": "example" + } + }, + "description": "The subdomain of the client" + }] +} \ No newline at end of file diff --git a/packages/cli/openapi-parser/src/__test__/__snapshots__/ada.test.ts.snap b/packages/cli/openapi-parser/src/__test__/__snapshots__/ada.test.ts.snap new file mode 100644 index 00000000000..14b0b22fc54 --- /dev/null +++ b/packages/cli/openapi-parser/src/__test__/__snapshots__/ada.test.ts.snap @@ -0,0 +1,1708 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`open api parser > ada > parse open api 1`] = ` +{ + "apiVersion": null, + "basePath": null, + "channel": [], + "description": "test", + "endpoints": [ + { + "audiences": [], + "authed": true, + "availability": null, + "description": "Get a specific end user", + "errors": { + "401": { + "description": "Unauthorized", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "unauthorized", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "You are not authorized to access this resource", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "UnauthorizedError", + }, + ], + "generatedName": "UnauthorizedError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "UnauthorizedErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "404": { + "description": "Not Found", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "resource_not_found", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "The requested resource with ID 5f7e0e2c1e7c7e000f0f9c3a was not found", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "NotFoundError", + }, + ], + "generatedName": "NotFoundError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "NotFoundErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "429": { + "description": "Too Many Requests", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "rate_limit_exceeded", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "50 requests allowed per second", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "TooManyRequestsError", + }, + ], + "generatedName": "TooManyRequestsError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "TooManyRequestsErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "500": { + "description": "Internal Server Error", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "internal_server_error", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "InternalServerError", + }, + ], + "generatedName": "InternalServerError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "InternalServerErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + }, + "examples": [ + { + "codeSamples": [], + "description": null, + "headers": [], + "name": null, + "pathParameters": [ + { + "name": "end_user_id", + "parameterNameOverride": null, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "end_user_id", + }, + }, + }, + ], + "queryParameters": [], + "request": null, + "response": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "key", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "value", + }, + }, + }, + ], + }, + "type": "full", + }, + ], + "generatedRequestName": "GetEndUserByIdRequest", + "headers": [], + "idempotent": null, + "internal": null, + "method": "GET", + "operationId": "getEndUserById", + "pagination": null, + "path": "/end-users/v1/{end_user_id}", + "pathParameters": [ + { + "availability": null, + "description": "The end_user_id", + "name": "end_user_id", + "parameterNameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "GetEndUserByIdRequestEndUserId", + "groupName": [], + "nameOverride": null, + "schema": { + "default": null, + "format": null, + "maxLength": null, + "minLength": null, + "pattern": null, + "type": "string", + }, + "type": "primitive", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "variableReference": null, + }, + ], + "queryParameters": [], + "request": null, + "requestNameOverride": null, + "response": { + "description": "OK", + "responseProperty": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "GetEndUserByIdResponse", + "groupName": null, + "nameOverride": null, + "schema": "EndUser", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "json", + }, + "sdkName": null, + "server": [], + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "summary": "Get an end user by ID", + "tags": [ + "End users", + ], + }, + { + "audiences": [], + "authed": true, + "availability": null, + "description": "Update an end user. Request data is limited to 4KB in size total.", + "errors": { + "400": { + "description": "Bad Request", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "bad_request", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "{'profile': {'system_properties': ['Unknown field.']}}", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "BadRequestError", + }, + ], + "generatedName": "BadRequestError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "BadRequestErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "401": { + "description": "Unauthorized", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "unauthorized", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "You are not authorized to access this resource", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "UnauthorizedError", + }, + ], + "generatedName": "UnauthorizedError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "UnauthorizedErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "404": { + "description": "Not Found", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "resource_not_found", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "The requested resource with ID 5f7e0e2c1e7c7e000f0f9c3a was not found", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "NotFoundError", + }, + ], + "generatedName": "NotFoundError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "NotFoundErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "413": { + "description": "Content Too Large", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "content_too_large", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "Maximum request size of 4.0 MB exceeded. Content length: 5.0 MB.", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "ContentTooLargeError", + }, + ], + "generatedName": "ContentTooLargeError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "ContentTooLargeErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "429": { + "description": "Too Many Requests", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "rate_limit_exceeded", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "50 requests allowed per second", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "TooManyRequestsError", + }, + ], + "generatedName": "TooManyRequestsError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "TooManyRequestsErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "500": { + "description": "Internal Server Error", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "internal_server_error", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "InternalServerError", + }, + ], + "generatedName": "InternalServerError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "InternalServerErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + }, + "examples": [], + "generatedRequestName": "UpdateEndUserByIdRequest", + "headers": [], + "idempotent": null, + "internal": null, + "method": "PATCH", + "operationId": "updateEndUserById", + "pagination": null, + "path": "/end-users/v1/{end_user_id}", + "pathParameters": [ + { + "availability": null, + "description": "The end_user_id", + "name": "end_user_id", + "parameterNameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "UpdateEndUserByIdRequestEndUserId", + "groupName": [], + "nameOverride": null, + "schema": { + "default": null, + "format": null, + "maxLength": null, + "minLength": null, + "pattern": null, + "type": "string", + }, + "type": "primitive", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "variableReference": null, + }, + ], + "queryParameters": [], + "request": { + "additionalProperties": false, + "contentType": null, + "description": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "UpdateEndUserByIdRequest", + "groupName": null, + "nameOverride": null, + "schema": "EndUserRequest", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "json", + }, + "requestNameOverride": null, + "response": { + "description": "OK", + "responseProperty": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "UpdateEndUserByIdResponse", + "groupName": null, + "nameOverride": null, + "schema": "EndUser", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "json", + }, + "sdkName": null, + "server": [], + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "summary": "Update an end user by ID", + "tags": [ + "End users", + ], + }, + { + "audiences": [], + "authed": true, + "availability": null, + "description": "Get multiple end users", + "errors": { + "400": { + "description": "Bad Request", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "bad_request", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "{'profile': {'system_properties': ['Unknown field.']}}", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "BadRequestError", + }, + ], + "generatedName": "BadRequestError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "BadRequestErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "401": { + "description": "Unauthorized", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "unauthorized", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "You are not authorized to access this resource", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "UnauthorizedError", + }, + ], + "generatedName": "UnauthorizedError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "UnauthorizedErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "429": { + "description": "Too Many Requests", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "rate_limit_exceeded", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "50 requests allowed per second", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "TooManyRequestsError", + }, + ], + "generatedName": "TooManyRequestsError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "TooManyRequestsErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + "500": { + "description": "Internal Server Error", + "examples": [ + { + "description": null, + "example": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "errors", + }, + "value": { + "type": "array", + "value": [ + { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "msg", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "internal_server_error", + }, + }, + }, + { + "key": { + "type": "string", + "value": "details", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e", + }, + }, + }, + ], + }, + ], + }, + }, + ], + }, + "name": "InternalServerError", + }, + ], + "generatedName": "InternalServerError", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "InternalServerErrorBody", + "groupName": null, + "nameOverride": null, + "schema": "Errors", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + }, + "examples": [ + { + "codeSamples": [], + "description": null, + "headers": [], + "name": null, + "pathParameters": [], + "queryParameters": [], + "request": null, + "response": { + "type": "map", + "value": [ + { + "key": { + "type": "string", + "value": "key", + }, + "value": { + "type": "primitive", + "value": { + "type": "string", + "value": "value", + }, + }, + }, + ], + }, + "type": "full", + }, + ], + "generatedRequestName": "GetEndUsersRequest", + "headers": [], + "idempotent": null, + "internal": null, + "method": "GET", + "operationId": "getEndUsers", + "pagination": null, + "path": "/end-users/v1", + "pathParameters": [], + "queryParameters": [ + { + "availability": null, + "description": "The end user ID that marks the start or beginning of the returned profile records.", + "name": "cursor", + "parameterNameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "GetEndUsersRequestCursor", + "groupName": [], + "nameOverride": null, + "type": "nullable", + "value": { + "availability": null, + "description": null, + "generatedName": "GetEndUsersRequestCursor", + "groupName": [], + "nameOverride": null, + "schema": { + "default": null, + "format": null, + "maxLength": null, + "minLength": null, + "pattern": null, + "type": "string", + }, + "type": "primitive", + }, + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + { + "availability": null, + "description": "The number of end user profile records to return", + "name": "limit", + "parameterNameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "GetEndUsersRequestLimit", + "groupName": [], + "nameOverride": null, + "type": "nullable", + "value": { + "availability": null, + "description": null, + "generatedName": "GetEndUsersRequestLimit", + "groupName": [], + "nameOverride": null, + "schema": { + "default": null, + "exclusiveMaximum": null, + "exclusiveMinimum": null, + "maximum": 100, + "minimum": 1, + "multipleOf": null, + "type": "int", + }, + "type": "primitive", + }, + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + }, + ], + "request": null, + "requestNameOverride": null, + "response": { + "description": "OK", + "responseProperty": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "GetEndUsersResponse", + "groupName": null, + "nameOverride": null, + "schema": "EndUsers", + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "reference", + }, + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "json", + }, + "sdkName": null, + "server": [], + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "summary": "Get multiple end users by ID", + "tags": [ + "End users", + ], + }, + ], + "globalHeaders": [], + "groups": {}, + "hasEndpointsMarkedInternal": false, + "idempotencyHeaders": [], + "nonRequestReferencedSchemas": [ + "Errors", + "EndUser", + "EndUsers", + ], + "schemas": { + "EndUser": { + "generatedName": "EndUser", + "nameOverride": null, + "type": "unknown", + }, + "EndUserCreatedWebhookPayload": { + "additionalProperties": false, + "allOf": [], + "allOfPropertyConflicts": [], + "availability": null, + "description": null, + "generatedName": "EndUserCreatedWebhookPayload", + "groupName": [], + "nameOverride": null, + "properties": [ + { + "audiences": [], + "availability": null, + "conflict": {}, + "generatedName": "endUserCreatedWebhookPayloadType", + "key": "type", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "endUserCreatedWebhookPayloadType", + "groupName": [], + "nameOverride": null, + "type": "optional", + "value": { + "availability": null, + "description": null, + "generatedName": "EndUserCreatedWebhookPayloadType", + "groupName": [], + "nameOverride": null, + "schema": { + "default": null, + "format": null, + "maxLength": null, + "minLength": null, + "pattern": null, + "type": "string", + }, + "type": "primitive", + }, + }, + }, + { + "audiences": [], + "availability": null, + "conflict": {}, + "generatedName": "endUserCreatedWebhookPayloadTimestamp", + "key": "timestamp", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "endUserCreatedWebhookPayloadTimestamp", + "groupName": [], + "nameOverride": null, + "type": "optional", + "value": { + "availability": null, + "description": null, + "generatedName": "EndUserCreatedWebhookPayloadTimestamp", + "groupName": [], + "nameOverride": null, + "schema": { + "default": null, + "format": null, + "maxLength": null, + "minLength": null, + "pattern": null, + "type": "string", + }, + "type": "primitive", + }, + }, + }, + { + "audiences": [], + "availability": null, + "conflict": {}, + "generatedName": "endUserCreatedWebhookPayloadData", + "key": "data", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "endUserCreatedWebhookPayloadData", + "groupName": [], + "nameOverride": null, + "type": "optional", + "value": { + "generatedName": "EndUserCreatedWebhookPayloadData", + "nameOverride": null, + "type": "unknown", + }, + }, + }, + ], + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "object", + }, + "EndUserRequest": { + "generatedName": "EndUserRequest", + "nameOverride": null, + "type": "unknown", + }, + "EndUserUpdatedWebhookPayload": { + "additionalProperties": false, + "allOf": [], + "allOfPropertyConflicts": [], + "availability": null, + "description": null, + "generatedName": "EndUserUpdatedWebhookPayload", + "groupName": [], + "nameOverride": null, + "properties": [ + { + "audiences": [], + "availability": null, + "conflict": {}, + "generatedName": "endUserUpdatedWebhookPayloadType", + "key": "type", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "endUserUpdatedWebhookPayloadType", + "groupName": [], + "nameOverride": null, + "type": "optional", + "value": { + "availability": null, + "description": null, + "generatedName": "EndUserUpdatedWebhookPayloadType", + "groupName": [], + "nameOverride": null, + "schema": { + "default": null, + "format": null, + "maxLength": null, + "minLength": null, + "pattern": null, + "type": "string", + }, + "type": "primitive", + }, + }, + }, + { + "audiences": [], + "availability": null, + "conflict": {}, + "generatedName": "endUserUpdatedWebhookPayloadTimestamp", + "key": "timestamp", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "endUserUpdatedWebhookPayloadTimestamp", + "groupName": [], + "nameOverride": null, + "type": "optional", + "value": { + "availability": null, + "description": null, + "generatedName": "EndUserUpdatedWebhookPayloadTimestamp", + "groupName": [], + "nameOverride": null, + "schema": { + "default": null, + "format": null, + "maxLength": null, + "minLength": null, + "pattern": null, + "type": "string", + }, + "type": "primitive", + }, + }, + }, + { + "audiences": [], + "availability": null, + "conflict": {}, + "generatedName": "endUserUpdatedWebhookPayloadData", + "key": "data", + "nameOverride": null, + "schema": { + "availability": null, + "description": null, + "generatedName": "endUserUpdatedWebhookPayloadData", + "groupName": [], + "nameOverride": null, + "type": "optional", + "value": { + "generatedName": "EndUserUpdatedWebhookPayloadData", + "nameOverride": null, + "type": "unknown", + }, + }, + }, + ], + "source": { + "file": "ada/openapi.json", + "type": "openapi", + }, + "type": "object", + }, + "EndUsers": { + "generatedName": "EndUsers", + "nameOverride": null, + "type": "unknown", + }, + "Error": { + "generatedName": "Error", + "nameOverride": null, + "type": "unknown", + }, + "Errors": { + "generatedName": "Errors", + "nameOverride": null, + "type": "unknown", + }, + }, + "securitySchemes": { + "BearerAuth": { + "tokenEnvVar": null, + "tokenVariableName": null, + "type": "bearer", + }, + }, + "servers": [ + { + "audiences": null, + "description": "The subdomain of the client", + "name": null, + "url": "https://example.ada.support/api", + }, + ], + "tags": { + "orderedTagIds": [ + "End Users API", + ], + "tagsById": { + "End Users API": { + "description": "test", + "id": "End Users API", + }, + }, + }, + "title": "End Users API", + "variables": {}, + "webhooks": [], +} +`; diff --git a/packages/cli/openapi-parser/src/__test__/ada.test.ts b/packages/cli/openapi-parser/src/__test__/ada.test.ts new file mode 100644 index 00000000000..9b6acc4d745 --- /dev/null +++ b/packages/cli/openapi-parser/src/__test__/ada.test.ts @@ -0,0 +1,5 @@ +import { testParseOpenAPI } from "./testParseOpenApi"; + +describe("open api parser", () => { + testParseOpenAPI("ada", "openapi.json"); +}); diff --git a/packages/cli/openapi-parser/src/__test__/fixtures/ada/openapi.json b/packages/cli/openapi-parser/src/__test__/fixtures/ada/openapi.json new file mode 100644 index 00000000000..302ed03d19f --- /dev/null +++ b/packages/cli/openapi-parser/src/__test__/fixtures/ada/openapi.json @@ -0,0 +1,892 @@ +{ + "info": { + "title": "End Users API", + "version": "1.0.0", + "description": "test" + }, + "tags": [{ + "name": "End Users API", + "description": "test" + }], + "paths": { + "/end-users/v1/{end_user_id}": { + "get": { + "operationId": "getEndUserById", + "summary": "Get an end user by ID", + "description": "Get a specific end user", + "security": [{ + "BearerAuth": [] + }], + "tags": ["End users"], + "parameters": [{ + "in": "path", + "name": "end_user_id", + "schema": { + "type": "string" + }, + "required": true, + "description": "The end_user_id" + }], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUser" + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "UnauthorizedError": { + "$ref": "#/components/examples/UnauthorizedError" + } + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "NotFoundError": { + "$ref": "#/components/examples/NotFoundError" + } + } + } + } + }, + "429": { + "description": "Too Many Requests", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "TooManyRequestsError": { + "$ref": "#/components/examples/TooManyRequestsError" + } + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "InternalServerError": { + "$ref": "#/components/examples/InternalServerError" + } + } + } + } + } + } + }, + "patch": { + "operationId": "updateEndUserById", + "summary": "Update an end user by ID", + "description": "Update an end user. Request data is limited to 4KB in size total.", + "security": [{ + "BearerAuth": [] + }], + "tags": ["End users"], + "parameters": [{ + "in": "path", + "name": "end_user_id", + "schema": { + "type": "string" + }, + "required": true, + "description": "The end_user_id" + }], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUserRequest" + } + } + } + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUser" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "BadRequestError": { + "$ref": "#/components/examples/BadRequestError" + } + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "UnauthorizedError": { + "$ref": "#/components/examples/UnauthorizedError" + } + } + } + } + }, + "413": { + "description": "Content Too Large", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "ContentTooLargeError": { + "$ref": "#/components/examples/ContentTooLargeError" + } + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "NotFoundError": { + "$ref": "#/components/examples/NotFoundError" + } + } + } + } + }, + "429": { + "description": "Too Many Requests", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "TooManyRequestsError": { + "$ref": "#/components/examples/TooManyRequestsError" + } + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "InternalServerError": { + "$ref": "#/components/examples/InternalServerError" + } + } + } + } + } + } + } + }, + "/end-users/v1": { + "get": { + "operationId": "getEndUsers", + "summary": "Get multiple end users by ID", + "description": "Get multiple end users", + "security": [{ + "BearerAuth": [] + }], + "tags": ["End users"], + "parameters": [{ + "in": "query", + "name": "cursor", + "description": "The end user ID that marks the start or beginning of the returned profile records.", + "schema": { + "type": "string", + "examples": ["65a17e3f43bec88e2792d0eb"] + }, + "required": false + }, { + "in": "query", + "name": "limit", + "description": "The number of end user profile records to return", + "schema": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "examples": [8] + }, + "required": false + }], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUsers" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "BadRequestError": { + "$ref": "#/components/examples/BadRequestError" + } + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "UnauthorizedError": { + "$ref": "#/components/examples/UnauthorizedError" + } + } + } + } + }, + "429": { + "description": "Too Many Requests", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "TooManyRequestsError": { + "$ref": "#/components/examples/TooManyRequestsError" + } + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Errors" + }, + "examples": { + "InternalServerError": { + "$ref": "#/components/examples/InternalServerError" + } + } + } + } + } + } + } + }, + "/end-users/v1/spec": {}, + "/end-users/v1/docs": {} + }, + "openapi": "3.1.0", + "components": { + "schemas": { + "EndUser": { + "type": ["object"], + "properties": { + "end_user_id": { + "type": ["string"], + "readOnly": true, + "description": "The unique Ada-generated ID for the end user", + "examples": ["5f7e0e2c1e7c7e000f0f9c3a"] + }, + "profile": { + "description": "The end user's profile information", + "type": ["object"], + "properties": { + "first_name": { + "type": ["string", "null"], + "description": "The end user's first name", + "examples": ["Ada"] + }, + "last_name": { + "type": ["string", "null"], + "description": "The end user's last name", + "examples": ["Lovelace"] + }, + "email": { + "type": ["string", "null"], + "description": "The end user's email address", + "examples": ["ada.lovelace@ada.cx"] + }, + "language": { + "type": ["string", "null"], + "description": "The end user's language in BCP 47 format", + "examples": ["en-US"] + }, + "metadata": { + "type": ["object"], + "description": "A dictionary of arbitrary key, value pairs assigned to the end user - `metadata` keys may only be of type: `string` - `metadata` values may only be one of type: `string`, `boolean`, or `integer` ", + "examples": [{ + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }], + "additionalProperties": {} + }, + "system_properties": { + "type": ["object"], + "description": "Read-only profile information set by Ada", + "properties": { + "user_agent": { + "type": ["string", "null"], + "description": "The end user's browser user-agent information captured by Ada", + "examples": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"], + "readOnly": true + }, + "device": { + "type": ["string", "null"], + "description": "The end user's device information captured by Ada", + "examples": ["macos"], + "readOnly": true + }, + "browser": { + "type": ["string", "null"], + "description": "The end user's browser information captured by Ada", + "examples": ["Chrome"], + "readOnly": true + }, + "browser_version": { + "type": ["string", "null"], + "description": "The end user's browser version captured by Ada", + "examples": ["119.0.0.0"], + "readOnly": true + }, + "introshown": { + "type": ["boolean", "null"], + "description": "Whether the introductory message of a campaign has been displayed to the end user", + "examples": [false], + "readOnly": true + }, + "last_answer_id": { + "type": ["string", "null"], + "description": "The ID for the last answer displayed to the end user during a conversation", + "examples": ["650071321ef45533437f6f29"], + "readOnly": true + }, + "last_question_asked": { + "type": ["string", "null"], + "description": "The last question asked by the end user", + "examples": ["What is my account balance?"], + "readOnly": true + }, + "sunshine_first_message_id": { + "type": ["string", "null"], + "description": "The ID for the first message sent to the end user via Sunshine Conversations", + "examples": ["65736922f17d0bf841d8eeb4"], + "readOnly": true + }, + "sunshine_conversation_id": { + "type": ["string", "null"], + "description": "The ID for the Sunshine Conversation for this end user", + "examples": ["12345abc"], + "readOnly": true + }, + "sunshine_end_user_channel": { + "type": ["string", "null"], + "description": "The channel used to communicate with the end user via Sunshine Conversations", + "examples": ["whatsapp"], + "readOnly": true + }, + "sunshine_signed_up_at": { + "type": ["string", "null"], + "description": "The date the end user signed up for Sunshine Conversations", + "examples": ["2023-12-08T19:06:04.890000"], + "readOnly": true + }, + "sunshine_user_id": { + "type": ["string", "null"], + "description": "The Sunshine Conversations user ID for the end user", + "examples": ["5f7e0e2c1e7c7e000f0f9c3a"], + "readOnly": true + } + } + } + } + }, + "created_at": { + "type": ["string"], + "readOnly": true, + "description": "The date and time the end user was created", + "examples": ["2023-12-08T19:06:04.890000"] + }, + "updated_at": { + "type": ["string"], + "readOnly": true, + "description": "The date and time the end user was updated", + "examples": ["2023-12-08T19:06:04.890000"] + } + }, + "examples": [{ + "end_user_id": "5f7e0e2c1e7c7e000f0f9c3a", + "profile": { + "first_name": "Ada", + "last_name": "Lovelace", + "email": "ada.lovelace@ada.cx", + "language": "en-US", + "metadata": { + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }, + "system_properties": { + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", + "device": "macos", + "browser": "Chrome", + "browser_version": "119.0.0.0", + "introshown": false, + "last_answer_id": "650071321ef45533437f6f29", + "last_question_asked": "What is my account balance?", + "sunshine_first_message_id": "65736922f17d0bf841d8eeb4", + "sunshine_conversation_id": "12345abc", + "sunshine_end_user_channel": "whatsapp", + "sunshine_signed_up_at": "2023-12-08T19:06:04.890000", + "sunshine_user_id": "5f7e0e2c1e7c7e000f0f9c3a" + } + }, + "created_at": "2023-12-08T19:06:04.890000", + "updated_at": "2023-12-08T19:06:04.890000" + }] + }, + "EndUserRequest": { + "type": ["object"], + "required": ["profile"], + "properties": { + "profile": { + "description": "The end user's profile information", + "type": ["object"], + "properties": { + "first_name": { + "type": ["string", "null"], + "description": "The end user's first name", + "examples": ["Ada"] + }, + "last_name": { + "type": ["string", "null"], + "description": "The end user's last name", + "examples": ["Lovelace"] + }, + "email": { + "type": ["string", "null"], + "description": "The end user's email address", + "examples": ["ada.lovelace@ada.cx"] + }, + "language": { + "type": ["string", "null"], + "description": "The end user's language in BCP 47 format", + "examples": ["en-US"] + }, + "metadata": { + "type": ["object", "null"], + "description": "A dictionary of arbitrary key, value pairs assigned to the end user - `metadata` keys may only be of type: `string` - `metadata` values may only be one of type: `string`, `boolean`, or `integer` ", + "examples": [{ + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }], + "additionalProperties": {} + } + } + } + }, + "examples": [{ + "profile": { + "first_name": "Ada", + "last_name": "Lovelace", + "email": "ada.lovelace@ada.cx", + "language": "en-US", + "metadata": { + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + } + } + }] + }, + "Error": { + "type": ["object"], + "properties": { + "msg": { + "type": ["string"], + "description": "The error message", + "examples": ["resource_not_found"] + }, + "details": { + "type": ["string"], + "description": "Extra information about the error", + "examples": ["The requested resource with ID was not found"] + } + }, + "examples": [{ + "msg": "resource_not_found", + "details": "The requested resource with ID 123456abcdef was not found" + }], + "required": ["details", "msg"] + }, + "Errors": { + "type": ["object"], + "properties": { + "errors": { + "type": ["array"], + "description": "A list of errors", + "items": { + "$ref": "#/components/schemas/Error" + } + } + }, + "required": ["errors"] + }, + "EndUsers": { + "type": ["object"], + "properties": { + "end_users": { + "type": ["array"], + "description": "List of end user profiles", + "items": { + "$ref": "#/components/schemas/EndUser" + } + }, + "meta": { + "description": "Metadata returned with the results including but not limited to a link to the next page of data", + "type": ["object"], + "properties": { + "next_page_url": { + "type": ["string"], + "format": "url", + "description": "Link to the next page of data using a cursor value", + "examples": ["https://example.ada.support/api/end-users/v1?cursor=65a17e3f43bec88e2792d0eb"] + } + } + } + } + }, + "EndUserCreatedWebhookPayload": { + "properties": { + "type": { + "type": ["string"], + "readOnly": false, + "description": "The webhook event type description", + "examples": ["v1.end_user.created"] + }, + "timestamp": { + "type": ["string"], + "readOnly": false, + "description": "The timestamp for when the event was generated. Uses millisecond precision to help with event ordering needs.", + "examples": ["2024-01-17T22:23:35.835"] + }, + "data": { + "type": ["object"], + "description": "The webhook event data", + "allOf": [{ + "$ref": "#/components/schemas/EndUser" + }, { + "type": ["object"], + "properties": { + "end_user_id": { + "type": ["string"], + "description": "The unique Ada-generated ID for the end user", + "examples": ["5f7e0e2c1e7c7e000f0f9c3a"], + "readOnly": false + }, + "created_at": { + "type": ["string"], + "description": "The date and time the end user was created", + "examples": ["2023-12-08T19:06:02.000000"], + "readOnly": false + }, + "updated_at": { + "type": ["string"], + "description": "The date and time the end user was updated", + "examples": ["2023-12-08T19:06:04.890000"], + "readOnly": false + } + } + }] + } + }, + "examples": [{ + "type": "v1.end_user.created", + "timestamp": "2024-01-17T22:23:35.835", + "data": { + "end_user_id": "5f7e0e2c1e7c7e000f0f9c3a", + "profile": { + "first_name": "Ada", + "last_name": "Lovelace", + "email": "ada.lovelace@ada.cx", + "language": "en-US", + "metadata": { + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }, + "system_properties": { + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", + "device": "macos", + "browser": "Chrome", + "browser_version": "119.0.0.0", + "introshown": false, + "last_answer_id": "650071321ef45533437f6f29", + "last_question_asked": "What is my account balance?", + "sunshine_first_message_id": "65736922f17d0bf841d8eeb4", + "sunshine_conversation_id": "12345abc", + "sunshine_end_user_channel": "whatsapp", + "sunshine_signed_up_at": "2023-12-08T19:06:04.890000", + "sunshine_user_id": "5f7e0e2c1e7c7e000f0f9c3a" + } + }, + "created_at": "2023-12-08T19:06:04.890000", + "updated_at": "2023-12-08T19:06:04.890000" + } + }] + }, + "EndUserUpdatedWebhookPayload": { + "properties": { + "type": { + "type": ["string"], + "readOnly": false, + "description": "The webhook event type description", + "examples": ["v1.end_user.updated"] + }, + "timestamp": { + "type": ["string"], + "readOnly": false, + "description": "The timestamp for when the event was generated. Uses millisecond precision to help with event ordering needs.", + "examples": ["2024-01-17T22:23:35.835"] + }, + "data": { + "type": ["object"], + "description": "The webhook event data", + "allOf": [{ + "$ref": "#/components/schemas/EndUser" + }, { + "type": ["object"], + "properties": { + "end_user_id": { + "type": ["string"], + "description": "The unique Ada-generated ID for the end user", + "examples": ["5f7e0e2c1e7c7e000f0f9c3a"], + "readOnly": false + }, + "created_at": { + "type": ["string"], + "description": "The date and time the end user was created", + "examples": ["2023-12-08T19:06:02.000000"], + "readOnly": false + }, + "updated_at": { + "type": ["string"], + "description": "The date and time the end user was updated", + "examples": ["2023-12-08T19:06:04.890000"], + "readOnly": false + } + } + }] + } + }, + "examples": [{ + "type": "v1.end_user.updated", + "timestamp": "2024-01-17T22:23:35.835", + "data": { + "end_user_id": "5f7e0e2c1e7c7e000f0f9c3a", + "profile": { + "first_name": "Ada", + "last_name": "Lovelace", + "email": "ada.lovelace@ada.cx", + "language": "en-US", + "metadata": { + "example_key1": "example_string_value", + "example_key2": true, + "example_key3": 123 + }, + "system_properties": { + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", + "device": "macos", + "browser": "Chrome", + "browser_version": "119.0.0.0", + "introshown": false, + "last_answer_id": "650071321ef45533437f6f29", + "last_question_asked": "What is my account balance?", + "sunshine_first_message_id": "65736922f17d0bf841d8eeb4", + "sunshine_conversation_id": "12345abc", + "sunshine_end_user_channel": "whatsapp", + "sunshine_signed_up_at": "2023-12-08T19:06:04.890000", + "sunshine_user_id": "5f7e0e2c1e7c7e000f0f9c3a" + } + }, + "created_at": "2023-12-08T19:06:04.890000", + "updated_at": "2023-12-08T19:06:04.890000" + } + }] + } + }, + "examples": { + "BadRequestError": { + "value": { + "errors": [{ + "msg": "bad_request", + "details": "{'profile': {'system_properties': ['Unknown field.']}}" + }] + } + }, + "NotFoundError": { + "value": { + "errors": [{ + "msg": "resource_not_found", + "details": "The requested resource with ID 5f7e0e2c1e7c7e000f0f9c3a was not found" + }] + } + }, + "UnauthorizedError": { + "value": { + "errors": [{ + "msg": "unauthorized", + "details": "You are not authorized to access this resource" + }] + } + }, + "ContentTooLargeError": { + "value": { + "errors": [{ + "msg": "content_too_large", + "details": "Maximum request size of 4.0 MB exceeded. Content length: 5.0 MB." + }] + } + }, + "TooManyRequestsError": { + "value": { + "errors": [{ + "msg": "rate_limit_exceeded", + "details": "50 requests allowed per second" + }] + } + }, + "InternalServerError": { + "value": { + "errors": [{ + "msg": "internal_server_error", + "details": "An unknown error occurred. error_id: 91d435a7-e0b4-4c56-a097-8907e9ed851e" + }] + } + } + }, + "securitySchemes": { + "BearerAuth": { + "type": "http", + "scheme": "bearer" + } + } + }, + "webhooks": { + "v1.end_user.created": { + "post": { + "summary": "End user created webhook", + "description": "A webhook sent when a new end user is created", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUserCreatedWebhookPayload" + } + } + } + }, + "responses": { + "200": { + "description": "Return a 200 status to indicate that the data was received successfully" + } + }, + "tags": ["Webhooks"] + } + }, + "v1.end_user.updated": { + "post": { + "summary": "End user updated webhook", + "description": "A webhook sent when an end user is updated", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EndUserUpdatedWebhookPayload" + } + } + } + }, + "responses": { + "200": { + "description": "Return a 200 status to indicate that the data was received successfully" + } + }, + "tags": ["Webhooks"] + } + } + }, + "servers": [{ + "url": "https://{handle}.ada.support/api", + "variables": { + "handle": { + "default": "example" + } + }, + "description": "The subdomain of the client" + }] +} \ No newline at end of file diff --git a/packages/cli/openapi-parser/src/schema/convertSchemas.ts b/packages/cli/openapi-parser/src/schema/convertSchemas.ts index bae26e10be8..9f7856f69c2 100644 --- a/packages/cli/openapi-parser/src/schema/convertSchemas.ts +++ b/packages/cli/openapi-parser/src/schema/convertSchemas.ts @@ -546,6 +546,15 @@ export function convertSchemaObject( } } + // handle type array + if (Array.isArray(schema.type)) { + if (schema.oneOf == null) { + schema.oneOf = schema.type; + } else { + schema.oneOf.push(...schema.type); + } + } + // handle oneOf if (schema.oneOf != null && schema.oneOf.length > 0) { const isUndiscriminated = getExtension(schema, FernOpenAPIExtension.IS_UNDISCRIMINATED); From ad206a2551ccddfae060ef23fd1e1912e0f2a9ba Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Fri, 6 Sep 2024 11:40:50 -0400 Subject: [PATCH 2/3] add changelog --- packages/cli/cli/versions.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/cli/cli/versions.yml b/packages/cli/cli/versions.yml index 19a90998845..b4e8aeeb78e 100644 --- a/packages/cli/cli/versions.yml +++ b/packages/cli/cli/versions.yml @@ -1,4 +1,21 @@ - changelogEntry: + - summary: | + The Fern OpenAPI importer now handles importing an array for the `type` key. + + ``` + User: + properties: + name: + type: ["string"] + id: + type: ["string", "number"] + ``` + type: feat + created_at: '2024-09-06' + ir_version: 53 + version: 0.41.4 + +- changelog_entry: - summary: | Allow referencing by method and path. For example, when configuring an oauth scheme you can now do: From b453f40e59c5fb8cc887a96ba3ca03e7beccad89 Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Fri, 6 Sep 2024 11:46:44 -0400 Subject: [PATCH 3/3] fix --- packages/cli/cli/versions.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/cli/versions.yml b/packages/cli/cli/versions.yml index b4e8aeeb78e..2aa329f866a 100644 --- a/packages/cli/cli/versions.yml +++ b/packages/cli/cli/versions.yml @@ -15,7 +15,7 @@ ir_version: 53 version: 0.41.4 -- changelog_entry: +- changelogEntry: - summary: | Allow referencing by method and path. For example, when configuring an oauth scheme you can now do: @@ -31,11 +31,11 @@ auth: OAuth ``` type: feat - created_at: '2024-09-06' - ir_version: 53 + createdAt: '2024-09-06' + irVersion: 53 version: 0.41.3 -- changelog_entry: +- changelogEntry: - summary: | Fixes an issue introduced in `0.41.1` that ignored server urls for docs generation. type: fix