Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5387
Closed
Open
Issue created Feb 20, 2020 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[Clarification Needed] Validation and code generation of open-ended "type: object"

Created by: sebastien-rosset

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

According to the JSON schema spec, when a schema is an open-ended "type: object", such as below, the document must be an unordered set of properties mapping a string to an instance, from the JSON "object" production.

components:
  schemas:
    Blob:
      type: object

In the above example, additionalProperties is not specified, hence it has the default value "true"

AFAIK, that means the document cannot be the "null" value, it cannot be a primitive type (e.g. string, integer...) and it cannot be an array. Is my understanding correct? If on the other hand, the intent is the document can take any valid JSON value, then with the JSON schema specification, and putting the OAS spec aside for a moment, it could be specified with a type array:

type: [ 'null', object, array, boolean, string, number ]

But type arrays are not supported in OAS, so instead my question is are we supposed to use "oneOf"?

components:
  schemas:
    Blob:
      nullable: true      # cannot use type: 'null' in OAS 3.0
      oneOf:
        - type: object
        - type: array
        - type: boolean
        - type: string
        - type: number

But in practice, I see multiple generators are lenient for "type: object" and accept any valid JSON document. Even if we use "oneOf" in the spec, multiple generators do not support 'oneOf' very well, so I am reluctant to use that construct for this specific purpose (because I need to generate SDK that work for multiple languages). I haven't gone through the entire list, but I see at least two different behaviors across two generators. For example, "python-experimental" accepts any JSON valid document:

'blob': (bool, date, datetime, dict, float, int, list, str, none_type,),  # noqa: E501

But with the same OAS spec, go-experimental implements a map[string]interface{}, which means the value can either be the nil value or a map of string to any value; with strict validation, it would have to be written as:

type: [ 'null', object ]
openapi-generator version

master February 20th 2020

OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking