Skip to content

[BUG] Schema info is not being stored in core java classes for five use cases #7613

@spacether

Description

@spacether

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

Validations are not being stored in our java classes for the following use cases:

  • [DONE] array model where the validations are in the array.items schema
  • [DONE] object model where additionalProperties has an inline schema definition
  • [DONE] vars and requiredVars and needed (right now they are only present in CodegenModel)
  • [DONE] composed schema models
  • enum info? default? nullable?

This data is needed in these classes

  • CodegenModel
  • CodegenResponse
  • CodegenParameter
  • CodegenProperty
openapi-generator version

5.0.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: OpenAPI Petstore
  description: "sample spec"
  license:
    name: Apache-2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.0
servers:
- url: http://petstore.swagger.io:80/v2
tags:
- name: items
  description: Everything about your Pets
paths:
  /ref_array_with_validations_in_items/{items}:
    post:
      tags:
      - items
      operationId: refArrayWithValidationsInItems
      parameters:
        - name: items
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/ArrayWithValidationsInItems'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ArrayWithValidationsInItems'
        required: true
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ArrayWithValidationsInItems'
  /array_with_validations_in_items/{items}:
    post:
      tags:
      - items
      operationId: arrayWithValidationsInItems
      parameters:
        - name: items
          in: path
          required: true
          schema:
            type: array
            items:
              type: array
              items:
                type: integer
                format: int64
                maximum: 7
                minimum: 5
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                type: array
                items:
                  type: integer
                  format: int64
                  maximum: 7
                  minimum: 5
        required: true
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                type: array
                items:
                  type: array
                  items:
                    type: integer
                    format: int64
                    maximum: 7
                    minimum: 5
components:
  schemas:
    ArrayWithValidationsInItems:
      type: array
      items:
        type: array
        items:
          type: integer
          format: int64
          maximum: 7
          minimum: 5
    ObjectWithValidationsInAdditionalProperties:
      type: object
      additionalProperties:
        type: integer
        format: int64
        maximum: 7
        minimum: 5
    ComposedOneOfInlineValidation:
      oneOf:
        - type: integer
          format: int64
          maximum: 7
          minimum: 5
    ComposedAnyOfInlineValidation:
      anyOf:
        - type: integer
          format: int64
          maximum: 7
          minimum: 5
    ComposedAllOfInlineValidation:
      allOf:
        - type: integer
          format: int64
          maximum: 7
          minimum: 5
  securitySchemes: {}
Generation Details

Use any generator, I use python-experimental

Steps to reproduce

Generate a client using the above spec

  • validations are missing for the use cases that I mentioned
Related issues/PRs
Suggest a fix

I see two possible paths forward:

  1. create models for all schemas that have this issue and $ref them (this is a lot of work, I do not prefer this solution)
  • this solution is also not great because we only store string data about these types. So even if we stored "ExtractedModel" or "int" the java generator has no way of telling if that value is a model vs a primitive class.
  1. add the following interfaces to IJsonSchemaValidationProperties and implement it in all needed java classes
  • items CodegenProperty
  • additionalProperties CodegenProperty
  • composedSchemas class that contains oneOf, anyOf, and allOf
    • oneOf List<CodegenProperty>
    • anyOf List<CodegenProperty>
    • allOf List<CodegenProperty>

I prefer option2 because it preserves the data from the spec file in our interfaces and leaves it up to the generators how they want to add the missing validations.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions