Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic while generating YNAB OpenAPI client #693

Open
opeik opened this issue Jan 18, 2024 · 2 comments
Open

Panic while generating YNAB OpenAPI client #693

opeik opened this issue Jan 18, 2024 · 2 comments

Comments

@opeik
Copy link

opeik commented Jan 18, 2024

Hi there!

I tried to generate a client for the YNAB OpenAPI spec which seems to panic:

❯ cargo install cargo-progenitor
    Updating crates.io index
     Ignored package `cargo-progenitor v0.4.1` is already installed, use --force to override

❯ RUST_BACKTRACE=1 cargo progenitor --input ynab_openapi_spec.yaml --output ynab --name ynab --v
ersion 0.1.0
thread 'main' panicked at /Users/opeik/.cargo/registry/src/index.crates.io-6f17d22bba15001f/progenitor-impl-0.4.1/src/method.rs:1201:9:
assertion failed: response_types.len() <= 1
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/panicking.rs:144:5
   3: progenitor_impl::method::<impl progenitor_impl::Generator>::extract_responses
   4: progenitor_impl::method::<impl progenitor_impl::Generator>::method_sig_body
   5: progenitor_impl::method::<impl progenitor_impl::Generator>::positional_method
   6: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
   7: core::iter::adapters::try_process
   8: progenitor_impl::Generator::generate_tokens
   9: cargo_progenitor::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@opeik opeik changed the title Panic while generating Up OpenAPI client Panic while generating YNAB OpenAPI client Jan 18, 2024
@ahl
Copy link
Collaborator

ahl commented Jan 20, 2024

The part of the spec it's barfing on is here:

      responses:
        "200":
          description: The requested category
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CategoryResponse"
        "404":
          description: The category not was found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        default:
          description: An error occurred
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

In short, this says, "200s will return a CategoryResponse; 404s will return ErrorResponse; and everything else will return ErrorResponse". Where we get hung up is that "everything else". If that's inclusive of success responses (say, a 201 or 202) should we expect to get ErrorResponses for success codes as well? See OAI/OpenAPI-Specification#3396

Given the ambiguity here and this common practice, I think we may want to change the interpretation to conform to the common law use of OpenAPI rather than its by-the-letter writing. So something like:

default covers responses cases whose category is not otherwise mentioned

@ahl ahl changed the title Panic while generating YNAB OpenAPI client Panic processing specs where default response is used to handle error cases Jan 20, 2024
@ahl
Copy link
Collaborator

ahl commented Jan 20, 2024

See #344

@ahl ahl changed the title Panic processing specs where default response is used to handle error cases Panic while generating YNAB OpenAPI client Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants