Skip to content

schemaFaker: false Still Generates Random Values #854

@bermi

Description

@bermi

Problem Description

When using openapi-to-postmanv2 with schemaFaker: false, the library still generates random property names and values for certain schema patterns, making the output non-deterministic across runs.

Expected Behavior

With schemaFaker: false, all generated examples should be deterministic and use schema placeholders like <string>, <number>, etc., without any random property names or values.

Actual Behavior

The library still generates random property names and values for schemas with additionalProperties and complex structures, even when schemaFaker: false is set.

Minimal Reproducible Example

OpenAPI Schema

openapi: 3.0.3
info:
  title: Test API
  version: 1.0.0
paths:
  /test:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                publicKey:
                  type: object
                  additionalProperties:
                    type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    additionalProperties: true

Test Code

const { convert } = require('openapi-to-postmanv2');

const openapiSpec = {
  // ... OpenAPI spec from above
};

// Convert with schemaFaker disabled
convert(
  { type: 'string', data: JSON.stringify(openapiSpec) },
  {
    schemaFaker: false,
    exampleParametersResolution: 'Schema',
    requestParametersResolution: 'Schema'
  },
  (err, result) => {
    if (err) {
      console.error(err);
      return;
    }

    // Run this multiple times - you'll see different property names
    console.log(JSON.stringify(result.collection, null, 2));
  }
);

Output Examples

Run 1:

{
  "body": {
    "mode": "raw",
    "raw": "{\n  \"publicKey\": {\n    \"amet_04\": \"<string>\"\n  }\n}"
  }
}

Run 2:

{
  "body": {
    "mode": "raw",
    "raw": "{\n  \"publicKey\": {\n    \"sit_2\": \"<string>\"\n  }\n}"
  }
}

Run 3:

{
  "body": {
    "mode": "raw",
    "raw": "{\n  \"publicKey\": {\n    \"fugiatd5\": \"<string>\"\n  }\n}"
  }
}

Root Cause

The issue occurs when schemas contain:

  1. additionalProperties: true or additionalProperties: { type: "string" }
  2. Complex anyOf/oneOf structures
  3. Objects without explicit property definitions

Even with schemaFaker: false, the library generates random property names like "amet_04", "sit_2", "fugiatd5" for these schema patterns.

Impact

This makes it impossible to generate deterministic Postman collections, causing:

  • Unnecessary git diffs on each generation
  • Build instability in CI/CD pipelines
  • Difficulty in version control tracking

Environment

  • openapi-to-postmanv2 version: (latest)
  • Node.js version: (varies)
  • Operating System: (any)

Suggested Fix

When schemaFaker: false is set, the library should:

  1. Use consistent placeholder property names for additionalProperties (e.g., "<property>": "<string>")
  2. Avoid generating any random strings or property names
  3. Provide a deterministic fallback for all schema patterns

Workaround

Currently, there's no complete workaround. Users can post-process the generated collection to normalize property names, but this is complex and error-prone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions