swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

Can't generate Strava api response models

Open cnsndnz opened this issue 4 years ago • 2 comments

Hi, I'm trying to generate ts-axios client for the strava api but can't generate the response models correctly. All response types are just 'any' or 'any[]'. I'm using the script below to generate client.

generateApi({
  name: `strava.ts`,
  url: "https://developers.strava.com/swagger/swagger.json",
  output:  path.resolve(process.cwd(), "clients"),
  httpClientType: 'axios',
})

I also realized that the Strava uses http links for schema definitions. Is this can be cause of the problem?

    "responses": {
          "200": {
            "description": "Profile information for the authenticated athlete.",
            "schema": {
              "$ref": "https://developers.strava.com/swagger/athlete.json#/DetailedAthlete"
            },

Thanks

cnsndnz avatar Oct 21 '21 13:10 cnsndnz

When I update the source code as follows I can generate the response types now. As I see currently the lib doesn't support the external refs.

1-) swagger.js --> line 65 --> I added resolve: true option to 'swagger2openapi' lib config to resolve external refs.

converter.convertObj( swaggerSchema, { warnOnly: true, refSiblings: "preserve", resolve: true, rbname: "requestBodyName", },

2-) After that there was an error due to a url issue in 'oas-resolver' package. At the execution of index.js -> resolveExternal function options.source was returning undefined and the pointer value was equal to the actual url so I made the changes below to try a fix. I am not sure why options.source is undefined but the solution works...

I changed below lines function resolveExternal(root, pointer, options, callback) { debugger; var u = url.parse(options.source); var base = options.source || pointer.split('\\').join('/').split('/');

to function resolveExternal(root, pointer, options, callback) { debugger; var u = url.parse(options.source || pointer); var base = (options.source || pointer).split('\\').join('/').split('/');

cnsndnz avatar Oct 22 '21 06:10 cnsndnz

Hey, thanks for this - it still works!

martdavidson avatar Aug 28 '22 16:08 martdavidson