defreplace_anyof(data):ifisinstance(data,dict):if"allOf"in data:
data.update(data.pop("allOf")[0])for _, v in data.items():
replace_anyof(v)elifisinstance(data,list):for v in data:
replace_anyof(v)else:return
schema_dict = CustomerModel.schema()
replace_anyof(schema_dict)import json
print(json.dumps(schema_dict,ensure_ascii=False))
node 去除ref引用
import $RefParser from"@apidevtools/json-schema-ref-parser";var mySchema = 上个代码结果
try{await $RefParser.dereference(mySchema);// note - by default, mySchema is modified in place, and the returned value is a reference to the same object// console.log(mySchema);// if you want to avoid modifying the original schema, you can disable the `mutateInputSchema` optionlet clonedSchema =await $RefParser.dereference(mySchema,{mutateInputSchema:false});
console.log(JSON.stringify(mySchema));}catch(err){
console.error(err);}