-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ call getEvents endpoints for events and aggregateIds
- Loading branch information
Showing
8 changed files
with
127 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,22 @@ | ||
import SwaggerClient from 'swagger-client'; | ||
|
||
// import swagger from './pokeapi.json'; | ||
import swagger from './pokeapi.json'; | ||
|
||
const main = async () => { | ||
// console.log(swagger); | ||
await Promise.resolve(); | ||
const apiClient = new SwaggerClient( | ||
'https://petstore.swagger.io/v2/swagger.json', | ||
); | ||
// eslint-disable-next-line @typescript-eslint/await-thenable | ||
const client = await apiClient; | ||
const apis = client.apis; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const petApi = apis.pet; | ||
console.log('getPokemon', petApi); | ||
if (petApi === undefined) { | ||
console.log('petApi is not defined'); | ||
const apiClient = new SwaggerClient({ spec: swagger }); | ||
|
||
const apis = apiClient.apis; | ||
|
||
return; | ||
} | ||
const findPetsByTags = petApi.findPetsByTags; | ||
if (findPetsByTags === undefined) { | ||
console.log('findPetsByTags is not defined'); | ||
const pokemonApi = apis.default; | ||
console.log('getPokemon', pokemonApi); | ||
const getPokemon = pokemonApi.getEvents; | ||
|
||
return; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const response = await findPetsByTags({ tags: ['dogs'] }); | ||
console.log(response); | ||
const { body } = await getPokemon({ | ||
idOrName: ['pikachu'], | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
// const body = response.body; | ||
console.log(body); | ||
}; | ||
void main(); |
25 changes: 19 additions & 6 deletions
25
packages/http-event-storage-adapter/src/swaggerClient.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
declare module 'swagger-client' { | ||
import type { Swagger, Tag } from './utils/types.d.ts'; | ||
import { EventDetail } from '@castore/core'; | ||
|
||
type Api = { | ||
getEvents: ( | ||
arg: Record<unknown, unknown>, | ||
) => Promise<{ body: { events: EventDetail[] } }>; | ||
}; | ||
|
||
export default class SwaggerClient { | ||
http(request: unknown): unknown; | ||
apis: Record< | ||
string, | ||
Record<string, (arg: Record<unknown, unknown>) => unknown> | ||
>; | ||
apis: { | ||
default: Api; | ||
event?: Api; | ||
}; | ||
tags: Tag[]; | ||
|
||
constructor(url: unknown, options?: Record<string, unknown>); | ||
constructor( | ||
url: string | { spec: Swagger }, | ||
options?: Record<string, unknown>, | ||
); | ||
} | ||
export type SwaggerClientConstructor = new ( | ||
url: unknown, | ||
url: string | { spec: Swagger }, | ||
options?: Record<string, unknown>, | ||
) => SwaggerClient; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/http-event-storage-adapter/src/utils/getEventTag.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Tag } from './types'; | ||
|
||
export const getEventTag = (swagger: { tags?: Tag[] }): 'default' | 'event' => { | ||
const { tags } = swagger; | ||
if (tags === undefined || tags.length === 0) { | ||
return 'default'; | ||
} | ||
const hasEventTag = tags.findIndex(tag => tag.name === 'event'); | ||
if (hasEventTag > -1) { | ||
return 'event'; | ||
} | ||
|
||
return 'default'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
type Contact = Record<string, unknown>; | ||
type License = Record<string, unknown>; | ||
|
||
type Info = { | ||
title: string; // The title of the API. | ||
version: string; // The version of the OpenAPI document (which is distinct from the OpenAPI Specification version or the API implementation version). | ||
summary?: string; | ||
description?: string; // A short description of the API. | ||
termsOfService?: string; | ||
contact?: Contact; | ||
license: License; | ||
}; | ||
|
||
type Server = { | ||
url: string; | ||
description?: string; | ||
variables?: Record<string, unknown>; | ||
}; | ||
|
||
type ExternalDocumentation = { | ||
url: string; | ||
description?: string; | ||
}; | ||
|
||
type PathItem = { | ||
$ref?: string; // Allows for a referenced definition of this path item. The referenced structure MUST be in the form of a Path Item Object. In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined. See the rules for resolving Relative References. | ||
summary?: string; // An optional, string summary, intended to apply to all operations in this path. | ||
description?: string; // An optional, string description, intended to apply to all operations in this path. CommonMark syntax MAY be used for rich text representation. | ||
}; | ||
|
||
type Path = Record<string, PathItem>; | ||
|
||
export type Tag = { | ||
name: string; // The name of the tag. | ||
description?: string; // A description for the tag. CommonMark syntax MAY be used for rich text representation. | ||
externalDocs: ExternalDocumentation; | ||
}; | ||
|
||
export type Swagger = { | ||
openapi: string; // This string MUST be the version number of the OpenAPI Specification that the OpenAPI document uses. | ||
infoObject: Info; // Provides metadata about the API. The metadata MAY be used by tooling as required. | ||
jsonSchemaDialect?: string; // The default value for the $schema keyword within Schema Objects contained within this OAS document. This MUST be in the form of a URI. | ||
servers?: Server[]; // An array of Server Objects, which provide connectivity information to a target server. If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of /. | ||
paths?: Path[]; | ||
webhooks?: Record<string, unknown>; | ||
components?: unknown; | ||
security?: Record<string, unknown>[]; | ||
tags?: Tag[]; | ||
externalDocs?: ExternalDocumentation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters