Skip to content

Commit

Permalink
fix(msw): broken mock when allof with not has properties object (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
soartec-lab authored Sep 13, 2024
1 parent 108abc8 commit 2245435
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/mock/src/faker/getters/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,25 @@ export const combineSchemasMock = ({
return `${acc}${currentValue}${!combine ? '])' : ''}`;
}

if (currentValue === '{}') {
currentValue = '';

if (acc.toString().endsWith(',')) {
acc = acc.toString().slice(0, -1);
}
}

return `${acc}${currentValue}${isObjectBounds ? '}' : ''}`;
}

if (currentValue === '{}') {
currentValue = '';

if (acc.toString().endsWith(',')) {
acc = acc.toString().slice(0, -1);
}
}

if (!currentValue) {
return acc;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/configs/default.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ export default defineConfig({
mock: true,
},
},
'all-of': {
input: '../specifications/all-of.yaml',
output: {
schemas: '../generated/default/all-of/model',
target: '../generated/default/all-of/endpoints.ts',
mock: true,
},
},
'deeply-nested-refs': {
input: '../specifications/deeply-nested-refs.yaml',
output: {
Expand Down
50 changes: 50 additions & 0 deletions tests/specifications/all-of.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
openapi: 3.0.0
info:
version: 1.0.0
title: AnyOf Schema
license:
name: MIT
paths:
/not-has-properties-with-all-of-pets:
get:
operationId: getNotHasPropertiesWithAllOfPets
tags:
- pets
description: |-
Not has properties with allOf pets.
responses:
'200':
description: User
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/Pet'
- $ref: '#/components/schemas/PetDetail'
- type: object
required:
- category
- type: object
required:
- color

components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
PetDetail:
type: object
required:
- tag
properties:
tag:
type: string

0 comments on commit 2245435

Please sign in to comment.