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] [python] additional_properties_type not set correctly in models #8771

Closed
3 of 6 tasks
spacether opened this issue Feb 19, 2021 · 2 comments · Fixed by #8802
Closed
3 of 6 tasks

[BUG] [python] additional_properties_type not set correctly in models #8771

spacether opened this issue Feb 19, 2021 · 2 comments · Fixed by #8802

Comments

@spacether
Copy link
Contributor

spacether commented Feb 19, 2021

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

Using a v3 spec for an object schema, when additionalProperties is True or unset or {} the type should be set for it
Looking at our generated models, the type is not set at the model level though it IS being set in CodegenProperty
The expected output is to have additional_properties_type = {str, int, float...} when it is incorrectly being set to additional_properties_type = None

This issue: #8813
Is also a blocker on getting this working because I need to define the vars that only the composed schema includes at the composed schema level.

openapi-generator version

5.0.0

OpenAPI declaration file content or url
# openapi-generator generate -i issue_8743v3_wrong_response_type.yaml -o issue_8743v3 -g python
openapi: 3.0.1
info:
  title: Quick Base API
  version: 1.0.0
servers:
- url: //api.quickbase.com/
paths:
  /fields/{fieldId}:
    get:
      description: Gets the properties of an individual field, based on field id.
      parameters:
      - name: fieldId
        in: path
        required: true
        schema:
          type: integer
      responses:
        200:
          description: Success
          content:
            '*/*':
              schema:
                type: object
                properties:
                  id:
                    type: integer
                  fieldType:
                    type: string
                  label:
                    type: string
                  properties:
                    $ref: '#/components/schemas/FieldProperties'
components:
  schemas:
    FieldProperties:
      type: object
      properties:
        comments:
          type: string
        format:
          type: string
        maxLength:
          type: integer
        allowNewChoices:
          type: boolean
        displayAsLink:
          type: boolean
        allowHTML:
          type: boolean
      description: 'Additional properties for the field. '
Generation Details

openapi-generator generate -i issue_8743v3_wrong_response_type.yaml -o issue_8743v3 -g python

Steps to reproduce

Generate the client and look in both generated models. Both models lack the expected additionalProperties description.

Related issues/PRs

This came up when investigating #8743

Suggest a fix
  • Update the model template to set additional_properties_type
  • If the value does not exist, then set it in the java layer
  • make sure that the users will be able to set disallowAdditionalPropertiesIfNotPresent = True
    • right now the generator is hard coding this to False. We should default to false, and allow true to be passed in.
@spacether
Copy link
Contributor Author

Investigation findings:
Per models produced from v3 specs:

  • unset additionalProperties -> None (incorrect, should define all types)
  • additionalProperties = True -> all types (correct)
  • additionalProperties = schema -> defines that schema in additional_properties_type (correct)
  • additionalProperties = False -> None (correct)

@spacether
Copy link
Contributor Author

spacether commented Mar 31, 2021

This issue will be closed when the 5.2.x branch gets merged into master
If you want to use the fix now, you can use the 5.2.x branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant