Skip to content

Field leads to duplicate interfaces #63

@Arkonos

Description

@Arkonos

Version: 2.0.0

When I change an abbreviated version of the example to include a Field

from pydantic import BaseModel, Field

class Profile(BaseModel):
    username: str

class LoginResponseData(BaseModel):
    profile: Profile = Field(..., description="Test")

the generated file will contain an extra interface for profile

/* [...] */

export interface LoginResponseData {
  profile: Profile;
}
/**
 * Test
 */
export interface Profile {
  username: string;
}
export interface Profile1 {
  username: string;
}

This can be avoided by adding --exclude Profile to the command, but this is cumbersome and manual.

This is the output of

_generate_json_schema(models)
{
  "$defs": {
    "LoginResponseData": {
      "additionalProperties": false,
      "properties": {
        "profile": {
          "$ref": "#/$defs/Profile",
          "description": "Test"
        }
      },
      "required": [
        "profile"
      ],
      "title": "LoginResponseData",
      "type": "object"
    },
    "Profile": {
      "additionalProperties": false,
      "properties": {
        "username": {
          "type": "string"
        }
      },
      "required": [
        "username"
      ],
      "title": "Profile",
      "type": "object"
    }
  },
  "properties": {
    "LoginResponseData": {
      "$ref": "#/$defs/LoginResponseData"
    },
    "Profile": {
      "$ref": "#/$defs/Profile"
    }
  },
  "required": [
    "LoginResponseData",
    "Profile"
  ],
  "title": "_Master_",
  "type": "object"
}

and the change compared to the same input without = Field(...

       "additionalProperties": false,
       "properties": {
         "profile": {
-          "$ref": "#/$defs/Profile"
+          "$ref": "#/$defs/Profile",
+          "description": "Test"
         }
       },
       "required": [

Probably related to bcherny/json-schema-to-typescript#193

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions