[Rust Server] Add support for untyped properties and models#5339
[Rust Server] Add support for untyped properties and models#5339richardwhiuk merged 4 commits intoOpenAPITools:5.0.xfrom Metaswitch:rust-server-untyped-support
Conversation
|
#5387 raises a question here, which we should probably clarify before merging this. |
|
How will this PR handle the following schema? Will you only accept maps of strings to values? Or any valid JSON/XML document? components:
schemas:
Blob:
type: object |
|
Any valid JSON/XML document due to the limitations of Foo:
type: objectand Foo: {}as discussed in #5387. I don't think that's a blocker on merging this - once that's fixed, we can support for the former in the Rust Server Generator. I think there's a secondary problem that we default to treating additional properties as not present. |
I've added a helper function in this PR to distinguish the two cases: https://github.com/OpenAPITools/openapi-generator/pull/5391/files#diff-57d7532cf464a8d7c24aab4b22ceb993R680 |
catch NPE if no OneOf Schemas is setted. merged from 5.0 branch [Rust Server] Support header objects (OpenAPITools#5337) [Rust Server] Support header objects Support operations with objects in the header [Rust Server] Support objects as query parameters (OpenAPITools#5338) - Support objects as query parameters - Update samples [Rust Server] Add support for untyped properties and models (OpenAPITools#5339) * [Rust Server] Add support for untyped properties * [Rust Server] Improve support for untyped data * Update samples [Rust Server] Support RFC 7807 (OpenAPITools#5407) * Support RFC 7807 - Problem Details for HTTP APIs * Add test for RFC 7807 * Update samples [Rust Server] Nullable fixes (OpenAPITools#5408) * [Rust Server] Nullable fixes * [Rust Server] Add tests for nullable cases * Update samples [Rust Server] Handle numeric response description (OpenAPITools#5452) * [Rust Server] Handle response descriptions which start with a number. * [Rust Server] Add test for numeric response descriptions * Update samples [Rust Server] Support numeric operation IDs (OpenAPITools#5453) * [Rust Server] Support operation IDs which begin with a number * [Rust Server] Add test for a numeric operation ID * Update samples [Rust Server] Support RFC 7386 (OpenAPITools#5454) * [Rust Server] Support RFC 7386 Support application/merge-patch+json as defined by RFC 7386 - https://tools.ietf.org/html/rfc7386 Handle exactly the same as application/json. * [Rust Server] Add test for RFC 7386 * Update samples [Rust Server] Suffix reserved words with _ (OpenAPITools#5455) * [Rust Server] Suffix reserved words with _ Suffix reserved words with an underscore instead of prefixing them. This follows convention in the Rust community, as prefixing with an underscore indicates an unused variable in Rust. * Update samples [Rust Server] Don't change API version (OpenAPITools#5458) Don't change the API version which is exposed in `crate::API_VERSION`. - If the API version isn't set, we don't expose it. - If it is set, we leave it well alone. - Always pass a package version: - Pass in the passed package version by preference - Pass in the API version if it's not. - If the API version isn't set, we use 1.0.0 - If it is set, and isn't a valid semver, we append .0 such that we have something with three digits (so that an API version of 1 works). [Rust Server] Support OpenAPI v3 callbacks (OpenAPITools#5405) * [Rust Server] Support Callbacks * [Rust Server] Support callbacks in the examples * [Rust Server] Update features documentation * [Rust Server] Mark as supporting callbacks * Update samples * [Rust Server] Add tests for callbacks * [Rust Server] Fix README Don't suggest examples which don't exist [Rust Server] Test allOf objects including base properties (OpenAPITools#5457) * [Rust Server] Add operationIds for rust-server-test * [Rust Server] Add test for allOf * Update samples [Rust Server] Make parse error Display-able (OpenAPITools#5490) * [Rust Server] Make parse error displayable Change error type to be displayable to prevent compile errors * [Rust Server] Add test for enum in path * Update samples
If a property has no specified type in the schema then it is allowed to take any type. This is problematic in Rust, where all code is statically typed. As such, this PR makes the assumption that JSON is in use, and thus we can use
serde_json::Valueas an escape hatch. This likely doesn't work for XML based APIs. To support both, theoretically, we could parameterise all models which included untyped properties (e.g. asModelName<T>) and then haveTbe eitherserde_json::Valueorxml::Nodeor similar. This isn't implemented here, but is a possible expansion.This PR also clarifies support regarding unknown mime types. Unknown mime types are now treated as unstructured data - and presented either as a byte array or a String - e.g.
application/yamlis presented as a stringRust Technical Committee
PR checklist
./bin/(or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).master,4.3.x,5.0.x. Default:master.