6 releases (3 breaking)

0.4.0 Mar 16, 2024
0.3.0 Mar 16, 2024
0.2.0 Mar 15, 2024
0.1.2 Mar 14, 2024

#3 in #openapi-v3

Download history 18/week @ 2024-06-10 16/week @ 2024-06-17 15/week @ 2024-06-24 21/week @ 2024-07-08 17/week @ 2024-07-15 47/week @ 2024-07-22 35/week @ 2024-07-29 21/week @ 2024-08-05 19/week @ 2024-08-12 9/week @ 2024-08-19 34/week @ 2024-08-26 2/week @ 2024-09-02 9/week @ 2024-09-09 18/week @ 2024-09-16 27/week @ 2024-09-23

62 downloads per month
Used in openapi-tui

MIT license

40KB
841 lines

Bootstrap

The idea is to use openapi code generator for rust to generate openapi specification library. To do so, I started with an openapi specification with

{
    "openapi": "3.1.0",
    "info": {
        "version": "3.1.0",
        "title": "openapi"
    },
    "components": {
        "schemas": {}
    }
}

Build OpenAPI In OpenAPI

  1. Download json-schema of OpenAPI v3.1
  2. Copy everything from schema.$def into the above OpenAPI json inside components.schemas
  3. Insert openapi definition into components.schemas
  4. Replace every #/$defs/ with #/componenst/schemas
  5. Remove every "$ref": "#/$defs/specification-extensions". We don't need them now.
  6. Remove every oneOf. We will add them later in the generated code.

See the result file here.

Generate Code

npx -y @openapitools/openapi-generator-cli generate -i openapi-in-openapi.json -g rust -o /tmp/openapi && mv /tmp/openapi/src/models .

Implement The Remaining Part

Generated code is not complete, and don't generate these structs. We will create them by hand :-) .

path-item-or-reference
parameter-or-reference
request-body-or-reference
response-or-reference
callbacks-or-reference
example-or-reference
link-or-reference
header-or-reference
security-scheme-or-reference

Dependencies

~2.5–3.5MB
~87K SLoC