Fix missed response schema cases, add backup_name#47
Conversation
|
Hello @wazawoo. Thank you for your contribution, I will check this PR. I’d like to clarify the “it didn’t generate anything” part. If literally no output was generated, that would indicate a bug. No need to split this for now. |
Add test for parsing inline responses
|
@denislituev sounds good, thanks! I added a test that I believe would fail before this PR (because the inline responses weren't added to inline_models) |
|
I also noticed that objects in arrays in responses are not parsed. Started looking into it. For example: {
"paths": {
"example_path": {
"get": {
"summary": "...",
"responses": {
"200": {
"description": "...",
"headers": {},
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"exampleField": {
"type": "string"
},
"anotherExampleField": {
"type": "string"
}
}
}
},
"example": []
}
}
}
},
"tags": [],
"description": "..."
},
"parameters": []
}
}
} |
|
Added more tests and fixed formatting issues. I don't love the long and verbose names I've given for the response objects. I have one more case that's broken with the spec im using as input: A response object, with a parameter with an array of objects. {
...
"schema": {
"type": "object",
"properties": {
"exampleProperty": {
"type": "string"
},
"objectArray": {
"type": "array",
"items": {
"type": "object",
"properties": {
"propA": {
"type": "string"
},
"propB": {
"type": "string"
}
}
}
}
}
},
...
}I think in general something might be missing with handling nested objects and arrays of objects. Not sure I'm approaching the fix in the cleanest way though. |
backup_namebackup_name
| if let ReferenceOr::Item(response) = response_ref { | ||
| for (content_type, media_type) in &response.content { | ||
| if let Some(schema) = &media_type.schema { | ||
| let operation_name = |
There was a problem hiding this comment.
Minor suggestion: The operation_name logic is duplicated on lines 191 and 232. Consider extracting it to the top of process_operation to avoid repetition.
I ran the cli on an API spec and it didn't generate anything. This spec had responses but no request bodies or other schemas. Also, the operations didn't have
operation_ids.I still wanted to generate models from these, so I made a couple changes:
inline_modelsbackup_nameto uniquely specify operations with nooperation_idI can add tests and/or split into different PRs, but first I wanted to see of you were interested in either of these changes.