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.63k stars 6.53k forks source link

[BUG] schema mappings discard field description / validation / etc #12886

Open Gama11 opened 2 years ago

Gama11 commented 2 years ago

Bug Report Checklist

Description

Bar.java looks like this with openapi-generator-cli generate -g spring -i example.yml -o output:

  /**
   * The maximum value
   * @return foo
  */
  @Size(min = 1, max = 10) 
  @Schema(name = "foo", description = "The maximum value", required = false)
  public String getFoo() {
    return foo;
  }

With the schema remapped (--schema-mappings=Foo=com.example.Foo), it's missing @Size and description:

  /**
   * Get foo
   * @return foo
  */
  @Valid 
  @Schema(name = "foo", required = false)
  public com.example.Foo getFoo() {
    return foo;
  }
openapi-generator version

6.0.1

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Example
  license:
    name: MIT
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      responses:
        '200':
          description: A paged array of pets
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Bar"
components:
  schemas:
    Bar:
      type: object
      properties:
        foo:
          $ref: "#/components/schemas/Foo"
    Foo:
      type: string
      description: The maximum value
      minLength: 1
      maxLength: 10
Related issues/PRs

12600

Gama11 commented 2 years ago

This is still an issue in 6.1.0.

wing328 commented 11 months ago

to rename the model name Foo to something else, please use model name mapping feature instead:

https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#name-mapping

Gama11 commented 11 months ago

Interesting... I wouldn't have thought that there even is a model name to be mapped, since there is no model for it (generated as a plain String).

wing328 commented 11 months ago

(generated as a plain String).

Ah, an alias to String schema. Then the model name mapping won't work in this case.