aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.03k stars 568 forks source link

Model has mandatory values with allowed undefined instead of optional breaking OpenAPI spec generation #2938

Closed Hi-Fi closed 6 months ago

Hi-Fi commented 2 years ago

Describe the bug

When generating API model with TSOA, generation fails as undefined is not valid value for OpenAPI (see https://github.com/lukeautry/tsoa/issues/891

Your environment

SDK version number

@aws-sdk/client-codebuild@3.38.0

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the browser/Node.js/ReactNative version

Node v16.11.0

Steps to reproduce

Model including following (used) model:

import * as CodeBuild from '@aws-sdk/client-codebuild';

export interface TestOrCoverageReportResult {
  report: CodeBuild.Report;
  testCases?: CodeBuild.TestCase[];
  testCoverages?: CodeBuild.CodeCoverage[];
}

Observed behavior

TSOA throws error. There's also issue related to that in TSOA tracker (https://github.com/lukeautry/tsoa/issues/1031), but this apispec cretion worked fine with AWS-SDK v2 as model had just normal mandatory values (https://github.com/aws/aws-sdk-js/blob/af5475f66c30b32ac03882393b0508dd4fedb3e5/clients/codebuild.d.ts#L2722-L2735 vs. https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-codebuild/src/models/models_0.ts#L3594-L3612).

Generate routes error.
 Error: Unknown type: UndefinedKeyword
At: /workspace/release-document-service/service/node_modules/@aws-sdk/client-codebuild/dist-types/models/models_0.d.ts:3149:3149.
This was caused by 'number | undefined' 

Expected behavior

Apispec is generated successfully. If undefined is valid value, those are marked as optional in model so apispec can be generated.

vudh1 commented 2 years ago

Hi @Hi-Fi, thank you for reaching out. Unfortunately, I am not able to reproduce the issue you addressed above with the latest version of the package. Can you try to use the latest version (v3.39.0)?

Hi-Fi commented 2 years ago

Sorry, example was a bit bad. Here's complete one that shows error.

index.ts

import {
    Controller,
    Post,
    Route,
    SuccessResponse,
  } from '@tsoa/runtime';
import * as CodeBuild from '@aws-sdk/client-codebuild';

@Route('health')
export class ExampleController extends Controller {
    @SuccessResponse(200, 'Returns test')
    @Post()
  public async health (): Promise<CodeBuild.Report> {
    return {} as CodeBuild.Report; 
  }
}

tsoa.json

{
    "entryFile": "./index.ts",
    "noImplicitAdditionalProperties": "throw-on-extras",
    "spec": {
      "outputDirectory": "apimodel",
      "specFileBaseName": "apispec",
      "host": "example.com",
      "basePath": "/example",
      "yaml": true,
      "specVersion": 3
    }
  }

Those file in same directory commands that show error (run in same dir as files)

npm i @aws-sdk/client-codebuild
npx tsoa spec

As mentioned issue at TSOA side is also open, but also here as types have changed between aws-sdk v2 and v3.

github-actions[bot] commented 6 months ago

Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.

github-actions[bot] commented 6 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.