-
-
Notifications
You must be signed in to change notification settings - Fork 144
Open
Description
openapi.json
{
"openapi": "3.0.1",
"info": {
"title": "test",
"description": "",
"version": "1.0.0"
},
"tags": [],
"paths": {
"/test": {
"post": {
"summary": "test",
"deprecated": false,
"description": "",
"tags": [],
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"nullable_field": {
"type": "string",
"nullable": true
}
},
"required": [
"nullable_field"
]
}
}
}
},
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {
"type": "string"
}
},
"required": [
"status"
]
}
}
},
"headers": {}
}
},
"security": []
}
}
},
"components": {
"schemas": {},
"securitySchemes": {}
},
"servers": [],
"security": {}
}command
uvx --from fastapi-code-generator fastapi-codegen --input ./specs/openapi.json --output . --output-model-type pydantic_v2.BaseModelmodels.py
result
# generated by fastapi-codegen:
# filename: ./specs/xiaozhi-server.openapitest.json
# timestamp: 2025-02-11T06:09:59+00:00
from __future__ import annotations
from pydantic import BaseModel
class TestPostRequest(BaseModel):
nullable_field: str
class TestPostResponse(BaseModel):
status: strexpected
# generated by fastapi-codegen:
# filename: ./specs/xiaozhi-server.openapitest.json
# timestamp: 2025-02-11T06:07:27+00:00
from __future__ import annotations
from typing import Optional
from pydantic import BaseModel, Field
class TestPostRequest(BaseModel):
nullable_field: Optional[str] = Field(...)
class TestPostResponse(BaseModel):
status: strref
Metadata
Metadata
Assignees
Labels
No labels