Schema components as references to other schema fails
bug@kubb/plugin-oas
### What version of `kubb` is running?
4.33.2
### What kind of platform do you use?
Windows
### Your `kubb.config.ts` config file?
```typescript
import { defineConfig } from "@kubb/core";
import { pluginOas } from "@kubb/plugin-oas";
import { pluginZod } from "@kubb/plugin-zod";
export default defineConfig(() => {
return [
{
root: ".",
input: {
path: "./openapi/example-api.yaml",
},
output: {
path: "./src/gen",
clean: true,
barrelType: "named",
extension: {
".ts": "",
},
},
plugins: [
pluginOas({
validate: false,
generators: [],
}),
pluginZod({
output: {
path: "./zod",
},
inferred: true,
unknownType: "unknown",
importPath: "zod",
}),
],
},
];
});
```
### Swagger/OpenAPI file?
```bash
example-api.yaml:
openapi: 3.0.3
info:
title: Repro API
version: v1.0
components:
schemas:
Parcel:
$ref: "api-definitions.yml#/components/schemas/Parcel"
paths:
/v1/returns/type-a:
post:
operationId: createReturnTypeA
requestBody:
$ref: "api-definitions.yml#/components/requestBodies/RequestABody"
responses:
"200":
$ref: "api-definitions.yml#/components/responses/createReturnResponse"
/v1/returns/type-b:
post:
operationId: createReturnTypeB
requestBody:
$ref: "api-definitions.yml#/components/requestBodies/RequestBBody"
responses:
"200":
$ref: "api-definitions.yml#/components/responses/createReturnResponse"
api-definitions.yml:
openapi: 3.0.3
info:
title: Repro Shared Definitions
version: v1.0
components:
schemas:
Parcel:
type: object
properties:
parcelNo:
type: string
trackingNumber:
type: string
ContactDetailsType:
type: object
properties:
fullName:
type: string
emailAddress:
type: string
required:
- fullName
- emailAddress
ProductDetails:
type: object
properties:
productCount:
type: number
itemIds:
type: array
items:
type: string
required:
- itemIds
TypeARequest:
type: object
properties:
actorId:
type: string
contactDetails:
$ref: "#/components/schemas/ContactDetailsType"
productDetails:
$ref: "#/components/schemas/ProductDetails"
required:
- actorId
- contactDetails
- productDetails
TypeBRequest:
type: object
properties:
actorId:
type: string
ticketId:
type: string
contactDetails:
$ref: "#/components/schemas/ContactDetailsType"
required:
- actorId
- ticketId
- contactDetails
Result:
type: object
properties:
returnId:
type: string
state:
type: string
enum:
- ACCEPTED
- REJECTED
parcels:
type: array
items:
$ref: "#/components/schemas/Parcel"
required:
- returnId
- state
requestBodies:
RequestABody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/TypeARequest"
RequestBBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/TypeBRequest"
responses:
createReturnResponse:
description: Shared create-return response.
content:
application/json:
schema:
$ref: "#/components/schemas/Result"
```
### What version of external packages are you using(`@tanstack-query`, `MSW`, `React`, `Vue`, ...)
```JSON
```
### What steps can reproduce the bug?
In the https://github.com/iivo-k/kubb-repro project:
```
cd ./breaking_example
npm install
npm generate
```
results in plugin-oas failing with some kind of a recursive loop
> ✗ Maximum call stack size exceeded
This happens when there's a component schema referencing another component schema
```
components:
schemas:
Parcel:
$ref: "api-definitions.yml#/components/schemas/Parcel"
```
### How often does this bug happen?
Every time
### What is the expected behavior?
Instead there should be just one generated Parcel schema, that is referenced from the generated code.
### Additional information
Sort of related to https://github.com/kubb-labs/kubb/issues/2619, but made a new issue & repro.
4 条评论