OpenAPITools / OpenAPITools/openapi-generator

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

Open
#13,708 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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

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

I have tried below command line options:

  • With minimal options

    • docker run --rm -it -v ${PWD}:/gen --user 1000:1000 --workdir /gen/ openapitools/openapi-generator-cli:latest generate --type-mappings=Object=JSON::Any,AnyType=JSON::Any,decimal=BigDecimal -g crystal -i example_api_specs/bug_spec.yml -o /gen/local/bug --additional-properties=shardName=bug,moduleName=Bug,shardLicense=MIT,shardVersion=0.0.1,shardAuthors=cyangle,skipOperationExample=true,shardDescription=Bug
      
    • It generated one api file fake_api.cr but there's no models generated
    • And the request body param inline_map is missing from fake_api.cr
    • api method: def fake(id : String?, map_of_string : Hash(String, String)?, map_of_pet : Hash(String, Pet)?)
  • With --global-property skipFormModel=false

    • docker run --rm -it -v ${PWD}:/gen --user 1000:1000 --workdir /gen/ openapitools/openapi-generator-cli:latest generate  --global-property skipFormModel=false --type-mappings=Object=JSON::Any,AnyType=JSON::Any,decimal=BigDecimal -g crystal -i example_api_specs/bug_spec.yml -o /gen/local/bug --additional-properties=shardName=bug,moduleName=Bug,shardLicense=MIT,shardVersion=0.0.1,shardAuthors=cyangle,skipOperationExample=true,shardDescription=Bug
      
    • It generated 2 models: FakeRequest and Pet
    • FakeRequest has all request body properties
    • But the model FakeRequest is never used in the generated api file fake_api.cr
    • api method is like this: def fake(id : String?)

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

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 with example_api_specs/bug_spec.yml and run the documented Crystal generator command to reproduce the missing inline_map request-body parameter. Inspect the Crystal generator path that handles application/x-www-form-urlencoded bodies and additionalProperties, then verify that generated fake_api.cr includes the inline_map input and that the generated FakeRequest behavior is consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.