-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
If a request parameter has an empty schema (schema: {}
), the produces rust code is invalid (does not compile). According to the OpenAPI validator linked above and the official specification, this is a valid spec.
The OpenAPI spec below produces a function with the following signature:
pub fn get_test(configuration: &configuration::Configuration, param: models::serde_json::Value) -> Result<(), Error<GetTestError>>
This cannot be compiled, the error message is could not find 'serde_json' in 'models'
. I would expect that all code generated from a valid OpenAPI spec generates compilable rust code.
openapi-generator version
I tested with version 06ed7c8 (the current main).
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: empty-schema
description: Ensure that empty schema produces valid rust code.
version: 1.0.0
paths:
/v1/test/{param}:
get:
operationId: getTest
parameters:
- name: param
in: path
required: true
schema: {}
responses:
'200':
description: The request was successful.
Steps to reproduce
I'll provide the steps to create a failing test using the valid OpenAPI spec above.
-
Add the snippet above to the test resources (e.g.
modules/openapi-generator/src/test/resources/3_0/rust/empty-schema.yaml
). -
Create a config for the test (e.g.
bin/configs/rust-reqwest-empty-schema.yaml
):generatorName: rust outputDir: samples/client/others/rust/reqwest/empty-schema library: reqwest inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/empty-schema.yaml templateDir: modules/openapi-generator/src/main/resources/rust additionalProperties: supportAsync: false packageName: empty-schema-reqwest
-
Generate the rust samples with
./bin/generate-samples.sh ./bin/configs/rust-*
. -
Execute the tests with
mvn integration-test -f samples/client/others/rust/pom.xml
.
Related issues/PRs
I did not find any issues regarding empty schemas and rust.
Suggest a fix
I'm new to rust and to openapi-generator, so I am no help here, sorry.