[GH-ISSUE #5988] [bug]: OpenAPI import generates empty request body for schemas using allOf #2354

Open
opened 2026-03-17 00:02:54 +03:00 by kerem · 2 comments
Owner

Originally created by @mahmoodhamdi on GitHub (Mar 13, 2026).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5988

Software and environment

  • Hoppscotch version: latest (main branch)
  • Browser: All
  • Platform: Web, Desktop

Steps to reproduce

  1. Create an OpenAPI v3 spec with a request body schema that uses allOf composition (a very common pattern for schema inheritance):
paths:
  /pets:
    post:
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/BaseAnimal'
                - type: object
                  properties:
                    breed:
                      type: string
components:
  schemas:
    BaseAnimal:
      type: object
      properties:
        name:
          type: string
        age:
          type: integer
  1. Import the spec in Hoppscotch
  2. Open the POST /pets request and look at the generated example body

Expected behavior

The request body example should include all merged properties from the allOf schemas:

{
  "name": "string",
  "age": 0,
  "breed": "string"
}

Actual behavior

The request body is empty ("") because the allOf case is not handled in the example generator.

Root cause

In packages/hoppscotch-common/src/helpers/import-export/import/openapi/example-generators/v3.ts, the function generateRequestBodyExampleFromSchemaObject has a TODO comment acknowledging this gap:

const generateRequestBodyExampleFromSchemaObject = (
  schemaObject: OpenAPIV3.SchemaObject
): RequestBodyExample => {
  // TODO: Handle schema objects with allof    <-- acknowledged but not implemented
  if (schemaObject.example) return schemaObject.example as RequestBodyExample

  if (schemaObject.oneOf)   // ✅ handled
    return generateRequestBodyExampleFromSchemaObject(...)
  if (schemaObject.anyOf)   // ✅ handled
    return generateRequestBodyExampleFromSchemaObject(...)
  // allOf                   // ❌ not handled — falls through to empty string

  if (!schemaObject.type) return ""  // <-- allOf schemas often lack top-level "type"

The same issue exists in v31.ts (oneOf/anyOf are handled at lines 105-113, but allOf is missing).

Suggested fix

For allOf, merge all sub-schemas' properties and generate an example from the merged result:

if (schemaObject.allOf) {
  return schemaObject.allOf.reduce((merged, subSchema) => {
    const sub = generateRequestBodyExampleFromSchemaObject(subSchema as OpenAPIV3.SchemaObject)
    return typeof merged === 'object' && typeof sub === 'object' && !Array.isArray(merged) && !Array.isArray(sub)
      ? { ...merged, ...sub }
      : sub
  }, {} as RequestBodyExample)
}

Impact

allOf is one of the most commonly used composition keywords in OpenAPI specs (used for inheritance, mixins, and extending base schemas). Any API spec using this pattern will have empty request bodies after import, forcing users to manually fill in every field.

Originally created by @mahmoodhamdi on GitHub (Mar 13, 2026). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5988 ### Software and environment - Hoppscotch version: latest (main branch) - Browser: All - Platform: Web, Desktop ### Steps to reproduce 1. Create an OpenAPI v3 spec with a request body schema that uses `allOf` composition (a very common pattern for schema inheritance): ```yaml paths: /pets: post: requestBody: content: application/json: schema: allOf: - $ref: '#/components/schemas/BaseAnimal' - type: object properties: breed: type: string components: schemas: BaseAnimal: type: object properties: name: type: string age: type: integer ``` 2. Import the spec in Hoppscotch 3. Open the POST /pets request and look at the generated example body ### Expected behavior The request body example should include all merged properties from the `allOf` schemas: ```json { "name": "string", "age": 0, "breed": "string" } ``` ### Actual behavior The request body is empty (`""`) because the `allOf` case is not handled in the example generator. ### Root cause In `packages/hoppscotch-common/src/helpers/import-export/import/openapi/example-generators/v3.ts`, the function `generateRequestBodyExampleFromSchemaObject` has a TODO comment acknowledging this gap: ```typescript const generateRequestBodyExampleFromSchemaObject = ( schemaObject: OpenAPIV3.SchemaObject ): RequestBodyExample => { // TODO: Handle schema objects with allof <-- acknowledged but not implemented if (schemaObject.example) return schemaObject.example as RequestBodyExample if (schemaObject.oneOf) // ✅ handled return generateRequestBodyExampleFromSchemaObject(...) if (schemaObject.anyOf) // ✅ handled return generateRequestBodyExampleFromSchemaObject(...) // allOf // ❌ not handled — falls through to empty string if (!schemaObject.type) return "" // <-- allOf schemas often lack top-level "type" ``` The same issue exists in `v31.ts` (`oneOf`/`anyOf` are handled at lines 105-113, but `allOf` is missing). ### Suggested fix For `allOf`, merge all sub-schemas' properties and generate an example from the merged result: ```typescript if (schemaObject.allOf) { return schemaObject.allOf.reduce((merged, subSchema) => { const sub = generateRequestBodyExampleFromSchemaObject(subSchema as OpenAPIV3.SchemaObject) return typeof merged === 'object' && typeof sub === 'object' && !Array.isArray(merged) && !Array.isArray(sub) ? { ...merged, ...sub } : sub }, {} as RequestBodyExample) } ``` ### Impact `allOf` is one of the most commonly used composition keywords in OpenAPI specs (used for inheritance, mixins, and extending base schemas). Any API spec using this pattern will have empty request bodies after import, forcing users to manually fill in every field.
Author
Owner

@savauu commented on GitHub (Mar 14, 2026):

Hi! I’d like to work on this issue.

I noticed the TODO in generateRequestBodyExampleFromSchemaObject where allOf schemas are not handled. I’ll try implementing support for merging the allOf sub-schemas so the example body is generated correctly.

Please let me know if that approach sounds good.

<!-- gh-comment-id:4060950076 --> @savauu commented on GitHub (Mar 14, 2026): Hi! I’d like to work on this issue. I noticed the TODO in `generateRequestBodyExampleFromSchemaObject` where `allOf` schemas are not handled. I’ll try implementing support for merging the `allOf` sub-schemas so the example body is generated correctly. Please let me know if that approach sounds good.
Author
Owner

@matthewwalker1621-star commented on GitHub (Mar 16, 2026):

Looks good to me

On Sat, Mar 14, 2026, 12:36 PM savari sable @.***>
wrote:

savauu left a comment (hoppscotch/hoppscotch#5988)
https://github.com/hoppscotch/hoppscotch/issues/5988#issuecomment-4060950076

Hi! I’d like to work on this issue.

I noticed the TODO in generateRequestBodyExampleFromSchemaObject where
allOf schemas are not handled. I’ll try implementing support for merging
the allOf sub-schemas so the example body is generated correctly.

Please let me know if that approach sounds good.


Reply to this email directly, view it on GitHub
https://github.com/hoppscotch/hoppscotch/issues/5988#issuecomment-4060950076,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/B7GHLXGZC3T4A5VKHIMAKEL4QWKADAVCNFSM6AAAAACWRCKUCSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DANRQHE2TAMBXGY
.
You are receiving this because you are subscribed to this thread.Message
ID: @.***>

<!-- gh-comment-id:4066545570 --> @matthewwalker1621-star commented on GitHub (Mar 16, 2026): Looks good to me On Sat, Mar 14, 2026, 12:36 PM savari sable ***@***.***> wrote: > *savauu* left a comment (hoppscotch/hoppscotch#5988) > <https://github.com/hoppscotch/hoppscotch/issues/5988#issuecomment-4060950076> > > Hi! I’d like to work on this issue. > > I noticed the TODO in generateRequestBodyExampleFromSchemaObject where > allOf schemas are not handled. I’ll try implementing support for merging > the allOf sub-schemas so the example body is generated correctly. > > Please let me know if that approach sounds good. > > — > Reply to this email directly, view it on GitHub > <https://github.com/hoppscotch/hoppscotch/issues/5988#issuecomment-4060950076>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/B7GHLXGZC3T4A5VKHIMAKEL4QWKADAVCNFSM6AAAAACWRCKUCSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DANRQHE2TAMBXGY> > . > You are receiving this because you are subscribed to this thread.Message > ID: ***@***.***> >
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#2354
No description provided.