Moibe commited on
Commit
69ad918
·
1 Parent(s): e6b3b7c

endpoint ahora regresa el tipo de archivo

Browse files
Files changed (2) hide show
  1. app/parser.py +13 -3
  2. app/schemas.py +7 -2
app/parser.py CHANGED
@@ -2,6 +2,7 @@ import httpx
2
 
3
  from .schemas import (
4
  EndpointInfo,
 
5
  Parameter,
6
  RequestBody,
7
  Response,
@@ -37,12 +38,21 @@ def _get_type(schema: dict, spec: dict) -> str:
37
  return "unknown"
38
 
39
 
40
- def _extract_fields(schema: dict, spec: dict) -> dict[str, str]:
41
- """Extract field_name -> type from an object schema."""
 
 
 
 
 
 
42
  if "$ref" in schema:
43
  schema = _resolve_ref(spec, schema["$ref"])
44
  properties = schema.get("properties", {})
45
- return {name: _get_type(prop, spec) for name, prop in properties.items()}
 
 
 
46
 
47
 
48
  def _parse_parameters(params: list[dict], spec: dict) -> list[Parameter]:
 
2
 
3
  from .schemas import (
4
  EndpointInfo,
5
+ FieldInfo,
6
  Parameter,
7
  RequestBody,
8
  Response,
 
38
  return "unknown"
39
 
40
 
41
+ def _get_format(schema: dict, spec: dict) -> str | None:
42
+ if "$ref" in schema:
43
+ schema = _resolve_ref(spec, schema["$ref"])
44
+ return schema.get("format")
45
+
46
+
47
+ def _extract_fields(schema: dict, spec: dict) -> dict[str, FieldInfo]:
48
+ """Extract field_name -> FieldInfo from an object schema."""
49
  if "$ref" in schema:
50
  schema = _resolve_ref(spec, schema["$ref"])
51
  properties = schema.get("properties", {})
52
+ return {
53
+ name: FieldInfo(type=_get_type(prop, spec), format=_get_format(prop, spec))
54
+ for name, prop in properties.items()
55
+ }
56
 
57
 
58
  def _parse_parameters(params: list[dict], spec: dict) -> list[Parameter]:
app/schemas.py CHANGED
@@ -15,16 +15,21 @@ class Parameter(BaseModel):
15
  description: str | None = None
16
 
17
 
 
 
 
 
 
18
  class RequestBody(BaseModel):
19
  content_type: str
20
- fields: dict[str, str] # field_name -> type
21
 
22
 
23
  class Response(BaseModel):
24
  status_code: str
25
  description: str | None = None
26
  content_type: str | None = None
27
- fields: dict[str, str] # field_name -> type
28
 
29
 
30
  class EndpointInfo(BaseModel):
 
15
  description: str | None = None
16
 
17
 
18
+ class FieldInfo(BaseModel):
19
+ type: str
20
+ format: str | None = None
21
+
22
+
23
  class RequestBody(BaseModel):
24
  content_type: str
25
+ fields: dict[str, FieldInfo]
26
 
27
 
28
  class Response(BaseModel):
29
  status_code: str
30
  description: str | None = None
31
  content_type: str | None = None
32
+ fields: dict[str, FieldInfo]
33
 
34
 
35
  class EndpointInfo(BaseModel):