Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

Typia was generating required: [] in OpenAPI schemas, which violates both OpenAPI and JSON Schema specifications. Per OpenAPI spec: "An empty list required: [] is not valid. If all properties are optional, do not specify the required keyword."

Changes

  • src/programmers/internal/json_schema_object.ts: Conditionally include required only when non-empty
  • src/programmers/internal/json_schema_native.ts: Remove hardcoded required: []
  • src/programmers/llm/LlmApplicationProgrammer.ts: Remove hardcoded required: []
  • test/schemas/**/*.json: Updated 184 test schema expectations

Before/After

interface ExampleInterface {
    a?: number;
    b?: string;
}
const schema = typia.json.schema<ExampleInterface>();

// Before: { type: "object", properties: {...}, required: [] }  ❌
// After:  { type: "object", properties: {...} }                ✅

Testing

npm run build
npm run test

All tests pass.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] Invalid OpenAPI Schema is generated in specific situations.</issue_title>
<issue_description>## 🐛 Bug Report

📝 Summary

An invalid OpenAPI schema is generated in specific situations.

  • Typia Version: 10.1.0
  • Expected behavior:
    Typia should not generate an empty array for the required field in OpenAPI schemas. According to the OpenAPI and JSON Schema specifications, an empty required array is invalid.
  • Actual behavior:
    Typia generates a schema that includes an empty required array (required: []) in certain cases.

Details

According to the OpenAPI specification, an empty array for the required field is not allowed.

This can be verified in the following references:

  1. OpenAPI Specification – Data Types

    An empty list required: [] is not valid. If all properties are optional, do not specify the required keyword.

  2. JSON Schema Draft-04
    See the definitions.stringarray section.

Both OpenAPI and its underlying JSON Schema Draft-04 specification disallow an empty required array.

However, Typia generates such an invalid schema in specific cases, for example:

https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDANHA3g1BzAZzgF84AzKCEOAIiRVRoG4AoFgUwA9JY5gA7GOyhlUAY3ZwASqgDuANVQAbAK7sAYpRABRfgDdsLOMbhQ5i1Rq0AuaezHQAJgB4CMKALyZU-RAD5WYjYHfjc4AjEAC3YQVDgAXgRkNAA6ACsCCH4UiOjY5xkFZTVNKl09PwAKAEpWFhDMpXYUpQg8StyY1FqWIA

This behavior is likely a bug.

Thank you.

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Omit `required` field in json_schema_object.ts when no properties are required
- Remove hardcoded `required: []` from json_schema_native.ts
- Remove hardcoded `required: []` from LlmApplicationProgrammer.ts
- Update 184 test schema expectation files to remove empty required arrays

This fixes the issue where Typia generates `required: []` which is invalid
according to OpenAPI and JSON Schema specifications.

Co-authored-by: samchon <[email protected]>
Copilot AI changed the title [WIP] Fix invalid OpenAPI schema generation Fix invalid empty required: [] in OpenAPI schema generation Nov 26, 2025
Copilot AI requested a review from samchon November 26, 2025 07:31
Copilot finished work on behalf of samchon November 26, 2025 07:31
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 28, 2025

Open in StackBlitz

npm i https://pkg.pr.new/typia@1696

commit: a3e028f

@samchon samchon closed this Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Invalid OpenAPI Schema is generated in specific situations.

2 participants