forked from mtusi2026/mtusi2026lab5
18 lines
849 B
Python
18 lines
849 B
Python
#!/usr/bin/env python3
|
|
"""Convert a temporary generation view to the oapi-codegen 3.0 subset.
|
|
Runtime handlers enforce anyOf and required fields; normative contract is untouched.
|
|
"""
|
|
import json
|
|
from pathlib import Path
|
|
s=json.loads(Path('contracts/openapi.json').read_text())
|
|
for schema in s['components']['schemas'].values():
|
|
schema.pop('anyOf',None)
|
|
for prop in schema.get('properties',{}).values():
|
|
if prop.get('type')==['string','null']:
|
|
prop.update(type='string',nullable=True)
|
|
# Preserve pointers so handlers can distinguish missing fields from empty values.
|
|
for name,field in [('CreateUser','password'),('CreateMessage','text')]:
|
|
s['components']['schemas'][name]['properties'][field]['x-go-type-skip-optional-pointer']=False
|
|
s['components']['schemas'][name]['required'].remove(field)
|
|
print(json.dumps(s))
|