oxidecomputer / typify

compiler from JSON Schema into idiomatic Rust types
Apache License 2.0
393 stars 57 forks source link

Fix issue #533 #543

Closed SRetip closed 4 months ago

SRetip commented 5 months ago

Close https://github.com/oxidecomputer/typify/issues/533 first case: image seckond case: image third case: image fourth case: image

SRetip commented 5 months ago

Thank you for this. I don't think we want to special-case a $ref and object-related data. Rather, this should work for a $ref with anything else. In addition, extensive merge logic already exists. If you'd like further guidance, please let me know; otherwise I'll fix this as I have time.

Certainly. I appreciate your response. I would require further details. I would be grateful for any additional clarification you could provide on this matter.

ahl commented 5 months ago

I think the essence of this is going to be that we match a schema in which $ref is Some and other stuff might not be None, then do something like:

    let schema_without_ref = SchemaObject { reference: None, .. schema.clone() }.into();
    let schema_only_ref = SchemaObject { reference: reference.clone(), .. Default::default() };
    let new_schema = merge_all([schema_without_ref, schema_only_ref], defs);
    self.convert(new_schema ..)

Also, we'll want a test. Probably in merged-schemas.json.

SRetip commented 4 months ago

I think the essence of this is going to be that we match a schema in which $ref is Some and other stuff might not be None, then do something like:

    let schema_without_ref = SchemaObject { reference: None, .. schema.clone() }.into();
    let schema_only_ref = SchemaObject { reference: reference.clone(), .. Default::default() };
    let new_schema = merge_all([schema_without_ref, schema_only_ref], defs);
    self.convert(new_schema ..)

Also, we'll want a test. Probably in merged-schemas.json.

Hello, I have made the changes you had requested.

ahl commented 4 months ago

Please add a test.

SRetip commented 4 months ago

I hope that's the test you mean the right one.