Repository navigation
Handle array-typed header parameters and CLI flags - #1464
Open
Indian-boult wants to merge 1 commit into
Open
Indian-boult wants to merge 1 commit into
Indian-boult wants to merge 1 commit into
Conversation
A header parameter whose schema is an array made the generated client call `to_string()` on a `Vec`, which does not compile. This is oxidecomputer#822. The CLI passed the whole `Vec` type to `clap::value_parser!`, which does not compile either, as oxidecomputer#1170 describes. The client now sends an array header in the simple style that OpenAPI 3.0.3 gives header parameters, with the items joined by commas, and the httpmock extension matches an array header against the same joined value. The CLI makes an array parameter a flag that may be repeated, parses each occurrence with the item type's parser, and collects the values. Scalar parameters generate the same code as before. sample_openapi/param-arrays.json has array query and header parameters, including one whose items are an enum. On main the client and CLI generated from it fail to compile with 10 errors. build_param_arrays.rs compiles the generated clients in CI. Array query parameters in httpmock are oxidecomputer#1260, which oxidecomputer#1261 handles, so param_arrays_httpmock stays out of the output crate like buildomat_httpmock. Fixes oxidecomputer#822
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #822, and handles the array case of #1170.
Two kinds of generated code fail to compile when a parameter's schema is an array.
value.to_string().try_into()?, andVechas noDisplay. This is Compilation failure for header values that are arrays #822.::clap::value_parser!(T)withmatches.get_one::<T>, and clap has no value parser forVec<T>. This is the array half of CLI generation fails for array-like and object-like query parameters #1170, and it hits query and header parameters alike.For the new
sample_openapi/param-arrays.json, the positional, builder and tagged builder clients and the CLI fail with 10 errors on main.OpenAPI 3.0.3 section 4.7.12 allows only the
simplestyle for header parameters, and its examples serialize the array["blue","black","brown"]asblue,black,brown. The client now joins the items of an array header with commas into one field line, and RFC 9110 section 5.3 treats that as equivalent to one field line per item for a list header. #822 suggested appending each item as its own line. I went with the spec's form, because a server that reads one header value then sees every item, but switching to one line per item is a small change if you prefer it. The httpmock extension matches an array header against the same joined string. Scalar headers keepto_string().In the CLI an array parameter is now a flag that can be repeated. Each occurrence goes through the item type's parser, so an enum item still gets
PossibleValuesParser, and the consumer collectsget_manyinto the parameter's type. This follows the sketch in #1170. Maps and untagged enums such asGetThingOrThingsIdin buildomat stay as they are, since #1170 says those need more design.Array query parameters in httpmock still call
to_string(). That is #1260, which #1261 handles, so I left those arms alone, andparam_arrays_httpmockis commented out in the output crate the waybuildomat_httpmockis.Tests
progenitor/tests/build_param_arrays.rscompiles the positional and both builder clients for the new spec, so CI now builds a client with array headers. It fails to compile on main with the six header errors.x-labels: a,b,x-shard-ids: 1,2and onekinds=pair per item. The CLI accepts--kinds widget --kinds gadgetand rejects--kinds sprocket.cargo fmt --checkwith nightly, the build and test steps on stable and 1.97, the trybuild tests and the no-default-features build pass.