You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: mediaType.example (and other example fields) reject non-object values due to broken #/definitions/any #154
Run the generator against this spec (e.g. genOpenApiTSCode).
The current behavior
Validation fails with:
Correct the validation error before generating the code.
[
{
instancePath: '.../content/text~1event-stream/example',
schemaPath: '#/definitions/any/type',
keyword: 'type',
params: { type: 'object' },
message: 'must be object'
}
]
The expected behavior
Per the OpenAPI 3.x spec, Media Type Object's example field may be any JSON value (string, number, boolean, array, object, or null), not only an object. The generator should accept it.
Root cause
In src/internal/Validator/openapi.json, the any definition is incorrectly restricted to object:
mediaType.properties.example (and a few other example fields) reference this broken definition:
"example": {
"$ref": "#/definitions/any"
}
so any non-object example value fails validation with must be object.
This is the same class of bug as #9 (Schema Object's properties.<name>.example, fixed in v0.1.6) and the fix in #114 (Parameter Object's examples.<name>.value, which switched the $ref from #/definitions/any to #/definitions/defaultType). This time it's mediaType.properties.example that was missed, and it's still present in the latest release (v2.0.7).
Notably, the correct definition already exists in the same schema file and just isn't reused everywhere:
There are currently 4 places in src/internal/Validator/openapi.json that still reference #/definitions/any for an example-like field and would need the same fix:
Parameter Object example
Media Type Object example (the one causing this issue)
another Parameter Object example variant
anyOrExpression (used by Link Object)
Proposed Fix
Replace $ref: "#/definitions/any" with $ref: "#/definitions/defaultType" in the 4 locations above, consistent with the approach taken in #114.
Environment
@himenon/openapi-typescript-code-generator: 2.0.7 (also confirmed on 1.0.9)
Activity
Himenon commentedon Sep 3, 2026
Thank you for reporting the issue, @satojin219! I’ll address it in PR #155.
satojin219 commentedon Sep 7, 2026
@Himenon
Thank you for your prompt response !🥰