aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
2.96k stars 557 forks source link

Exporting YAML OpenAPI spec with SDK Client GetExportCommand results in JSON spec #6090

Closed stohlthomas closed 1 month ago

stohlthomas commented 1 month ago

Checkboxes for prior research

Describe the bug

Trying to export with the aws cli is working. However, with this aws-sdk example i am only able to fetch a json specification.

const getApiExportCommand = new GetExportCommand({
  restApiId  : restApiId,
  stageName  : stageName,
  exportType : 'oas30',
  accepts    : 'application/yaml',
})

const APIGATEWAY_CLIENT = new APIGatewayClient({ })
APIGATEWAY_CLIENT.send(getApiExportCommand).then((result) => {
  console.log(Buffer.from(result.body).toString('utf8'))
}).catch(console.error)

Any help or insights how to debug further is appreciated.

SDK version number

@aws-sdk/client-api-gateway@3.574.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node 18

Reproduction Steps

const getApiExportCommand = new GetExportCommand({
  restApiId  : <restApiId>,
  stageName  : <stageName>,
  exportType : 'oas30',
  accepts    : 'application/yaml',
})

const APIGATEWAY_CLIENT = new APIGatewayClient({ })
APIGATEWAY_CLIENT.send(getApiExportCommand).then((result) => {
  console.log(Buffer.from(result.body).toString('utf8'))
}).catch(console.error)

Observed Behavior

Json export response

Expected Behavior

Yaml export response

Possible Solution

No response

Additional Information/Context

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/api-gateway/command/GetExportCommand/

aBurmeseDev commented 1 month ago

Hi @stohlthomas - thanks for reporting.

I was able to reproduce this behavior and will be further investigating with the team.

AWS CLI

aws apigateway get-export --rest-api-id bhuovzm968 --stage-name testStage --export-type oas30 --accepts application/yaml  --region us-west-1 exportedCLI.yaml
{
    "contentType": "application/octet-stream",
    "contentDisposition": "attachment; filename=\"oas30_2024-05-13T23:26:39Z.yaml\""
}

JS v2 & v3

import { APIGatewayClient, GetExportCommand } from "@aws-sdk/client-api-gateway";
import AWS from 'aws-sdk';

// v2 client
const v2Client = new AWS.APIGateway({
    region: "us-west-1"
})

const client = new APIGatewayClient({
    region: "us-west-1"
});
const input = { // GetExportRequest
  restApiId: "bhuovzm968",
  stageName: "testStage", 
  exportType: "oas30",
  accepts: "application/yaml", 
};
const command = new GetExportCommand(input);

async function v3(){
    try {
    const response = await client.send(command);
    console.log(response)
    } catch (error) {
    console.log(error)
    }
}
v3()

async function v2(){
    v2Client.getExport(input, function(err, data) {
        if (err) console.log(err, err.stack); 
        else     console.log(data); 
      });
}
v2()
v2 response
{
  contentType: 'application/octet-stream',
  contentDisposition: 'attachment; filename="oas30_2024-05-13T23:26:39Z.yaml"',  <<<< v2 output yaml file
  body: <Buffer 6f 70 65 6e 61 70 69 3a 20 22 33 2e 30 2e 31 22 0a 69 6e 66 6f 3a 0a 20 20 74 69 74 6c 65 3a 20 22 50 65 74 53 74 6f 72 65 22 0a 20 20 64 65 73 63 72 ... 3888 more bytes>
}

v3 response
{
  '$metadata': {
    httpStatusCode: 200,
    requestId: '57552ab4-58e6-473e-b82d-61591639b3b4',
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  contentType: 'application/octet-stream',
  contentDisposition: 'attachment; filename="oas30_2024-05-13T23:26:39Z.json"', <<<< v3 output json file
  body: Uint8ArrayBlobAdapter(6163) [Uint8Array] [
    123,  10,  32,  32,  34, 111, 112, 101, 110,  97, 112, 105,
     34,  32,  58,  32,  34,  51,  46,  48,  46,  49,  34,  44,
     10,  32,  32,  34, 105, 110, 102, 111,  34,  32,  58,  32,
    123,  10,  32,  32,  32,  32,  34, 116, 105, 116, 108, 101,
     34,  32,  58,  32,  34,  80, 101, 116,  83, 116, 111, 114,
    101,  34,  44,  10,  32,  32,  32,  32,  34, 100, 101, 115,
     99, 114, 105, 112, 116, 105, 111, 110,  34,  32,  58,  32,
     34,  89, 111, 117, 114,  32, 102, 105, 114, 115, 116,  32,
     65,  80,  73,  32,
    ... 6063 more items
  ]
}
kuhe commented 1 month ago

the fix is expected as version https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.580.0 to be released later today

stohlthomas commented 1 month ago

Thanks for the quick investigation.

I pulled v3.580.0 and i am still receiving a json file. Could you validate if it is working for you? Then i might need to check on my side again.

github-actions[bot] commented 3 weeks 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.