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

$ref from JSON is not recognized and replaced by any

Open AlexanderShabalin opened this issue 1 year ago • 2 comments

In my yaml I have references to json models in the local files, like this

schemas: details: $ref: 'models/details.json'

When I generate TS, I am gettin the property type as "any". No errors are shown. Just a missing type in a result.

When I describe details as Yaml in this file, then everything works as expected, and generator creates an interface. So it's something about the external JSON models that is not working. However the same setup works with another TS generator, so models themselves are correct.

AlexanderShabalin avatar May 24 '24 09:05 AlexanderShabalin

Is any way to work with separate schemas with relative ref?

I have sane issue with any-types

v-lukoyanov avatar Oct 31 '24 21:10 v-lukoyanov

Update: Solved by first bundling the file using https://github.com/Redocly/redocly-cli and then using that bundle as input to swagger-typescript-api

I've got the same issue, probably because of remote $ref

Generated endpoint

    /**
     * @description Returns the activities of an athlete for a specific identifier. Requires activity:read. Only Me activities will be filtered out unless requested by a token with activity:read_all.
     *
     * @tags Activities
     * @name GetLoggedInAthleteActivities
     * @summary List Athlete Activities
     * @request GET:/athlete/activities
     * @secure
     */
    getLoggedInAthleteActivities: (
      query?: {
        /** An epoch timestamp to use for filtering activities that have taken place before a certain time. */
        before?: number;
        /** An epoch timestamp to use for filtering activities that have taken place after a certain time. */
        after?: number;
        /** Page number. Defaults to 1. */
        page?: number;
        /**
         * Number of items per page. Defaults to 30.
         * @default 30
         */
        per_page?: number;
      },
      params: RequestParams = {},
    ) =>
      this.request<any[], any>({   // <------- UNEXPECTED ANY TYPES
        path: `/athlete/activities`,
        method: "GET",
        query: query,
        secure: true,
        format: "json",
        ...params,
      }),

Swagger source for endpoint /athlete/activities

          "200": {
            "description": "The authenticated athlete's activities",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "https://developers.strava.com/swagger/activity.json#/SummaryActivity"  // <--- SHOULD GET THIS RESPONSE TYPE
              }
            },

carleryd avatar Mar 28 '25 13:03 carleryd