KittyCAD/kittycad.rs

openapitor outputs invalid Rust for Ramp API

Closed this issue · 1 comments

openapitor's generated code includes documentation on struct fields. The docs are taken directly from the OpenAPI spec. For example, this fragment of Ramp's OpenAPI spec:

            "ApiCardUpdate": {
                "type": "object",
                "properties": {
                    "card_program_id": {
                        "type": "string",
                        "format": "uuid",
                        "nullable": true,
                        "description": "Specify a card program to link with.\n            This will override the card's spending restrictions with those of the card program.\n            Pass card_program_id = None to detach the card's current card program.\n\n            If the card_program_id field is specified, then the card program's changes will override any other changes.\n            For example, if both spending_restrictions and card_program_id are passed, then the new spending restrictions\n            will match those of the card program (not the passed spending restrictions).\n            "
                    },
}
}

As of openapitor commit a442e7d (main), generates this fragment of Rust:

pub struct ApiCardUpdate {
    #[doc = "Specify a card program to link with.\n            This will override the card's \
             spending restrictions with those of the card program.\n            Pass \
             card_program_id = None to detach the card's current card program.\n\n            If \
             the card_program_id field is specified, then the card program's changes will \
             override any other changes.\n            For example, if both spending_restrictions \
             and card_program_id are passed, then the new spending restrictions\n            will \
             match those of the card program (not the passed spending restrictions).\n            "]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub card_program_id: Option<uuid::Uuid>,

However, something is wrong with the newlines here -- the doc on card_program_id makes cargo test fail. The failure is:

---- src/types.rs - types::ApiCardUpdate::card_program_id (line 1565) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `the`
 --> src/types.rs:1566:4
  |
3 | If the card_program_id field is specified, then the card program's changes will override any other changes.
  |    ^^^ expected one of 8 possible tokens

I can reproduce this in Rust Playground. Basically it's outputting this which is invalid, but if I escape the newlines differently, or I remove the leading spaces, it works.

I think what's happening is that the leading spaces on the lines in the doc are being interpreted as a code block. See rustdoc reference.

org-projects-app[bot] added this issue to KittyCode Project.