Skip to content

DefaultGenerator: unusedSchemas contains too many schemas #50

@jmini

Description

@jmini

Some model object are missing when the server is configured to consume both application/json and application/x-www-form-urlencoded.

With this example the model SomeObject is not generated:

swagger: '2.0'
info:
  title: Test
  description: Test API
  version: 1.0.0
host: some.example.com
basePath: /v1
schemes:
  - https
  - http
consumes:
  - application/json
  - application/x-www-form-urlencoded
produces:
  - application/json
paths:
  /testMe:
    post:
      tags:
        - db
      operationId: testMeOp
      parameters:
        - in: body
          name: body
          required: false
          schema:
            $ref: '#/definitions/SomeObject'
      responses:
        '200':
          description: Successful Operation
definitions:
  SomeObject:
    type: object
    properties:
      p1:
        type: string
      p2:
        type: integer
        format: int32

This is due to org.openapitools.codegen.utils.ModelUtils.getUnusedSchemas(OpenAPI) not working as expected.

I am not sure if the dual consumes definition is correct or not (it is derived from a spec send by a used), but we could also imagine an other case with 2 path. In one JSON is expected as request body, in the other an application/x-www-form-urlencoded request body. In this case, the schema is also used.

In my opinion the logic to compute the unused schema should be to compute all the used schema and subtract them from a set containing all schemas.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions