reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.69k stars 1.16k forks source link

Deep refs resolving in @rtk-query/codegen-openapi #2833

Closed abelgibayev closed 1 month ago

abelgibayev commented 1 year ago

We have OpenAPI specs with multiple files and some models contain multiple refs.

E.g: spec.yaml

paths:
  /some/endpoint:
    post:
      requestBody: 
        $ref: './entity.yaml#/components/requestBodies/SomeEndpointParams'

entity.yaml

components:
  requestBodies:
    SomeEndpointParams:
      content:
        application/json:
           schema:
             $ref: "#/components/schemas/SomeEndpointRequest

  schemas:
    SomeEndpointRequest:
      type: object
      properties:
        custom_field:
          $ref: "#/components/schemas/SomeEndpointCustomField"

    SomeEndpointCustomField:
      type: object
      properties:
        field_a:
          type: number
        field_b:
          type: number

The problem is next: running npx @rtk-query/codegen-openapi openapi-config.ts throws such error Can't find paths,/some/endpoint,post,requestBody,content,application/json,schema,properties,custom_field.

The configuration is correct, openapi-fetch correctly generates classes and models from it.

Aaron46 commented 1 year ago

What does your config file look like?

evanjmg commented 9 months ago

I am getting the same issue for nested on 2nd page. It works in all other cases

evanjmg commented 9 months ago

Happens with

 discriminator:
        propertyName: kind
        mapping:
          something: '#/components/schemas/something'
gbataille commented 7 months ago

I'm having the same issue. seems to come from oazapfts

Where I'm at at the moment is this: when you have several files to define your open API doc, you can use this sort of reference

          $ref: 'common-swagger-v1.yaml#/components/schemas/common.Quantity'

It seems that when the main file uses such an import, the first time it is encountered, it is imported (as in "copy/paste") in the object structure image

But then further similar references in the same main file will point to the resolved first occurence inside the main document, wherever this might be image

It seems that sometimes however, this (weird) link fails.

I'm going to try to track it further

markerikson commented 1 month ago

This is probably a problem with the underlying https://github.com/oazapfts/oazapfts library - could you file an issue over there with a repro? Thanks!