swagger-api / swagger-api/swagger-codegen

[RustServer] `object` type is generated when an empty object is given

Open
#7,208 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When the object data type is empty (or have nothing understandable to the generator), it generates object type, which is invalid to rust.

      parameters:
        - name: param
          in: body
          description: request body
          required: true
          schema:
            type: object
            additionalProperties:
              type: string

to

 fn test_inline_additional_properties(&self, param_param: object, context: &Context) -> Box<Future<Item=TestInlineAdditionalPropertiesResponse, Error=ApiError> + Send> {
                                                          ^^^^^^ invalid type object
Swagger-codegen version

master (dc69138de52f089f9a7ad8be475ebbaa8c6e2d99)

Swagger declaration file content or url
swagger: '2.0'
info:
  description: "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
  version: 1.0.0
  title: Swagger Petstore
paths:
  /fake/inline-additionalProperties:
    post:
      tags:
        - fake
      summary: test inline additionalProperties
      description: ''
      operationId: testInlineAdditionalProperties
      consumes:
        - application/json
      parameters:
        - name: param
          in: body
          description: request body
          required: true
          schema:
            type: object
            additionalProperties:
              type: string
      responses:
        '200':
          description: successful operation
Command line used for generation
$ java -jar swagger-codegen-cli.jar generate  -v -l rust-server -i swagger.yaml   -o server
Steps to reproduce

Just run the command above

Related issues/PRs

None

Suggest a fix/enhancement

Just handle object types around here. I think serde_json::Value is suitable. I'll do it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustServerCodegen.java around line 128, then reproduce the issue with the provided Swagger declaration and rust-server generation command. Verify that the inline additionalProperties body parameter no longer produces the invalid Rust type object and uses the intended valid representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, rust
Domain
backend, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.