Skip to content

Commit

Permalink
Merge pull request #30 from HiDeoo/hd-fix-implicit-object
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Apr 18, 2024
2 parents 5b27ed4 + a73ec81 commit 6117d9a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/starlight-openapi/libs/schemaObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function isParameterWithSchemaObject(parameter: Parameter): parameter is
export function isSchemaObjectObject(schemaObject: SchemaObject): schemaObject is SchemaObject {
return (
schemaObject.type === 'object' ||
'properties' in schemaObject ||
('oneOf' in schemaObject && (schemaObject.oneOf as SchemaObject[]).some(isSchemaObjectObject)) ||
('anyOf' in schemaObject && (schemaObject.anyOf as SchemaObject[]).some(isSchemaObjectObject)) ||
('allOf' in schemaObject && (schemaObject.allOf as SchemaObject[]).some(isSchemaObjectObject))
Expand Down
7 changes: 7 additions & 0 deletions packages/starlight-openapi/tests/requestBody.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ test('displays the request body for a v3.0 schema', async ({ docPage }) => {
expect(await requestBody.getByRole('combobox').inputValue()).toBe('application/json')
})

test('supports schema object for implicit objects', async ({ docPage }) => {
await docPage.goto('/v3/animals/operations/hamsters')

await expect(docPage.getRequestBodyParameter('id')).toBeVisible()
await expect(docPage.getRequestBodyParameter('name')).toBeVisible()
})

test('supports schema object `allOf` property for explicit objects', async ({ docPage }) => {
await docPage.goto('/v2/animals/operations/addcat/')

Expand Down
35 changes: 35 additions & 0 deletions schemas/v3.0/animals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,31 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/hamsters:
post:
summary: Creates a new hamster
tags:
- animals
requestBody:
description: Hamster to add
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Hamster'
responses:
'200':
description: animal response
content:
application/json:
schema:
$ref: '#/components/schemas/Animal'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
webhooks:
newAnimal:
post:
Expand Down Expand Up @@ -352,6 +377,16 @@ components:
type: string
tag:
type: string
Hamster:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Animals:
type: array
maxItems: 100
Expand Down

0 comments on commit 6117d9a

Please sign in to comment.