@xyd-js/openapi 0.1.0-xyd.1 → 0.1.0-xyd.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../semi/index.ts","../../src/const.ts","../../src/parameters.ts","../../src/properties.ts","../../src/requestBody.ts","../../src/responses.ts","../../src/schema.ts","../../src/paths.ts","../../src/utils.ts","../../src/examples.ts"],"sourcesContent":["import path from 'path';\n\nimport {\n deferencedOpenAPI,\n oapSchemaToReferences,\n} from \"../../src\";\nimport fs from \"fs\";\n\n(async () => {\n const openApiPath = path.join(process.cwd(), './examples/semi/openapi.yaml');\n const schema = await deferencedOpenAPI(openApiPath)\n const references = oapSchemaToReferences(schema)\n\n console.log(path.join(process.cwd(), './examples/semi/references.json'))\n fs.writeFileSync(path.join(process.cwd(), './examples/semi/references.json'), JSON.stringify(references, null, 2))\n console.log(2)\n})()\n\n","export const SUPPORTED_HTTP_METHODS: string[] = [\n 'get',\n 'put',\n 'patch',\n 'post',\n 'delete',\n // 'options',\n // 'head',\n // 'trace'\n];","import {OpenAPIV3} from \"openapi-types\";\nimport {DefinitionProperty} from \"@xyd-js/uniform\";\n\n// oapParametersToDefinitionProperties converts OpenAPI parameters to uniform DefinitionProperties\nexport function oapParametersToDefinitionProperties(\n parameters: OpenAPIV3.ParameterObject[]\n): { [key: string]: DefinitionProperty[] } {\n const parameterIn: { [key: string]: DefinitionProperty[] } = {}\n\n parameters.forEach((param) => {\n if (!parameterIn[param.in]) {\n parameterIn[param.in] = []\n }\n\n const schema = param.schema as OpenAPIV3.SchemaObject\n\n const property: DefinitionProperty = {\n name: param.name,\n type: schema.type || \"\",\n description: param.description || \"\"\n }\n\n parameterIn[param.in].push(property)\n })\n\n return parameterIn\n}\n","import {OpenAPIV3} from \"openapi-types\";\nimport {DefinitionProperty} from \"@xyd-js/uniform\";\n\n// schemaObjectToDefinitionProperties converts OpenAPI schema object to uniform DefinitionProperty[]\nexport function schemaObjectToDefinitionProperties(v: OpenAPIV3.SchemaObject): DefinitionProperty[] {\n return Object.entries(v.properties || {}).map(([name, prop]) => {\n let objProp = prop as OpenAPIV3.SchemaObject\n\n let merged: DefinitionProperty[] = []\n\n if (objProp.allOf) {\n merged = objProp.allOf.reduce((acc, of) => {\n return [\n ...acc,\n ...schemaObjectToDefinitionProperties(of as OpenAPIV3.SchemaObject)\n ]\n }, [] as DefinitionProperty[])\n }\n\n if (objProp.type === \"array\") {\n const items = objProp.items as OpenAPIV3.SchemaObject\n\n merged = schemaObjectToDefinitionProperties(items)\n }\n\n return {\n name: name,\n type: objProp.type || \"\",\n description: objProp.description || \"\",\n properties: (\n merged?.length\n ? merged\n : objProp.properties ? schemaObjectToDefinitionProperties(objProp) : []\n )\n }\n })\n}","import {OpenAPIV3} from \"openapi-types\";\nimport {DefinitionProperty} from \"@xyd-js/uniform\";\n\nimport {schemaObjectToDefinitionProperties} from \"./properties\";\n\n// oapRequestBodyToDefinitionProperties converts OpenAPI request body to uniform DefinitionProperties\nexport function oapRequestBodyToDefinitionProperties(\n reqBody: OpenAPIV3.RequestBodyObject\n): DefinitionProperty[] | null {\n // TODO: support other content types ???\n const schema = reqBody.content['application/json'].schema as OpenAPIV3.SchemaObject\n\n let schemaObject: OpenAPIV3.SchemaObject | undefined\n\n if (schema.allOf) {\n return schema.allOf.reduce((acc, of) => {\n const fakeBody: OpenAPIV3.RequestBodyObject = {\n content: {\n 'application/json': {\n schema: of\n }\n }\n }\n\n return [\n ...acc,\n ...oapRequestBodyToDefinitionProperties(fakeBody) || []\n ]\n }, [] as DefinitionProperty[])\n }\n\n switch (schema.type) {\n case 'object': {\n schemaObject = schema\n break\n }\n case 'array': {\n const arrSchema = schema as OpenAPIV3.ArraySchemaObject\n\n const items = arrSchema.items as OpenAPIV3.SchemaObject\n\n schemaObject = items\n break\n }\n default:\n // TODO: primitive types ???\n break\n }\n\n if (!schemaObject) {\n return null\n }\n\n return schemaObjectToDefinitionProperties(schemaObject)\n}","import {OpenAPIV3} from \"openapi-types\";\nimport {DefinitionProperty} from \"@xyd-js/uniform\";\n\nimport {schemaObjectToDefinitionProperties} from \"./properties\";\n\nexport function oapResponseToDefinitionProperties(\n responses: OpenAPIV3.ResponsesObject\n): DefinitionProperty[] | null {\n let schemaObject: OpenAPIV3.SchemaObject | undefined\n // TODO: support another statuses\n if (responses[\"default\"]) {\n const w = responses[\"default\"] as OpenAPIV3.ResponseObject\n\n schemaObject = w?.content?.['application/json']?.schema as OpenAPIV3.SchemaObject\n } else if (responses[\"200\"]) {\n const w = responses[\"200\"] as OpenAPIV3.ResponseObject\n\n schemaObject = w?.content?.['application/json']?.schema as OpenAPIV3.SchemaObject\n }\n\n if (!schemaObject) {\n return null\n }\n\n switch (schemaObject.type) {\n case 'array':\n const arrSchema = schemaObject as OpenAPIV3.ArraySchemaObject\n\n const items = arrSchema.items as OpenAPIV3.SchemaObject\n\n schemaObject = items\n break\n default:\n break\n }\n\n return schemaObjectToDefinitionProperties(schemaObject)\n}","import {OpenAPIV3} from \"openapi-types\";\nimport Oas from \"oas\";\n\nimport type {Reference, OpenAPIReferenceContext} from \"@xyd-js/uniform\";\n\nimport {SUPPORTED_HTTP_METHODS} from \"./const\";\nimport {oapPathToReference} from \"./paths\";\nimport {oapExamples} from \"./examples\";\n\n// TODO: support one-of\n// TODO: support $ref - currently we use $refParser.dereference that converts $ref into objects\n// TODO: better method check system - currently we need to manually check that in few methods\n\n// oapSchemaToReferences converts an OpenAPI schema to a list of uniform References\nexport function oapSchemaToReferences(\n schema: OpenAPIV3.Document\n): Reference[] {\n const references: Reference[] = [];\n const oas = new Oas(schema as any);\n\n const server = schema.servers?.[0]?.url || \"\"\n\n Object.entries(schema.paths).forEach(([path, oapPath]) => {\n SUPPORTED_HTTP_METHODS.forEach((eachMethod) => {\n const httpMethod = eachMethod.toLowerCase()\n\n switch (httpMethod) {\n case 'get':\n break\n case 'put':\n break\n case 'post':\n break\n case 'delete':\n break\n case 'patch':\n break\n default:\n console.error(`Unsupported method v111: ${httpMethod}`)\n return\n }\n\n const reference = oapPathToReference(\n httpMethod,\n path,\n oapPath as OpenAPIV3.PathItemObject\n )\n\n if (reference) {\n const ctx = reference.context as OpenAPIReferenceContext\n ctx.path = `${encodeURIComponent(server)}${encodeURIComponent(path)}` // TODO: it should be inside `oapPathToReference` ?\n\n const operation = oas.operation(path, httpMethod);\n reference.examples.groups = oapExamples(oas, operation)\n\n references.push(reference)\n }\n })\n })\n\n return references\n}\n","import {OpenAPIV3} from \"openapi-types\";\nimport {Definition, ExampleGroup, Reference, ReferenceCategory} from \"@xyd-js/uniform\";\n\nimport {oapParametersToDefinitionProperties} from \"./parameters\";\nimport {oapRequestBodyToDefinitionProperties} from \"./requestBody\";\nimport {oapResponseToDefinitionProperties} from \"./responses\";\nimport {\n httpMethodToUniformMethod,\n toPascalCase\n} from \"./utils\";\n\n// oapPathToReference converts an OpenAPI path to a uniform Reference\nexport function oapPathToReference(\n httpMethod: \"get\" | \"put\" | \"post\" | \"delete\" | \"patch\", // TODO: ts type\n path: string,\n oapPath: OpenAPIV3.PathItemObject,\n): Reference | null {\n const mType = httpMethodToUniformMethod(httpMethod)\n\n if (!mType) {\n console.error(`Unsupported method v222: ${httpMethod}`)\n return null\n }\n\n const definitions: Definition[] = []\n const exampleGroups: ExampleGroup[] = []\n\n const oapMethod = oapPath?.[httpMethod] as OpenAPIV3.OperationObject\n\n if (!oapMethod) {\n return null\n }\n\n const endpointRef: Reference = {\n title: oapMethod?.summary || \"\",\n canonical: toPascalCase(oapMethod?.summary || \"\"),\n description: oapMethod?.description || \"\",\n\n category: ReferenceCategory.REST,\n type: mType,\n\n context: {\n method: httpMethod,\n\n path: `${encodeURIComponent(path)}`,\n },\n\n examples: {\n groups: exampleGroups,\n },\n definitions: definitions,\n }\n\n if (oapMethod.parameters) {\n const parameters = oapMethod.parameters as OpenAPIV3.ParameterObject[]\n\n const paramtersMap = oapParametersToDefinitionProperties(parameters) // TODO: finish\n\n Object.entries(paramtersMap).forEach(([key, definitionProperties]) => {\n let title: string\n\n // TODO: add context to definition\n switch (key) {\n case 'path':\n title = \"Paths\"\n break\n case 'query':\n title = \"Query\"\n break\n case 'header':\n title = \"Header\"\n break\n default:\n console.error(`Unsupported parameter type: ${key} for ${httpMethod} ${path}`)\n return\n }\n\n definitions.push({\n title,\n properties: definitionProperties\n })\n })\n }\n\n if (oapMethod.requestBody) {\n const reqBody = oapMethod.requestBody as OpenAPIV3.RequestBodyObject\n\n definitions.push({\n title: 'Request body',\n properties: oapRequestBodyToDefinitionProperties(reqBody) || []\n })\n }\n\n if (oapMethod.responses) {\n const responses = oapMethod.responses as OpenAPIV3.ResponsesObject\n\n definitions.push({\n title: 'Response',\n properties: oapResponseToDefinitionProperties(responses) || []\n })\n }\n\n return endpointRef\n}\n","import path from \"path\";\nimport fs from \"fs\";\nimport yaml from \"js-yaml\";\nimport $refParser from \"json-schema-ref-parser\";\nimport {OpenAPIV3} from \"openapi-types\";\n\nimport {ReferenceType} from \"@xyd-js/uniform\";\n\ntype Parameters = {\n query?: Record<string, string | number | boolean>;\n headers?: Record<string, string>;\n};\n\nexport function toPascalCase(str: string): string {\n return str\n .split(/[\\s_-]+/)\n .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n .join('');\n}\n\n// readOpenApiSpec reads an OpenAPI spec file and returns the content\nfunction readOpenApiSpec(filePath: string) {\n const ext = path.extname(filePath).toLowerCase();\n const content = fs.readFileSync(filePath, 'utf-8');\n\n if (ext === '.yaml' || ext === '.yml') {\n return yaml.load(content);\n } else if (ext === '.json') {\n return JSON.parse(content);\n } else {\n throw new Error('Unsupported file format. Use JSON or YAML.');\n }\n}\n\n// deferencedOpenAPI reads an OpenAPI spec file and returns a dereferenced OpenAPIV3.Document\n// dereferenced means that all $ref references are resolved automatically\nexport async function deferencedOpenAPI(openApiPath: string) {\n const openApiSpec = readOpenApiSpec(openApiPath);\n\n //@ts-ignore TODO: fix ts\n await $refParser.dereference(openApiSpec);\n\n return openApiSpec as OpenAPIV3.Document\n}\n\n// httpMethodToUniformMethod converts an HTTP method to a uniform ReferenceType\nexport function httpMethodToUniformMethod(method: string): ReferenceType | null {\n switch (method) {\n case 'get':\n return ReferenceType.REST_HTTP_GET\n case 'put':\n return ReferenceType.REST_HTTP_PUT\n case 'patch':\n return ReferenceType.REST_HTTP_PATCH\n case 'post':\n return ReferenceType.REST_HTTP_POST\n case 'delete':\n return ReferenceType.REST_HTTP_DELETE\n // case 'options':\n // return ReferenceType.REST_HTTP_OPTIONS\n // case 'head':\n // return ReferenceType.REST_HTTP_HEAD\n // case 'trace':\n // return ReferenceType.REST_HTTP_TRACE\n default:\n return null\n }\n}\n\n// schemaToRequestBody generates a request body from an OpenAPI schema\nfunction schemaToRequestBody(schema: OpenAPIV3.SchemaObject): string {\n const requestBody: any = {};\n\n if (schema.type === 'object' && schema.properties) {\n for (const [key, value] of Object.entries(schema.properties)) {\n if ((value as OpenAPIV3.SchemaObject).default !== undefined) {\n requestBody[key] = (value as OpenAPIV3.SchemaObject).default;\n } else {\n requestBody[key] = null; // or some placeholder value\n }\n }\n }\n\n return JSON.stringify(requestBody);\n}\n\n// generateRequestInitFromOpenAPIObject generates a RequestInit object from an OpenAPI object\nexport function generateRequestInitFromOapOperation(\n urlPath: string,\n operation: OpenAPIV3.OperationObject\n): { url: string, reqInit: RequestInit } {\n const reqInit: RequestInit = {}\n let queryParams = '';\n\n if (operation.parameters) {\n const parameters = operation.parameters as OpenAPIV3.ParameterObject[]\n\n const params = new URLSearchParams(\n Object.entries(parameters).map(([key, value]) => [key, String(value)])\n ).toString();\n\n queryParams += `?${params}`;\n }\n\n if (operation.requestBody) {\n const reqBody = operation.requestBody as OpenAPIV3.RequestBodyObject;\n const contentType = Object.keys(reqBody.content || {})[0];\n\n if (contentType === \"application/json\") {\n const schema = reqBody.content['application/json'].schema as OpenAPIV3.SchemaObject\n\n reqInit.body = schemaToRequestBody(schema);\n reqInit.headers = {\n 'Content-Type': 'application/json',\n }\n }\n }\n\n return {\n url: `${urlPath}${queryParams}`,\n reqInit,\n };\n}\n\n","import {OpenAPIV3} from \"openapi-types\";\nimport Oas from \"oas\";\n// @ts-ignore\nimport {Operation} from 'oas/operation'; // TODO: fix ts\nimport oasToSnippet from \"@readme/oas-to-snippet\";\nimport OpenAPISampler from \"openapi-sampler\";\nimport type {JSONSchema7} from \"json-schema\";\n\nimport {ExampleGroup, Example} from \"@xyd-js/uniform\";\n\n// TODO: option with another languages\n// TODO: uniform plugins\n// TODO: fs uniform plugins\nexport function oapExamples(\n oas: Oas,\n operation: Operation\n): ExampleGroup[] {\n const exampleGroups: ExampleGroup[] = []\n\n if (operation.schema.requestBody) {\n const body = operation.schema.requestBody as OpenAPIV3.RequestBodyObject\n const schema = fixAllOfBug(\n body.content[\"application/json\"].schema as JSONSchema7\n )\n\n if (!schema) {\n return exampleGroups\n }\n\n const fakeData = OpenAPISampler.sample(schema)\n\n // TODO: snippet languages options\n const {code} = oasToSnippet(oas, operation, {\n body: fakeData\n }, null, \"shell\");\n\n const examples: Example[] = []\n\n examples.push({\n codeblock: {\n tabs: [{\n title: \"curl\",\n language: \"curl\",\n code: code || \"\",\n }]\n }\n })\n\n exampleGroups.push({\n description: \"Example request\",\n examples\n })\n }\n\n if (operation.schema.responses) {\n const responses = operation.schema.responses as OpenAPIV3.ResponsesObject\n\n const examples: Example[] = []\n\n Object.entries(responses).forEach(([status, r]) => {\n const response = r as OpenAPIV3.ResponseObject\n const schema = response?.content?.[\"application/json\"].schema as JSONSchema7\n\n if (!schema) {\n return\n }\n\n const fakeData = OpenAPISampler.sample(schema)\n\n examples.push({\n codeblock: {\n title: status,\n tabs: [{\n title: \"json\",\n language: \"json\",\n code: JSON.stringify(fakeData, null, 2) || \"\",\n }]\n }\n })\n })\n\n exampleGroups.push({\n description: \"Response\",\n examples\n })\n }\n\n return exampleGroups\n}\n\n/*\nfixAllOfBug fixes below case:\n\n```yaml\n allOf:\n - $ref: '#/components/schemas/SomeSchema'\n - type: object\n required:\n properties:\n```\n*/\nfunction fixAllOfBug(schema: JSONSchema7) {\n const modifiedSchema = {...schema}\n\n if (schema.allOf) {\n schema.allOf.forEach((prop, i) => {\n const propObj = prop as object\n\n if (\"properties\" in propObj && !propObj[\"properties\"]) {\n delete modifiedSchema.allOf?.[i]\n }\n })\n }\n\n return modifiedSchema\n}"],"mappings":"AAAA,OAAOA,MAAU,OCAV,IAAMC,EAAmC,CAC5C,MACA,MACA,QACA,OACA,QAIJ,ECLO,SAASC,EACZC,EACuC,CACvC,IAAMC,EAAuD,CAAC,EAE9D,OAAAD,EAAW,QAASE,GAAU,CACrBD,EAAYC,EAAM,EAAE,IACrBD,EAAYC,EAAM,EAAE,EAAI,CAAC,GAG7B,IAAMC,EAASD,EAAM,OAEfE,EAA+B,CACjC,KAAMF,EAAM,KACZ,KAAMC,EAAO,MAAQ,GACrB,YAAaD,EAAM,aAAe,EACtC,EAEAD,EAAYC,EAAM,EAAE,EAAE,KAAKE,CAAQ,CACvC,CAAC,EAEMH,CACX,CCtBO,SAASI,EAAmCC,EAAiD,CAChG,OAAO,OAAO,QAAQA,EAAE,YAAc,CAAC,CAAC,EAAE,IAAI,CAAC,CAACC,EAAMC,CAAI,IAAM,CAC5D,IAAIC,EAAUD,EAEVE,EAA+B,CAAC,EAWpC,GATID,EAAQ,QACRC,EAASD,EAAQ,MAAM,OAAO,CAACE,EAAKC,IACzB,CACH,GAAGD,EACH,GAAGN,EAAmCO,CAA4B,CACtE,EACD,CAAC,CAAyB,GAG7BH,EAAQ,OAAS,QAAS,CAC1B,IAAMI,EAAQJ,EAAQ,MAEtBC,EAASL,EAAmCQ,CAAK,CACrD,CAEA,MAAO,CACH,KAAMN,EACN,KAAME,EAAQ,MAAQ,GACtB,YAAaA,EAAQ,aAAe,GACpC,WACIC,GAAA,MAAAA,EAAQ,OACFA,EACAD,EAAQ,WAAaJ,EAAmCI,CAAO,EAAI,CAAC,CAElF,CACJ,CAAC,CACL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F,EAAO,KAAK,EAAE,QAAQ,CAAC,CAACO,EAAMC,CAAO,IAAM,CACtDC,EAAuB,QAASC,GAAe,CAC3C,IAAMC,EAAaD,EAAW,YAAY,EAE1C,OAAQC,EAAY,CAChB,IAAK,MACD,MACJ,IAAK,MACD,MACJ,IAAK,OACD,MACJ,IAAK,SACD,MACJ,IAAK,QACD,MACJ,QACI,QAAQ,MAAM,4BAA4BA,CAAU,EAAE,EACtD,MACR,CAEA,IAAMC,EAAYC,EACdF,EACAJ,EACAC,CACJ,EAEA,GAAII,EAAW,CACX,IAAME,EAAMF,EAAU,QACtBE,EAAI,KAAO,GAAG,mBAAmBR,CAAM,CAAC,GAAG,mBAAmBC,CAAI,CAAC,GAEnE,IAAMQ,EAAYX,EAAI,UAAUG,EAAMI,CAAU,EAChDC,EAAU,SAAS,OAASI,EAAYZ,EAAKW,CAAS,EAEtDZ,EAAW,KAAKS,CAAS,CAC7B,CACJ,CAAC,CACL,CAAC,EAEMT,CACX,CNvDA,OAAOc,MAAQ,MAEd,SAAY,CACT,IAAMC,EAAcC,EAAK,KAAK,QAAQ,IAAI,EAAG,8BAA8B,EACrEC,EAAS,MAAMC,EAAkBH,CAAW,EAC5CI,EAAaC,EAAsBH,CAAM,EAE/C,QAAQ,IAAID,EAAK,KAAK,QAAQ,IAAI,EAAG,iCAAiC,CAAC,EACvEF,EAAG,cAAcE,EAAK,KAAK,QAAQ,IAAI,EAAG,iCAAiC,EAAG,KAAK,UAAUG,EAAY,KAAM,CAAC,CAAC,EACjH,QAAQ,IAAI,CAAC,CACjB,GAAG","names":["path","SUPPORTED_HTTP_METHODS","oapParametersToDefinitionProperties","parameters","parameterIn","param","schema","property","schemaObjectToDefinitionProperties","v","name","prop","objProp","merged","acc","of","items","oapRequestBodyToDefinitionProperties","reqBody","schema","schemaObject","acc","of","fakeBody","schemaObjectToDefinitionProperties","oapResponseToDefinitionProperties","responses","_a","_b","_c","_d","schemaObject","w","schemaObjectToDefinitionProperties","Oas","ReferenceCategory","path","fs","yaml","$refParser","ReferenceType","toPascalCase","str","word","readOpenApiSpec","filePath","ext","content","deferencedOpenAPI","openApiPath","openApiSpec","httpMethodToUniformMethod","method","oapPathToReference","httpMethod","path","oapPath","mType","httpMethodToUniformMethod","definitions","exampleGroups","oapMethod","endpointRef","toPascalCase","ReferenceCategory","parameters","paramtersMap","oapParametersToDefinitionProperties","key","definitionProperties","title","reqBody","oapRequestBodyToDefinitionProperties","responses","oapResponseToDefinitionProperties","oasToSnippet","OpenAPISampler","oapExamples","oas","operation","exampleGroups","body","schema","fixAllOfBug","fakeData","code","examples","responses","status","r","_a","response","modifiedSchema","prop","i","propObj","oapSchemaToReferences","schema","_a","_b","references","oas","Oas","server","path","oapPath","SUPPORTED_HTTP_METHODS","eachMethod","httpMethod","reference","oapPathToReference","ctx","operation","oapExamples","fs","openApiPath","path","schema","deferencedOpenAPI","references","oapSchemaToReferences"]}
@@ -0,0 +1,16 @@
1
+ import path from 'path';
2
+
3
+ import {
4
+ deferencedOpenAPI,
5
+ oapSchemaToReferences,
6
+ } from "../../src";
7
+ import fs from "fs";
8
+
9
+ (async () => {
10
+ const openApiPath = path.join(process.cwd(), './examples/semi/openapi.yaml');
11
+ const schema = await deferencedOpenAPI(openApiPath)
12
+ const references = oapSchemaToReferences(schema)
13
+
14
+ fs.writeFileSync(path.join(process.cwd(), './examples/semi/references.json'), JSON.stringify(references, null, 2))
15
+ })()
16
+
@@ -0,0 +1,365 @@
1
+ openapi: 3.1.0
2
+
3
+ info:
4
+ title: LiveSession API
5
+ version: v1
6
+
7
+ servers:
8
+ - url: https://api.livesession.io/v1
9
+ description: Production server (uses live data)
10
+
11
+ paths:
12
+ # BEGIN Sessions
13
+ /sessions:
14
+ get:
15
+ summary: Get Sessions
16
+ security:
17
+ - livesession_oauth: [ users.sessions:read ]
18
+ - api_token: [ users.sessions:read ]
19
+ description: |
20
+ ---
21
+ title: List sessions
22
+ group: [ENDPOINTS]
23
+ ---
24
+
25
+ List of all sessions
26
+ tags:
27
+ - Sessions
28
+ parameters:
29
+ - name: page
30
+ in: query
31
+ description: The number of page to start with (default 0, max 10000).
32
+ schema:
33
+ type: integer
34
+ - name: size
35
+ in: query
36
+ description: The number of page's size (default 25, max 100).
37
+ schema:
38
+ type: integer
39
+ - name: email
40
+ in: query
41
+ description: The email address that you have associated with a session via [identify](https://developers.livesession.io/javascript-api/methods/#identify).
42
+ schema:
43
+ type: string
44
+ - name: visitor_id
45
+ in: query
46
+ description: The visitor ID.
47
+ schema:
48
+ type: string
49
+ - name: tz
50
+ in: query
51
+ description: IANA timezone. Default Europe/London if RelativeDateString is applied.
52
+ schema:
53
+ type: string
54
+ - name: date_from
55
+ in: query
56
+ description: ISO 8601 string or RelativeDateString. For RelativeDateString see table below for possible values.
57
+ schema:
58
+ oneOf:
59
+ - type: string
60
+ - $ref: '#/components/schemas/RelativeDateString'
61
+ - name: date_to
62
+ in: query
63
+ description: ISO 8601 string or [RelativeDateString](#/components/schemas/RelativeDateString). For RelativeDateString see table below for possible values.
64
+ schema:
65
+ oneOf:
66
+ - type: string
67
+ - $ref: '#/components/schemas/RelativeDateString'
68
+ responses:
69
+ '200':
70
+ description: Successful response
71
+ content:
72
+ application/json:
73
+ schema:
74
+ $ref: '#/components/schemas/GetListSessionsResponse'
75
+ '400':
76
+ description: 400 response
77
+ content:
78
+ application/json:
79
+ schema:
80
+ $ref: '#/components/schemas/ErrorResponse'
81
+ '500':
82
+ description: 500 response
83
+ content:
84
+ application/json:
85
+ schema:
86
+ $ref: '#/components/schemas/ErrorResponse'
87
+
88
+ components:
89
+ securitySchemes:
90
+ api_token:
91
+ type: apiKey
92
+ name: Authorization
93
+ description: "[API Tokens](https://developers.livesession.io/rest-api/introduction/#creating-a-personal-access-token)"
94
+ in: header
95
+
96
+ livesession_oauth:
97
+ type: oauth2
98
+ flows:
99
+ authorizationCode:
100
+ authorizationUrl: https://apis.livesession.io/accounts/v1/oauth2/authorize # TODO: more friendly url
101
+ tokenUrl: https://apis.livesession.io/accounts/v1/oauth2/access_token # TODO: more friendly url
102
+ refreshUrl: https://apis.livesession.io/accounts/v1/oauth2/access_token # TODO: more friendly url
103
+ scopes:
104
+ users.sessions:read: read user sessions
105
+
106
+ webhooks:read: read webhooks
107
+ webhooks:write: write webhooks
108
+
109
+ alerts:read: read alerts
110
+ alerts:write: write alerts
111
+
112
+ websites:read: read websites
113
+ websites:write: write websites
114
+
115
+ payment_intents:write: write payment intents
116
+ payment_intents.confirm: confirm payment intents
117
+
118
+ schemas:
119
+
120
+ # BEGIN Errors
121
+ ErrorResponse:
122
+ type: object
123
+ properties:
124
+ error:
125
+ type: object
126
+ properties:
127
+ type:
128
+ type: string
129
+ code:
130
+ type: string
131
+ param:
132
+ type: string
133
+ message:
134
+ type: string
135
+ http_status_code:
136
+ type: integer
137
+ request_id:
138
+ type: string
139
+
140
+ # END Errors
141
+
142
+ # BEGIN Sessions
143
+ Session:
144
+ type: object
145
+ properties:
146
+ id:
147
+ type: string
148
+ website_id:
149
+ type: string
150
+ session_url:
151
+ type: string
152
+ creation_timestamp:
153
+ type: integer
154
+ duration:
155
+ type: integer
156
+ end_timestamp:
157
+ type: integer
158
+ active_time:
159
+ type: integer
160
+ end_url:
161
+ type: string
162
+ expiration_timestamp:
163
+ type: integer
164
+ last_event_timestamp:
165
+ type: integer
166
+ product:
167
+ type: string
168
+ device:
169
+ type: string
170
+ tags:
171
+ type: array
172
+ items:
173
+ type: string
174
+ last_seen_page_view_id:
175
+ type: string
176
+ seen:
177
+ type: boolean
178
+ referrer:
179
+ type: string
180
+ start_url:
181
+ type: string
182
+ visitor_first_session:
183
+ type: boolean
184
+ engagment_score:
185
+ type: number
186
+ visitor:
187
+ $ref: '#/components/schemas/SessionVisitorData'
188
+ resolution:
189
+ $ref: '#/components/schemas/SessionResolutionData'
190
+ os:
191
+ $ref: '#/components/schemas/SessionOsData'
192
+ browser:
193
+ $ref: '#/components/schemas/SessionBrowserData'
194
+ utm:
195
+ $ref: '#/components/schemas/SessionUTMData'
196
+ page_views_statistics:
197
+ $ref: '#/components/schemas/SessionPageViewsStatisticsData'
198
+ events_statistics:
199
+ $ref: '#/components/schemas/SessionEventsStatisticsData'
200
+
201
+ SessionVisitorData:
202
+ type: object
203
+ properties:
204
+ id:
205
+ type: string
206
+ ip:
207
+ type: string
208
+ geolocation:
209
+ $ref: '#/components/schemas/SessionVisitorDataGeolocation'
210
+ name:
211
+ type: string
212
+ email:
213
+ type: string
214
+ email_hash:
215
+ type: string
216
+ params:
217
+ type: array
218
+ items:
219
+ $ref: '#/components/schemas/SessionVisitorDataParams'
220
+ last_session_timestamp:
221
+ type: integer
222
+ first_session_timestamp:
223
+ type: integer
224
+
225
+ SessionOsData:
226
+ type: object
227
+ properties:
228
+ name:
229
+ type: string
230
+ version:
231
+ type: string
232
+
233
+ SessionBrowserData:
234
+ type: object
235
+ properties:
236
+ description:
237
+ type: string
238
+ name:
239
+ type: string
240
+ version:
241
+ type: string
242
+
243
+ SessionUTMData:
244
+ type: object
245
+ properties:
246
+ source:
247
+ type: string
248
+ medium:
249
+ type: string
250
+ campaign:
251
+ type: string
252
+ term:
253
+ type: string
254
+ content:
255
+ type: string
256
+
257
+ SessionEventsStatisticsData:
258
+ type: object
259
+ properties:
260
+ clicks:
261
+ type: integer
262
+ error_clicks:
263
+ type: integer
264
+ rage_clicks:
265
+ type: integer
266
+ error_logs:
267
+ type: integer
268
+ net_errors:
269
+ type: integer
270
+
271
+ SessionPageViewLocationData:
272
+ type: object
273
+ properties:
274
+ base:
275
+ type: string
276
+ href:
277
+ type: string
278
+ origin:
279
+ type: string
280
+ referrer:
281
+ type: string
282
+
283
+ SessionPageViewViewPortData:
284
+ type: object
285
+ properties:
286
+ height:
287
+ type: integer
288
+ width:
289
+ type: integer
290
+
291
+ SessionVisitorDataGeolocation:
292
+ type: object
293
+ properties:
294
+ country_code:
295
+ type: string
296
+ city:
297
+ type: string
298
+ region:
299
+ type: string
300
+
301
+ SessionVisitorDataParams:
302
+ type: object
303
+ properties:
304
+ name:
305
+ type: string
306
+ value:
307
+ type: string
308
+
309
+ SessionResolutionData:
310
+ type: object
311
+ properties:
312
+ height:
313
+ type: integer
314
+ width:
315
+ type: integer
316
+ resolution:
317
+ type: string
318
+
319
+ SessionPageViewsStatisticsData:
320
+ type: object
321
+ properties:
322
+ count:
323
+ type: integer
324
+
325
+ GetListSessionsResponse:
326
+ type: object
327
+ properties:
328
+ total:
329
+ type: integer
330
+ page:
331
+ $ref: '#/components/schemas/Pagination'
332
+ sessions:
333
+ type: array
334
+ items:
335
+ $ref: '#/components/schemas/Session'
336
+
337
+ Pagination:
338
+ type: object
339
+ properties:
340
+ num:
341
+ type: integer
342
+ size:
343
+ type: integer
344
+
345
+ RelativeDateString:
346
+ type: string
347
+ description: |
348
+ * `TODAY` - Today since midnight
349
+ * `YESTERDAY` - Yesterday since midnight
350
+ * `BEGINNING_OF_WEEK` - Nearest monday since midnight
351
+ * `BEGINNING_OF_MONTH` - 1st of the month since midnight
352
+ * `BEGINNING_OF_PREV_MONTH` - Previous 1st of the month since midnight
353
+ * `TODAY-7DAYS` - Exact 7 days ago since midnight
354
+ * `TODAY-30DAYS` - Exact 30 days ago since midnight
355
+ enum:
356
+ - TODAY
357
+ - YESTERDAY
358
+ - BEGINNING_OF_WEEK
359
+ - BEGINNING_OF_MONTH
360
+ - BEGINNING_OF_PREV_MONTH
361
+ - TODAY-7DAYS
362
+ - TODAY-30DAYS
363
+ # END Sessions
364
+
365
+