openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][TYPESCRIPT] TypeScript Won't Generate Docs Folder

Open mason-at-pieces opened this issue 1 year ago • 5 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [ ] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I am able to generate python, kotlin, and dart sdks perfectly fine. They all also generate a separate folder where it generates markdown docs.

However, TypeScript is not generating that separate docs folder and I cannot figure out why.

openapi-generator version

v7.4.0

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            maximum: 100
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
        required: true
      responses:
        '201':
          description: Null response
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      maxItems: 100
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
Generation Details

I run this simple, command and it generates the SDK but no docs:

openapi-generator generate -i test.openapi.yaml -g typescript-fetch -o ./typescript-sdk

Steps to reproduce

Run this command on any spec file:

openapi-generator generate -i test.openapi.yaml -g typescript-fetch -o ./typescript-sdk

mason-at-pieces avatar Apr 02 '24 18:04 mason-at-pieces

typescript -fetch does not provide auto-generated doc at the moment.

A good starting point is to copy https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript/api_doc.mustache and https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript/model_doc.mustache to typescript-fetch template folder and update these templates accordingly.

(in TypeScriiptFetchCodegen, make sure to add these 2 new templates files to the generator)

May I know if you've time to contribute the enhancement?

wing328 avatar Apr 03 '24 07:04 wing328

@wing328 Thanks for the reply. Would using typescript work then instead of using typescript-fetch?

Also, I will look into this today however the model_doc.mustache file does not exist. Is there another example I can use to copy over?

And then from there, is it as simple as running the same command with the files copied over?

mason-at-pieces avatar Apr 03 '24 16:04 mason-at-pieces

(in TypeScriiptFetchCodegen, make sure to add these 2 new templates files to the generator)

Where exactly is this in the repo?

mason-at-pieces avatar Apr 04 '24 19:04 mason-at-pieces

@wing328 Just created the pr to add this functionality for typescript-fetch 👍

mason-at-pieces avatar Apr 10 '24 20:04 mason-at-pieces

Can you please add the same for typescript-axios generator?

rbrazhnyk avatar Apr 23 '24 06:04 rbrazhnyk