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

Option for handle object without $ref (nested objects)

Open frolovsky opened this issue 2 years ago • 1 comments

When generating the client, we pass the swagger. A swagger can include complex objects. Such objects usually have nested objects. So, if we want to access this nested object from code, then we can only get it if it is described inside the swagger using "$ref". Example object in schema (without $ref)

"work_day": {
  "type": "object",
  "description": "Workday state",
  "properties": {
    "uuid": {
      "type": "string",
      "description": "Workday uuid",
      "example": "6e8242b9-adea-4d0a-ba74-07dc2cf6f459"
    }
  }
}

We generate some schema and result is:

export interface Generated {
  name?: string;
  work_day?: {
    uuid?: string;
  };
}

But now, let use $ref inside our schema

"work_day": {
  "schema": {
    "$ref": "#/components/schemas/Workday"
  }
}

Result in TypeScript:


export interface Generated {
  name?: string;
  work_day?: GeneratedWorkDay;
}

export interface GeneratedWorkDay {
  uuid?: string;
}

It is possible to handle object without $ref?

frolovsky avatar Oct 09 '23 12:10 frolovsky

@js2me Hi! If I make changes that add an option for parsing, when passed, nested objects will be separated into a separate type, will you look at it? I see a lot opened pull request and as I understand it, there is not enough time to see everything)

frolovsky avatar Nov 01 '23 13:11 frolovsky