Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] schema mappings are not applied to parameters schemas #12885

Closed
4 of 6 tasks
Gama11 opened this issue Jul 15, 2022 · 3 comments
Closed
4 of 6 tasks

[BUG] schema mappings are not applied to parameters schemas #12885

Gama11 opened this issue Jul 15, 2022 · 3 comments

Comments

@Gama11
Copy link
Contributor

Gama11 commented Jul 15, 2022

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

Schema mappings don't seem to be applied to schemas referenced from an endpoint's parameters. With this:

openapi-generator-cli generate -g java -i example.yml -o output --schema-mappings=Limit=com.example.Limit

the generated code still uses a raw Integer rather than com.example.Limit:

public List<Pet> listPets(Integer limit) throws ApiException {

In contrast, --schema-mappings=Pet=com.example.Pet works as expected:

public List<com.example.Pet> listPets(Integer limit) throws ApiException {
openapi-generator version

6.0.1

OpenAPI declaration file content or url

This is a modified version of the pet store example, with the limit query parameter extracted into a separate schema:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            $ref: "#/components/schemas/Limit"
      responses:
        '200':
          description: A paged array of pets
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pets"
components:
  schemas:
    Limit:
      type: integer
      format: int32
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
Related issues/PRs

#12600

@dpozinen
Copy link

dpozinen commented Sep 2, 2022

Looks like a symptom of this issue. With the schema below I am getting different outputs pre and post 6.0.0

paths:
  /admin/applications:
    post:
      operationId: "createApplication"
      parameters:
        - $ref: "#/components/parameters/Meta-Caller-Name"
...
components:
  parameters:
    Meta-Caller-Name:
      name: Meta-Caller-Name
      in: header
      description: "Service name that call api"
      required: true
      schema:
        enum: [ swagger ]
        example: swagger
        type: string

Notice that @Schema is not generated after the updated.

    // BEFORE 6.0.0
    @RequestMapping(...)
    default ResponseEntity<SaveApplicationResponse> createApplication(
        @Parameter(name = "Meta-Caller-Name", schema = @Schema(description = "", allowableValues = { "swagger" })) String metaCallerName
    ) {
        return getDelegate().createApplication(metaCallerName);
    }

    // AFTER 6.0.0
    @RequestMapping(...)
    default ResponseEntity<SaveApplicationResponse> createApplication(
        @Parameter(name = "Meta-Caller-Name") String metaCallerName
    ) {
        return getDelegate().createApplication(metaCallerName);
    }

This impacts for example allowableValues which are used by swagger to generate examples on the UI.

@wing328
Copy link
Member

wing328 commented Sep 2, 2022

can you please try the latest master? there were fixes related to how schema mapping works in the parameters.

@Gama11
Copy link
Contributor Author

Gama11 commented Sep 12, 2022

It looks like this is indeed fixed with 6.1.0.

@Gama11 Gama11 closed this as completed Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants