OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.62k stars 6.53k forks source link

[BUG][Crystal] Can not generate request form body parameters with additional properties #13708

Open cyangle opened 2 years ago

cyangle commented 2 years ago

Bug Report Checklist

Description

It seems like OAG can't generate below spec correctly.

I have tried below command line options:

Maybe I'm missing some command line flags for this to work.

I found this problem while trying to improve support for form serialization in crystal generator.

@wing328

openapi-generator version

6.2.1-SNAPSHOT

OpenAPI declaration file content or url

bug_spec.yml

openapi: 3.0.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: OpenAPI Petstore
  license:
    name: Apache-2.0
    url: "https://www.apache.org/licenses/LICENSE-2.0.html"
tags:
  - name: fake
paths:
  /fake:
    post:
      tags:
        - fake
      operationId: fake
      parameters:
        - name: id
          in: query
          schema:
            type: string
      requestBody:
        content:
          application/x-www-form-urlencoded:
            encoding:
              map_of_string:
                explode: true
                style: deepObject
              map_of_pets:
                explode: true
                style: deepObject
              inline_map:
                explode: true
                style: deepObject
            schema:
              type: object
              properties:
                map_of_string:
                  $ref: "#/components/schemas/map_of_string"
                map_of_pet:
                  $ref: "#/components/schemas/map_of_pet"
                inline_map:
                  type: object
                  additionalProperties:
                    type: string
      responses:
        "200":
          description: The instance started successfully
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
servers:
  - url: https://localhost:8080/{version}
    description: The local server
    variables:
      version:
        enum:
          - "v1"
          - "v2"
        default: "v2"
  - url: https://127.0.0.1/no_variable
    description: The local server without variables
components:
  schemas:
    map_of_string:
      type: object
      additionalProperties:
        type: string
    map_of_pet:
      type: object
      additionalProperties:
        $ref: "#/components/schemas/pet"
    pet:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
Generation Details

See description.

Steps to reproduce

See description.

Related issues/PRs
Suggest a fix
cyangle commented 1 year ago

So whether to generate a list of form params or a single model for request body is determined by request contentType at here.

I think it's better to provide a cli option to always generate a single model for each request body.

I'm considering adding a new boolean flag --generate-form-as-model similar to --generate-alias-as-model.

The cli option is false by default so that it behaves the same as before.

I can send a PR implementing this.

What do you think? @wing328