Skip to content

[BUG][typescript-axios] Primitive anyOf validation becomes an empty nullable model #25637

Open

Description

@Justineo

Bug Report Checklist

  • Provided a minimal standalone spec.
  • Validated the OpenAPI 3.0 and 3.1 regression fixtures with the CLI validator.
  • Reproduced on the latest master.
  • Searched related issues and PRs.
  • Included actual and expected output.
Description

With typescript-axios, a primitive schema whose anyOf alternatives contain validation keywords but no type becomes an empty interface and is incorrectly made nullable.

A pattern-only branch is not a null-only schema. The enclosing type: string still restricts the value to a string. See the OpenAPI Schema Object and JSON Schema validation keywords.

Actual output:

export interface Hostname {}
export interface Address {
    'hostname': Hostname | null;
}

This accepts numbers and null as SDK method arguments, and a returned hostname cannot be assigned to a string.

Expected output:

export type Hostname = string;
export interface Address {
    'hostname': Hostname;
}

The original pattern constraints should remain in the normalized OpenAPI document. TypeScript does not express those predicates, but it can preserve the enclosing primitive type and its nullability.

openapi-generator version

Reproduced with 7.27.0 and master at df804ac9802fba0c51a64f8c3cb03191ed3dde2d (7.28.0-SNAPSHOT). The new ModelUtils, normalizer, and Axios regression tests fail against the unmodified master implementation.

OpenAPI declaration file content or url
openapi: 3.0.3
info: {title: Primitive anyOf validation, version: 1.0.0}
paths: {}
components:
  schemas:
    Hostname:
      type: string
      anyOf: [{pattern: '^[a-z]+[.]example$'}, {pattern: '^[*][.][a-z]+[.]example$'}]
    Address: {type: object, required: [hostname], properties: {hostname: {$ref: '#/components/schemas/Hostname'}}}
Generation Details
java -jar openapi-generator-cli.jar generate \
  -g typescript-axios -i primitive-anyof.yaml -o generated
Steps to reproduce
  1. Save the spec above as primitive-anyof.yaml.
  2. Run the generation command.
  3. Inspect Hostname and Address.hostname in generated/api.ts.
Related issues/PRs

#19155 concerns an untyped union of explicit primitive alternatives. #22427 and #24356 concern nullable reference propagation. This report concerns validation-only alternatives under an explicitly typed parent.

Suggest a fix
  • Do not classify validation-only schemas as null schemas or discard their predicates during OpenAPI 3.1 normalization.
  • Preserve an enclosing type when simplifying a single validation-only alternative.
  • Generate primitive aliases for the Axios models, including inline properties and nullable references, while retaining genuine nullability.
AI disclosure — Codex

Codex investigated the code, prepared standalone fixtures, ran the reproductions and validation, and drafted this report. I supplied the problem and requested an upstream fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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