Skip to content

Commit

Permalink
Merge pull request #27 from HiDeoo/hd-fix-implicit-object-rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Apr 16, 2024
2 parents 2d0ad7d + 9f94d78 commit 47bd720
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/starlight-openapi/libs/schemaObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export function isParameterWithSchemaObject(parameter: Parameter): parameter is
export function isSchemaObjectObject(schemaObject: SchemaObject): schemaObject is SchemaObject {
return (
schemaObject.type === 'object' ||
('oneOf' in schemaObject && (schemaObject.oneOf as SchemaObject[]).every(isSchemaObjectObject)) ||
('anyOf' in schemaObject && (schemaObject.anyOf as SchemaObject[]).every(isSchemaObjectObject)) ||
('allOf' in schemaObject && (schemaObject.allOf as SchemaObject[]).every(isSchemaObjectObject))
('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
10 changes: 9 additions & 1 deletion packages/starlight-openapi/tests/requestBody.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ 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 `allOf` property for objects', async ({ docPage }) => {
test('supports schema object `allOf` property for explicit objects', async ({ docPage }) => {
await docPage.goto('/v2/animals/operations/addcat/')

await expect(docPage.getRequestBodyParameter('name')).toBeVisible()
await expect(docPage.getRequestBodyParameter('tag')).toBeVisible()
await expect(docPage.getRequestBodyParameter('age')).toBeVisible()
})

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

await expect(docPage.getRequestBodyParameter('name')).toBeVisible()
await expect(docPage.getRequestBodyParameter('tag')).toBeVisible()
await expect(docPage.getRequestBodyParameter('age')).toBeVisible()
})

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

Expand Down
18 changes: 18 additions & 0 deletions schemas/v2.0/animals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,24 @@ paths:
description: 'unexpected error'
schema:
$ref: '#/definitions/Error'
/turtles:
post:
description: 'Creates a new turtle'
operationId: 'addTurtle'
parameters:
- name: 'turtle'
in: 'body'
description: 'Turtle to add'
required: true
schema:
allOf:
- $ref: '#/definitions/NewAnimal'
- required:
- 'age'
properties:
age:
type: 'integer'
format: 'int32'
definitions:
Animal:
type: 'object'
Expand Down

0 comments on commit 47bd720

Please sign in to comment.