openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
550 stars 67 forks source link

typegen - $Ref parameters doesn't assign to parameters type #91

Closed Tlahey closed 2 years ago

Tlahey commented 2 years ago

Hello, this is my use case :

I have a swagger yaml file like that

# Parameter definition
components:
  parameters:
    offsetParam:
      limit:
            name: limit
            in: query
            required: true
            schema:
              type: integer
              minLength: 1
            description: xxxx

# Some other stuff

# My Rest GET
  /levels:
    get:
      tags:
        - Indicators
      summary: Get levels
      # Response [...]
      operationId: getIndicatorsLevels
      description: xxxx
      parameters:
        - $ref: '#/components/parameters/limit'

After apply typegen file.yaml > file.d.ts I have this result.

'getIndicatorsLevels'(
    parameters?: Parameters<UnknownParamsObject> | null,
    data?: any,
    config?: AxiosRequestConfig  
  ): OperationResponse<Paths.GetIndicatorsLevels.Responses.$200>

In this case, getIndicatorsLevels doesn't include my reference in parametersobject. Instead it use a UnknownParamsObject! But, if I check the namespace GetIndicatorsLevels, I have this parameters, but not the QueryParameters interface

    namespace GetIndicatorsLevels {
        namespace Parameters {
            export type $0 = Components.Parameters.Limit;
            export type $1 = Components.Parameters.Page;
        }
        namespace Responses {
            export interface $200 {
                items: /*  */ Components.Schemas.Level[];
                meta: /*  */ Components.Schemas.PaginateMeta;
            }
        }
    }

I'm on

Can you reproduce the problem or is it a YAML file problem ? Thank you in advance :)

briceruzand commented 2 years ago

Hello too, I try to use your tools, which seems very interesting, on my API, but I have the same behavior on my api sample.

openapi: 3.0.3
info:
  title: Annotations test API
  version: 1.0.1
components:
  schemas:
    Annotations:
      title: Annotations
      type: object
      additionalProperties: true
      example:
        key: value
        key2:
          - value1
          - value2
paths:
  /api/v1/{target}/annotations:
    put:
      operationId: Annotations.put
      description: Replace Annotations
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Annotations"
      parameters:
        - in: path
          name: target
          required: true
          schema:
            type: string
            pattern: ^[a-z0-9][a-z0-9-]*$
            minLength: 1
            maxLength: 32
            example: my-target
      responses:
        "200":
          description: Annotations response
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Annotations"

Generated Components ans Paths are well generated but not referenced in OperationMethods or PathsDictionary

Actual generated OperationMethods :

export interface OperationMethods {
  /**
   * Annotations.put - Replace Annotations
   */
  'Annotations.put'(
    parameters?: Parameters<UnknownParamsObject> | null,
    data?: any,
    config?: AxiosRequestConfig  
  ): OperationResponse<any>
}

Expected generated OperationMethods :

export interface OperationMethods {
  /**
   * Annotations.put - Replace Annotations
   */
  'Annotations.put'(
      parameters?: Parameters<Paths.AnnotationsPut.PathParameters> | null,
      data?: Paths.AnnotationsPut.RequestBody,
      config?: AxiosRequestConfig
  ): OperationResponse<Paths.AnnotationsPut.Responses.$200>;
}

I am using the same version. Note: my openapi spec seems to be valid and use well with other tools ng-openapi-gen.

Thx for your help.

npdev453 commented 2 years ago

Issue from second comment fixed by #96

but original problem is there https://github.com/anttiviljami/openapi-client-axios/blob/master/packages/typegen/src/typegen.ts#L80 I can't found in exportTypes any */pathParameters , just *parameter/0,*parameter/1 Possible solution https://github.com/anttiviljami/openapi-client-axios/pull/96/commits/b74bf168e571287fcc0297f9a6758208b6ba2914

briceruzand commented 2 years ago

Thx @npdev453 , I confirm that #96 fix my trouble.