Skip to content

[BUG] client generator in multiple languages ignores URI object type defined in schema in favor of generic type #21519

Open
@wresch

Description

@wresch

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating client SDKs in at least two languages, a OpenAPI 2.0 schema that contains a definition for a URI object is ignored and instances of the URI object are turned into either java URIs (in the case of groovy) or python strings in the case of python and python-pydantic-v1. Here is a small example OpenAPI document:

{
  "swagger": "2.0",
  "info": {
    "title": "Fuzzball API",
    "version": "2.0",
    "contact": {
      "name": "CtrlIQ, Inc",
      "url": "https://ciq.co",
      "email": "info@ciq.co"
    }
  },
  "schemes": ["https"],
  "consumes": ["application/json"],
  "produces": ["application/json"],
  "paths": {
    "/file": {
      "get": {
        "operationId": "GetFile",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/File"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [],
        "tags": [
          "FileService"
        ]
      }
    }
  },
  "definitions": {
    "File": {
      "type": "object",
      "properties": {
        "source": {
          "$ref": "#/definitions/URI",
          "description": "Source is the origin of the data. The type of URIs supported are\ndetermined by whether this is specified under ingress or egress."
        },
        "destination": {
          "$ref": "#/definitions/URI",
          "description": "Destination is the location to move the data. The type of URIs\nsupported are determined by whether this is specified under ingress or\negress."
        }
      },
      "description": "File specifies details of workflow volume data movement."
    },
    "URI": {
      "type": "object",
      "properties": {
        "uri": {
          "type": "string",
          "description": "uri is the uri of the resource to be accessed."
        },
        "secrets": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "description": "secrets is a map of key value pairs to use to access resource.\nThe key specifies the type of data that is being used and the value\nspecifies raw data or a template for the workflow system to populate with\ndata internally from the secrets engine."
        },
        "secret": {
          "type": "string"
        },
        "decryptionSecret": {
          "type": "string"
        }
      },
      "description": "URI contains the specification for a resource to access as well as\nadditional data necessary for access such as credentials."
    },
    "Status": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      }
    }
  }
}

Generate an SDK with

java -jar bin/openapi-generator-cli-7.14.0.jar generate -g python-pydntic-v1 -o pp -i mini.json --additional-properties="packageName=mini"
cat pp/mini/models/file.py | tail -n +15 | head -n 20
from __future__ import annotations
import pprint
import re  # noqa: F401
import json


from typing import Optional
from pydantic import BaseModel

class File(BaseModel):
    """
    File specifies details of workflow volume data movement.  # noqa: E501
    """
    source: Optional[str] = None
    destination: Optional[str] = None
    __properties = ["source", "destination"]

    class Config:
        """Pydantic configuration"""

The model class is using Optional[str] instead of Optional[URI] with URI imported from model/uri.py (which is generated as expected). Same is true for -g python. For -g groovy or -g java it uses java.net.URI instead of the definition from the spec.

openapi-generator version

tested with the following jar releases/snapshots:

  • openapi-generator-cli-7.13.0.jar
  • openapi-generator-cli-7.14.0-20250602.095643-46.jar
  • openapi-generator-cli-7.14.0.jar
  • openapi-generator-cli-8.0.0-20240727.184357-6.jar
OpenAPI declaration file content or url

Full document is available at https://api.stable.fuzzball.ciq.dev/v2/schema

Minimal example see above

Generation Details
for gen in python python-pydantic-v1 java groovy ; do
	java -jar $jar generate -g python-pydntic-v1 -o mini-${gen} -i mini.json --additional-properties="packageName=mini"
done
Steps to reproduce

see above

Related issues/PRs

couldn't find anything

Suggest a fix

don't know the code base well enough

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions