redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

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

Open abelgibayev opened this issue 3 years ago • 4 comments

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.

abelgibayev avatar Oct 27 '22 06:10 abelgibayev

What does your config file look like?

Aaron46 avatar Nov 08 '22 22:11 Aaron46

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

evanjmg avatar Jan 02 '24 12:01 evanjmg

Happens with

 discriminator:
        propertyName: kind
        mapping:
          something: '#/components/schemas/something'

evanjmg avatar Jan 02 '24 12:01 evanjmg

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

gbataille avatar Feb 19 '24 13:02 gbataille

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!

markerikson avatar Aug 30 '24 22:08 markerikson