pydantic

package module
v0.0.0-...-85da603 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Indent string = "    "

Indent 默认缩进为四个空格

Functions

func Parse

func Parse(v ...any) map[string]*File

Parse 解析一个结构体,返回其所需的所有文件

func Save

func Save(path string, v ...any) error

Save 将导入模型和已解析模型写入文件

Types

type File

type File struct {
	Name   string           `json:"name"`   // 包名
	Files  map[string]*File `json:"-"`      // 包名映射表
	Import []string         `json:"import"` // 导入的其他包
	Models []*Model         `json:"models"` // 从包内读取到的结构体模型
}

File 用来保存同一个包内的结构体

func (*File) MarshalText

func (f *File) MarshalText() ([]byte, error)

MarshalText 输出导入模型和已解析模型

func (*File) Parse

func (f *File) Parse(v any)

Parse 解析一个结构体

func (*File) Save

func (f *File) Save(path string) error

Save 将导入模型和已解析模型写入文件

type Model

type Model struct {
	Name    string      // 结构体名称
	Inline  []*Model    // 在字段中定义的内联结构体
	Fields  [][4]string // 导出的字段的下划线命名、pydantic 模型中允许的类型名、字段别名以及字段注释
	Parents []string    // 嵌入在本结构体中的类型名
}

Model 用来描述一个结构体

func (*Model) MarshalText

func (m *Model) MarshalText() ([]byte, error)

MarshalText 将模型输出为 BaseModel 对象

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL