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 info is not being stored in core java classes for five use cases #7613

Closed
3 of 6 tasks
spacether opened this issue Oct 6, 2020 · 6 comments
Closed
3 of 6 tasks

Comments

@spacether
Copy link
Contributor

spacether commented Oct 6, 2020

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.

@spacether spacether changed the title [BUG] Validations are not being stored in our java classes for three use cases [BUG] Validations are not being stored in our java classes for five use cases Oct 6, 2020
@spacether spacether changed the title [BUG] Validations are not being stored in our java classes for five use cases [BUG] Validations are not being stored in the java classes for five use cases Oct 6, 2020
@sebastien-rosset
Copy link
Contributor

Basic question: by java classes do you mean the java classes of the openapi code generator? Or the generated Java classes, e.g -g java?

@spacether
Copy link
Contributor Author

spacether commented Oct 9, 2020

I mean the classes:

  • CodegenProperty
  • CodegenModel
  • CodegenParameter
  • CodegenResponse

@sebastien-rosset
Copy link
Contributor

I mean the classes:

  • CodegenProperty
  • CodegenModel
  • CodegenParameter
  • CodegenResponse

ok, thanks. Any by "validation", you mean the validate option, as in java -jar openapi-generator-cli.jar validate -i ...?

@spacether
Copy link
Contributor Author

I mean openapi Schema validation properties like pattern minimum, maximum, maxItems etc

@sebastien-rosset
Copy link
Contributor

I mean openapi Schema validation properties like pattern minimum, maximum, maxItems etc

ah ok, thanks, now it all makes sense.

@spacether spacether changed the title [BUG] Validations are not being stored in the java classes for five use cases [BUG] Validations are not being stored in the java classes for four use cases Nov 4, 2020
@spacether spacether changed the title [BUG] Validations are not being stored in the java classes for four use cases [BUG] Schema info is not being stored in the java classes for five use cases Nov 4, 2020
@spacether spacether changed the title [BUG] Schema info is not being stored in the java classes for five use cases [BUG] Schema info is not being stored in core java classes for five use cases Nov 4, 2020
@spacether
Copy link
Contributor Author

The remaining enum/default/nullable info should be covered by our Java classes. Marking this issue as done now that #10653 has been merged.

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

2 participants