diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 97213ec2fe9e..45e6d8157709 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -86549,6 +86549,34 @@ components: required: - data type: object + TestExample: + description: A test example resource. + properties: + created_at: + description: Creation time of the test example. + format: date-time + readOnly: true + type: string + id: + description: The ID of the test example. + example: "abc-123" + type: string + name: + description: The name of the test example. + example: "My Test Example" + type: string + required: + - id + - name + type: object + TestExamplesResponse: + description: Response containing a list of test examples. + properties: + data: + items: + $ref: "#/components/schemas/TestExample" + type: array + type: object TestOptimizationDeleteServiceSettingsRequest: description: Request object for deleting Test Optimization service settings. properties: @@ -158742,6 +158770,34 @@ paths: operator: OR permissions: - teams_read + /api/v2/test-examples: + get: + description: Get a list of all test examples. + operationId: ListTestExamples + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - id: "abc-123" + name: "My Test Example" + schema: + $ref: "#/components/schemas/TestExamplesResponse" + description: OK + "403": + $ref: "#/components/responses/ForbiddenResponse" + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: List test examples + tags: + - Test Examples + x-permission: + operator: OR + permissions: + - test_read /api/v2/test/flaky-test-management/tests: patch: description: |- @@ -162115,6 +162171,8 @@ tags: name: Synthetics - description: View and manage teams within Datadog. See the [Teams page](https://docs.datadoghq.com/account_management/teams/) for more information. name: Teams + - description: Manage test example resources. + name: Test Examples - description: |- Search and manage flaky tests through Test Optimization. See the [Test Optimization page](https://docs.datadoghq.com/tests/) for more information. name: Test Optimization diff --git a/features/v2/test_examples.feature b/features/v2/test_examples.feature new file mode 100644 index 000000000000..263011b0ce3c --- /dev/null +++ b/features/v2/test_examples.feature @@ -0,0 +1,12 @@ +@endpoint(test-examples) @endpoint(test-examples-v2) +Feature: Test Examples + Manage test example resources. + + @generated @skip @team:DataDog/webframeworks-test + Scenario: List test examples returns "OK" response + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "TestExamples" API + And new "ListTestExamples" request + When the request is sent + Then the response status is 200 OK diff --git a/features/v2/undo.json b/features/v2/undo.json index 7a8309d2ceff..09d56ad5577c 100644 --- a/features/v2/undo.json +++ b/features/v2/undo.json @@ -7776,6 +7776,12 @@ "type": "idempotent" } }, + "ListTestExamples": { + "tag": "Test Examples", + "undo": { + "type": "safe" + } + }, "UpdateFlakyTests": { "tag": "Test Optimization", "undo": { diff --git a/packages/datadog-api-client/README.md b/packages/datadog-api-client/README.md index c8fd41dbf166..0dec27e41ba2 100644 --- a/packages/datadog-api-client/README.md +++ b/packages/datadog-api-client/README.md @@ -465,6 +465,7 @@ apiInstance | Synthetics | @datadog/datadog-api-client-synthetics | [README.md](../../services/synthetics/README.md) | | Tags | @datadog/datadog-api-client-tags | [README.md](../../services/tags/README.md) | | Teams | @datadog/datadog-api-client-teams | [README.md](../../services/teams/README.md) | +| Test Examples | @datadog/datadog-api-client-test-examples | [README.md](../../services/test-examples/README.md) | | Test Optimization | @datadog/datadog-api-client-test-optimization | [README.md](../../services/test-optimization/README.md) | | Usage Metering | @datadog/datadog-api-client-usage-metering | [README.md](../../services/usage-metering/README.md) | | Users | @datadog/datadog-api-client-users | [README.md](../../services/users/README.md) | diff --git a/private/bdd_runner/src/support/scenarios_model_mapping.ts b/private/bdd_runner/src/support/scenarios_model_mapping.ts index 00c031ed925d..4356109e6228 100644 --- a/private/bdd_runner/src/support/scenarios_model_mapping.ts +++ b/private/bdd_runner/src/support/scenarios_model_mapping.ts @@ -14481,6 +14481,9 @@ export const ScenariosModelMappings: { [key: string]: OperationMapping } = { }, operationResponseType: "UserTeamsResponse", }, + "TestExamplesApi.V2.ListTestExamples": { + operationResponseType: "TestExamplesResponse", + }, "WebIntegrationsApi.V2.ListWebIntegrationAccounts": { integrationName: { type: "string", diff --git a/services/test_examples/.yarnrc.yml b/services/test_examples/.yarnrc.yml new file mode 100644 index 000000000000..3186f3f0795a --- /dev/null +++ b/services/test_examples/.yarnrc.yml @@ -0,0 +1 @@ +nodeLinker: node-modules diff --git a/services/test_examples/README.md b/services/test_examples/README.md new file mode 100644 index 000000000000..f1254618fed9 --- /dev/null +++ b/services/test_examples/README.md @@ -0,0 +1,35 @@ +# @datadog/datadog-api-client-test-examples + +## Description + +Manage test example resources. + +## Navigation + +- [Installation](#installation) +- [Getting Started](#getting-started) + +## Installation + +```sh +# NPM +npm install @datadog/datadog-api-client-test-examples +# Yarn +yarn add @datadog/datadog-api-client-test-examples +``` + +## Getting Started +```ts +import { createConfiguration } from "@datadog/datadog-api-client"; +import { TestExamplesApiV2 } from "@datadog/datadog-api-client-test-examples"; +import { v2 } from "@datadog/datadog-api-client-test-examples"; + +const configuration = createConfiguration(); +const apiInstance = new TestExamplesApiV2(configuration); + +apiInstance.listTestExamples().then((data) => { + console.log("API called successfully. Returned data: " + JSON.stringify(data)); +}).catch((error) => { + console.error("Error calling API: " + error); +}); +``` \ No newline at end of file diff --git a/services/test_examples/package.json b/services/test_examples/package.json new file mode 100644 index 000000000000..42bfd06b73c9 --- /dev/null +++ b/services/test_examples/package.json @@ -0,0 +1,43 @@ +{ + "name": "@datadog/datadog-api-client-test-examples", + "description": "", + "author": "", + "keywords": [ + "api", + "fetch", + "typescript" + ], + "license": "Apache-2.0", + "licenses": [ + { + "type": "Apache-2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0" + } + ], + "repository": { + "type": "git", + "url": "https://github.com/DataDog/datadog-api-client-typescript.git", + "directory": "services/test-examples" + }, + "files": [ + "dist/**/*" + ], + "main": "./dist/index.js", + "typings": "./dist/index.d.ts", + "scripts": { + "prepack": "yarn workspace @datadog/datadog-api-client build && yarn build", + "build": "yarn generate-version-files && tsc", + "generate-version-files": "node -p \"'export const version = ' + JSON.stringify(require('./package.json').version)\" > src/version.ts" + }, + "dependencies": { + "@datadog/datadog-api-client": "^2.0.0-beta.2" + }, + "devDependencies": { + "typescript": "5.8.3" + }, + "engines": { + "node": ">=18.0.0" + }, + "version": "0.0.1", + "packageManager": "yarn@4.9.1" +} diff --git a/services/test_examples/src/index.ts b/services/test_examples/src/index.ts new file mode 100644 index 000000000000..26c06f06deea --- /dev/null +++ b/services/test_examples/src/index.ts @@ -0,0 +1,3 @@ +export * as v2 from "./v2"; + +export { TestExamplesApi as TestExamplesApiV2 } from "./v2/TestExamplesApi"; diff --git a/services/test_examples/src/v2/TestExamplesApi.ts b/services/test_examples/src/v2/TestExamplesApi.ts new file mode 100644 index 000000000000..2f826b7554cb --- /dev/null +++ b/services/test_examples/src/v2/TestExamplesApi.ts @@ -0,0 +1,167 @@ +import { + ApiException, + BaseAPIRequestFactory, + BaseServerConfiguration, + buildUserAgent, + Configuration, + createConfiguration, + deserialize, + getPreferredMediaType, + HttpMethod, + isBrowser, + logger, + normalizeMediaType, + parse, + RequiredError, + RequestContext, + ResponseContext, + serialize, + ServerConfiguration, + stringify, + applySecurityAuthentication, +} from "@datadog/datadog-api-client"; + +import { TypingInfo } from "./models/TypingInfo"; +import { APIErrorResponse } from "./models/APIErrorResponse"; +import { TestExamplesResponse } from "./models/TestExamplesResponse"; +import { version } from "../version"; + +export class TestExamplesApiRequestFactory extends BaseAPIRequestFactory { + public userAgent: string | undefined; + + public constructor(configuration: Configuration) { + super(configuration); + if (!isBrowser) { + this.userAgent = buildUserAgent("test-examples", version); + } + } + public async listTestExamples( + _options?: Configuration, + ): Promise { + const _config = _options || this.configuration; + + // Path Params + const localVarPath = "/api/v2/test-examples"; + + // Make Request Context + const { server, overrides } = _config.getServerAndOverrides( + "TestExamplesApi.v2.listTestExamples", + TestExamplesApi.operationServers, + ); + const requestContext = server.makeRequestContext( + localVarPath, + HttpMethod.GET, + overrides, + ); + requestContext.setHeaderParam("Accept", "application/json"); + requestContext.setHttpConfig(_config.httpConfig); + + // Set User-Agent + if (this.userAgent) { + requestContext.setHeaderParam("User-Agent", this.userAgent); + } + + // Apply auth methods + applySecurityAuthentication(_config, requestContext, [ + "apiKeyAuth", + "appKeyAuth", + ]); + + return requestContext; + } +} + +export class TestExamplesApiResponseProcessor { + /** + * Unwraps the actual response sent by the server from the response context and deserializes the response content + * to the expected objects + * + * @params response Response returned by the server for a request to listTestExamples + * @throws ApiException if the response code was not in [200, 299] + */ + public async listTestExamples( + response: ResponseContext, + ): Promise { + const contentType = normalizeMediaType(response.headers["content-type"]); + if (response.httpStatusCode === 200) { + const body: TestExamplesResponse = deserialize( + parse(await response.body.text(), contentType), + TypingInfo, + "TestExamplesResponse", + ) as TestExamplesResponse; + return body; + } + if (response.httpStatusCode === 403 || response.httpStatusCode === 429) { + const bodyText = parse(await response.body.text(), contentType); + let body: APIErrorResponse; + try { + body = deserialize( + bodyText, + TypingInfo, + "APIErrorResponse", + ) as APIErrorResponse; + } catch (error) { + logger.debug(`Got error deserializing error: ${error}`); + throw new ApiException( + response.httpStatusCode, + bodyText, + ); + } + throw new ApiException(response.httpStatusCode, body); + } + + // Work around for missing responses in specification, e.g. for petstore.yaml + if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { + const body: TestExamplesResponse = deserialize( + parse(await response.body.text(), contentType), + TypingInfo, + "TestExamplesResponse", + "", + ) as TestExamplesResponse; + return body; + } + + const body = (await response.body.text()) || ""; + throw new ApiException( + response.httpStatusCode, + 'Unknown API Status Code!\nBody: "' + body + '"', + ); + } +} + +export class TestExamplesApi { + private requestFactory: TestExamplesApiRequestFactory; + private responseProcessor: TestExamplesApiResponseProcessor; + private configuration: Configuration; + + static operationServers: { [key: string]: BaseServerConfiguration[] } = {}; + + public constructor( + configuration?: Configuration, + requestFactory?: TestExamplesApiRequestFactory, + responseProcessor?: TestExamplesApiResponseProcessor, + ) { + this.configuration = configuration || createConfiguration(); + this.requestFactory = + requestFactory || new TestExamplesApiRequestFactory(this.configuration); + this.responseProcessor = + responseProcessor || new TestExamplesApiResponseProcessor(); + } + + /** + * Get a list of all test examples. + * @param param The request object + */ + public listTestExamples( + options?: Configuration, + ): Promise { + const requestContextPromise = this.requestFactory.listTestExamples(options); + return requestContextPromise.then((requestContext) => { + return this.configuration.httpApi + .send(requestContext) + .then((responseContext) => { + return this.responseProcessor.listTestExamples(responseContext); + }); + }); + } +} diff --git a/services/test_examples/src/v2/index.ts b/services/test_examples/src/v2/index.ts new file mode 100644 index 000000000000..ef0cde131baf --- /dev/null +++ b/services/test_examples/src/v2/index.ts @@ -0,0 +1,5 @@ +export { TestExamplesApi } from "./TestExamplesApi"; + +export { APIErrorResponse } from "./models/APIErrorResponse"; +export { TestExample } from "./models/TestExample"; +export { TestExamplesResponse } from "./models/TestExamplesResponse"; diff --git a/services/test_examples/src/v2/models/APIErrorResponse.ts b/services/test_examples/src/v2/models/APIErrorResponse.ts new file mode 100644 index 000000000000..58d6c35b80f0 --- /dev/null +++ b/services/test_examples/src/v2/models/APIErrorResponse.ts @@ -0,0 +1,45 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * API error response. + */ +export class APIErrorResponse { + /** + * A list of errors. + */ + "errors": Array; + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + "additionalProperties"?: { [key: string]: any }; + /** + * @ignore + */ + "_unparsed"?: boolean; + + /** + * @ignore + */ + static readonly attributeTypeMap: AttributeTypeMap = { + errors: { + baseName: "errors", + type: "Array", + required: true, + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return APIErrorResponse.attributeTypeMap; + } + + public constructor() {} +} diff --git a/services/test_examples/src/v2/models/TestExample.ts b/services/test_examples/src/v2/models/TestExample.ts new file mode 100644 index 000000000000..b09df16beea7 --- /dev/null +++ b/services/test_examples/src/v2/models/TestExample.ts @@ -0,0 +1,63 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * A test example resource. + */ +export class TestExample { + /** + * Creation time of the test example. + */ + "createdAt"?: Date; + /** + * The ID of the test example. + */ + "id": string; + /** + * The name of the test example. + */ + "name": string; + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + "additionalProperties"?: { [key: string]: any }; + /** + * @ignore + */ + "_unparsed"?: boolean; + + /** + * @ignore + */ + static readonly attributeTypeMap: AttributeTypeMap = { + createdAt: { + baseName: "created_at", + type: "Date", + format: "date-time", + }, + id: { + baseName: "id", + type: "string", + required: true, + }, + name: { + baseName: "name", + type: "string", + required: true, + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return TestExample.attributeTypeMap; + } + + public constructor() {} +} diff --git a/services/test_examples/src/v2/models/TestExamplesResponse.ts b/services/test_examples/src/v2/models/TestExamplesResponse.ts new file mode 100644 index 000000000000..6429314b8426 --- /dev/null +++ b/services/test_examples/src/v2/models/TestExamplesResponse.ts @@ -0,0 +1,43 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { TestExample } from "./TestExample"; + +/** + * Response containing a list of test examples. + */ +export class TestExamplesResponse { + "data"?: Array; + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + "additionalProperties"?: { [key: string]: any }; + /** + * @ignore + */ + "_unparsed"?: boolean; + + /** + * @ignore + */ + static readonly attributeTypeMap: AttributeTypeMap = { + data: { + baseName: "data", + type: "Array", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return TestExamplesResponse.attributeTypeMap; + } + + public constructor() {} +} diff --git a/services/test_examples/src/v2/models/TypingInfo.ts b/services/test_examples/src/v2/models/TypingInfo.ts new file mode 100644 index 000000000000..0877e395ffbb --- /dev/null +++ b/services/test_examples/src/v2/models/TypingInfo.ts @@ -0,0 +1,15 @@ +import { ModelTypingInfo } from "@datadog/datadog-api-client"; + +import { APIErrorResponse } from "./APIErrorResponse"; +import { TestExample } from "./TestExample"; +import { TestExamplesResponse } from "./TestExamplesResponse"; + +export const TypingInfo: ModelTypingInfo = { + enumsMap: {}, + oneOfMap: {}, + typeMap: { + APIErrorResponse: APIErrorResponse, + TestExample: TestExample, + TestExamplesResponse: TestExamplesResponse, + }, +}; diff --git a/services/test_examples/tsconfig.json b/services/test_examples/tsconfig.json new file mode 100644 index 000000000000..d6c32bfb893c --- /dev/null +++ b/services/test_examples/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "strict": true, + /* Basic Options */ + "target": "es6", + "module": "commonjs", + "moduleResolution": "node", + "declaration": true, + + "esModuleInterop": true, + "resolveJsonModule": true, + + "noImplicitAny": true, + "noImplicitThis": true, + + /* Additional Checks */ + "noUnusedLocals": false /* Report errors on unused locals. */, // TODO: reenable (unused imports!) + "noUnusedParameters": false /* Report errors on unused parameters. */, // TODO: set to true again + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + + "sourceMap": true, + "outDir": "./dist", + "lib": ["es6", "es7"] + }, + "exclude": ["dist", "node_modules", "tests"], + "include": ["src"] +} diff --git a/yarn.lock b/yarn.lock index 9ea34016097e..ddf0b4649067 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1369,6 +1369,15 @@ __metadata: languageName: unknown linkType: soft +"@datadog/datadog-api-client-test-examples@workspace:services/test_examples": + version: 0.0.0-use.local + resolution: "@datadog/datadog-api-client-test-examples@workspace:services/test_examples" + dependencies: + "@datadog/datadog-api-client": "npm:^2.0.0-beta.2" + typescript: "npm:5.8.3" + languageName: unknown + linkType: soft + "@datadog/datadog-api-client-test-optimization@workspace:services/test_optimization": version: 0.0.0-use.local resolution: "@datadog/datadog-api-client-test-optimization@workspace:services/test_optimization"